minfra-cli 1.3.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6145d8b76367e739eb7b93bcfdcaf22428004ab45de977215e874c8b59da64b
4
- data.tar.gz: 8811fbed0e951e862888428e4370cc10d9c4fa199e9d9fa567b847ec1f689383
3
+ metadata.gz: 16d7979548068a14a297be13086588549af443c92b2e34aad122cd2235fd4ed5
4
+ data.tar.gz: 047e86635b52285501a533c2c87b36187025382dbf7429e6bfe0b17b0b4a9fc8
5
5
  SHA512:
6
- metadata.gz: 61359dada17608504dac46c3af40fc94e8a7d53f468ca95f6bcec518c9d7c9b32a7a6ff14540286c1fcc9b14d6eee45df4df336e6156a0a8cea8c986c8188fd5
7
- data.tar.gz: 9792bf505ded5f51f4955be00f13fae965aaaadf17caa1606f310ebbb600cc145929ab5e39b31c4c0dc707a1de24912dd830f2c6749077db8d42961539a594ce
6
+ metadata.gz: 60d8a24e419d98ef0609da5d09d356a2ac4d01920d79e96ff80a28c6917afa22f09dcfc99138fe345375ddb5f282906e9339b692e49dba01fc93bcc072e6b52a
7
+ data.tar.gz: 29324defe80574b1057cad503bfc15919cde0e6ae04d250bb6a346bacdb7e6612af5dccdadd01fc563ed962bf5328741e024d3c61310aec40c1505e10169fd74
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.4.1
2
+ * kube command supports port-foward and finds the first fuzzy podname
3
+ # 1.4.0
4
+ * plugin managment
5
+ * changed logging (added central logger, and configurable loglevel: MINFRA_LOGGING_LEVEL minfra.logging_level)
6
+ * hiera main path can be configured (minfra.hiera.env_path)
7
+ * fixed kube subcommand
1
8
  # 1.3.0
2
9
  * deep lookup value like "env.cluster.name"
3
10
  # 1.2.2
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Is a KIND (k8s in docker) based development environment.
4
4
 
5
5
 
6
+ ## Setup
6
7
 
7
8
  ## Expected hiera data
8
9
 
@@ -183,7 +183,7 @@ module Minfra
183
183
 
184
184
  subcommand = args.shift
185
185
 
186
- if ['exec', 'logs'].include?(subcommand)
186
+ if ['exec', 'logs','port-forward'].include?(subcommand)
187
187
  resource = nil
188
188
  implicit_resource = 'pod'
189
189
  else
@@ -196,8 +196,8 @@ module Minfra
196
196
  options[:cluster])
197
197
 
198
198
  cluster = stack.cluster_name
199
-
200
- if [resource, implicit_resource].include?('pod') && ['delete', 'describe', 'exec', 'logs'].include?(subcommand)
199
+ byebug
200
+ if [resource, implicit_resource].include?('pod') && ['delete', 'describe', 'exec', 'logs', 'port-forward'].include?(subcommand)
201
201
  cmd_get_pods = "kubectl --kubeconfig #{kube_config_path} --context #{cluster} --namespace #{options[:stack]} get pod -o jsonpath='{range .items[*]}{.metadata.name}{\"\\n\"}'"
202
202
 
203
203
  pods_list = run_cmd(cmd_get_pods).split("\n")
@@ -0,0 +1,21 @@
1
+ module Minfra
2
+ module Cli
3
+ class Plugin < Command
4
+
5
+ desc "describe","describe plugins"
6
+ def describe
7
+ Minfra::Cli.plugins.each do |plugin|
8
+ puts "#{plugin.name} (#{plugin.version})"
9
+ end
10
+ end
11
+ desc "install", "install plugins"
12
+ def install
13
+ Minfra::Cli.plugins.each do |plugin|
14
+ puts "setup: #{plugin.name}"
15
+ plugin.install
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ Minfra::Cli.register("plugin", "dealing wit plugins", Minfra::Cli::Plugin)
@@ -5,7 +5,7 @@ module Minfra
5
5
  include Logging
6
6
  include Hook
7
7
 
8
- desc "setup", "creates a default config file on the host"
8
+ desc "dev", "creates a default config file on the host"
9
9
  def dev
10
10
  setup_config
11
11
  end
@@ -36,7 +36,6 @@ module Minfra
36
36
  end
37
37
 
38
38
  def init!(base_path_str=nil)
39
- debug( "Config: initializing" )
40
39
  @base_path = Pathname.new(base_path_str || ENV["MINFRA_PATH"]).expand_path
41
40
  @me_path = @base_path.join('me')
42
41
  @project_config_path=@base_path.join("config","project.json")
@@ -62,7 +61,6 @@ module Minfra
62
61
  end
63
62
 
64
63
  def load(orch_env)
65
- debug( "loading config env: #{orch_env} #{@orch_env}" )
66
64
  return self if defined?(@orch_env)
67
65
  @orch_env = orch_env
68
66
  @orch_env_config=Hashie::Mash.new
@@ -2,7 +2,7 @@ module Minfra
2
2
  module Cli
3
3
  module Logging
4
4
  def error(str)
5
- STDERR.puts "Error: #{str}"
5
+ logger.error str
6
6
  end
7
7
 
8
8
  def exit_error(str)
@@ -11,15 +11,23 @@ module Minfra
11
11
  end
12
12
 
13
13
  def info(str)
14
- STDERR.puts str
14
+ logger.info str
15
+ end
16
+
17
+ def warn(str)
18
+ logger.warn str
15
19
  end
16
20
 
17
21
  def debug(str)
18
- STDERR.puts "Debug: #{str}"
22
+ logger.debug str
19
23
  end
20
24
 
21
25
  def deprecated(comment)
22
- STDERR.puts "DEPRECATED: #{comment}"
26
+ logger.warn "DEPRECATED: #{comment}"
27
+ end
28
+ private
29
+ def logger
30
+ Minfra::Cli.logger
23
31
  end
24
32
  end
25
33
  end
@@ -3,12 +3,11 @@ module Minfra
3
3
  class Main < Command
4
4
 
5
5
  desc 'kube', 'kubectl wrapper and other features'
6
- long_desc '
7
- '
8
- option :environment, required: false, aliases: ['-e']
9
6
  option :cluster
7
+ option :stack, required: true
10
8
  def kube(*args)
11
- kube.kubectl_command(args)
9
+ kube = Kube.new(options, @minfra_config)
10
+ kube.kubectl_command(args)
12
11
  end
13
12
 
14
13
  # tbd: move this to project
@@ -1,34 +1,108 @@
1
1
  module Minfra
2
2
  module Cli
3
3
  class Plugins
4
+ class Plugin
5
+ include Logging
6
+ attr_reader :name, :version, :opts, :path
7
+
8
+
9
+ def initialize(name:, version:, opts:, disabled:)
10
+ @name= name
11
+ @version = version
12
+ @opts = opts.merge(require: false)
13
+ @disabled= disabled
14
+ if opts["path"]
15
+ @path= Minfra::Cli.config.base_path.join(opts["path"])
16
+ end
17
+ end
18
+ def disabled?
19
+ @disabled
20
+ end
21
+
22
+ #adds the plugin to the
23
+ def prepare
24
+ debug("plugin prepare: #{name}, #{version}, disabled: #{disabled?}")
25
+ return if disabled?
26
+ if path
27
+ begin
28
+ lib_path=path.join('lib')
29
+ $LOAD_PATH.unshift lib_path
30
+ require name
31
+ rescue Gem::Requirement::BadRequirementError, LoadError
32
+ warn("plugin prepare path: #{name} (#{$!})")
33
+ end
34
+ else
35
+ begin
36
+ @gem_spec=Gem::Specification.find_by_name(name)
37
+ gem name, version
38
+ rescue Gem::MissingSpecError
39
+ warn("plugin prepare gem: #{name}, #{version} (#{$!})")
40
+ end
41
+ end
42
+ end
43
+
44
+ def setup
45
+ return if disabled?
46
+ if path
47
+ minfra_path = Pathname.new(path).join("minfracs","init.rb")
48
+ if minfra_path.exist?
49
+ begin
50
+ require minfra_path # this should register the command
51
+ rescue LoadError
52
+ logger.warn("Minfra plugin detected but dependencies not installed: #{minfra_path} (try: minfra plugin install)")
53
+ end
54
+ end
55
+ else
56
+ error("Gem based plugins not supported yet")
57
+ end
58
+ end
59
+
60
+ def install
61
+ return if disabled?
62
+ if path
63
+ system("cd #{path}; bundle install")
64
+ else
65
+ system("gem install #{name} --version #{version}")
66
+ end
67
+ end
68
+ end
69
+
70
+ def initialize(plugins)
71
+ @plugins=plugins
72
+ end
73
+
74
+ def prepare
75
+ @plugins.each(&:prepare)
76
+ end
77
+ def setup
78
+ @plugins.each(&:setup)
79
+ end
80
+
81
+ def install
82
+ if path
83
+ system("cd #{path}; bundle install")
84
+ else
85
+ system("gem install #{name} --version #{version}")
86
+ end
87
+ end
88
+
89
+ def each(&block)
90
+ @plugins.each(&block)
91
+ end
92
+
4
93
  def self.load
94
+ found=[]
5
95
  [Pathname.new(ENV["MINFRA_PATH"]).join("config","minfra_plugins.json"),
6
96
  Pathname.new(ENV["MINFRA_PATH"]).join("me","minfra_plugins.json")].each do |file|
7
-
8
97
  next unless File.exist?(file)
9
-
10
98
  plugins=JSON.parse(File.read(file))
11
99
  plugins["plugins"].each do |spec|
12
- opts=spec["opts"] || {}
13
- opts.merge(require: false)
14
- if opts["path"]
15
- begin
16
- $LOAD_PATH.unshift opts["path"]+"/lib"
17
- require spec["name"]
18
- rescue Gem::Requirement::BadRequirementError
19
- STDERR.puts("Can't load plugin: #{spec["name"]}")
20
- end
21
- else
22
- begin
23
- Gem::Specification.find_by_name(spec["name"])
24
- gem spec["name"], spec["version"]
25
- rescue Gem::MissingSpecError
26
- STDERR.puts("Can't load plugin: #{spec["name"]}, #{spec["version"]}; run 'minfra plugin setup'")
27
- end
28
- end
29
- end
100
+ found << Plugin.new(name: spec['name'], opts: spec['opts'] || {}, version: spec['version'], disabled: spec['disabled'])
101
+ end
30
102
  end
103
+ new(found)
31
104
  end
105
+
32
106
  end
33
107
  end
34
108
  end
@@ -1,5 +1,5 @@
1
1
  module Minfra
2
2
  module Cli
3
- VERSION = '1.3.0'.freeze
3
+ VERSION = '1.4.1'.freeze
4
4
  end
5
5
  end
data/lib/minfra/cli.rb CHANGED
@@ -24,9 +24,13 @@ require "#{ENV['MINFRA_PATH']}/config/preload.rb" if File.exist?("#{ENV['MINFRA_
24
24
 
25
25
  module Minfra
26
26
  module Cli
27
- extend Minfra::Cli::Logging
28
27
 
28
+ extend Minfra::Cli::Logging
29
29
 
30
+ def self.logger
31
+ @logger
32
+ end
33
+
30
34
  def self.init(argv)
31
35
  @argv = argv
32
36
  # we'll set the context very early!
@@ -39,9 +43,15 @@ module Minfra
39
43
  @config = Config.load('dev')
40
44
  end
41
45
 
46
+ @logger=Logger.new(STDERR)
47
+ logger.level=ENV["MINFRA_LOGGING_LEVEL"] || @config.project.minfra.logging_level || 'warn'
48
+ @logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}")
49
+
42
50
  hiera_init
43
51
 
44
- Minfra::Cli::Plugins.load
52
+ @plugins = Minfra::Cli::Plugins.load
53
+ @plugins.prepare
54
+
45
55
  Minfra::Cli.scan
46
56
  require_relative 'cli/main_command'
47
57
  Minfra::Cli.resolve
@@ -66,7 +76,8 @@ module Minfra
66
76
  hiera = Hiera.new(:config => @hiera_root.join('hiera.yaml').to_s)
67
77
  Hiera.logger=:noop
68
78
  env= @config.orch_env
69
- raise("unknown environment #{env}, I expact a file at hiera/hieradata/environments/#{env}.eyaml") unless @hiera_root.join("hieradata/environments/#{env}.eyaml").exist?
79
+ hiera_main_path=@hiera_root.join("hieradata/#{config.project.minfra.hiera.env_path}/#{env}.eyaml")
80
+ raise("unknown environment #{env}, I expact a file at #{hiera_main_path}") unless hiera_main_path.exist?
70
81
 
71
82
  scope={ "hieraroot" => @hiera_root.to_s, "env" => env}
72
83
  special_lookups=hiera.lookup("lookup_options", {}, scope, nil, :priority)
@@ -88,7 +99,7 @@ module Minfra
88
99
  end
89
100
 
90
101
  result=hiera.lookup(value, default, scope, nil, lookup_type)
91
- unless values.empty?
102
+ if !values.empty? && result.kind_of?(Hash) # we return nil or the scalar value and only drill down on hashes
92
103
  result=result.dig(*values)
93
104
  end
94
105
 
@@ -107,17 +118,17 @@ module Minfra
107
118
  def self.config
108
119
  @config
109
120
  end
121
+
110
122
  def self.scan
123
+ #loading built in commands
111
124
  root_path.join("lib/minfra/cli/commands").each_child do |command_path|
112
125
  require command_path if command_path.to_s.match(/\.rb$/) && !command_path.to_s.match(/\#/)
113
126
  end
114
- # this is like railties but their called minfracs
115
- $LOAD_PATH.each do |path|
116
- minfra_path = Pathname.new(path).join("..","minfracs","init.rb")
117
- if minfra_path.exist?
118
- require minfra_path # this should register the command
119
- end
120
- end
127
+ @plugins.setup
128
+ end
129
+
130
+ def self.plugins
131
+ @plugins
121
132
  end
122
133
 
123
134
  def self.register(subcommand,info,command)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfra-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-31 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -170,6 +170,7 @@ files:
170
170
  - lib/minfra/cli/command.rb
171
171
  - lib/minfra/cli/commands/dev.rb
172
172
  - lib/minfra/cli/commands/kube.rb
173
+ - lib/minfra/cli/commands/plugin.rb
173
174
  - lib/minfra/cli/commands/project.rb
174
175
  - lib/minfra/cli/commands/project/branch.rb
175
176
  - lib/minfra/cli/commands/project/tag.rb