minfra-cli 3.0.1 → 3.1.0

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: 6aee1958bcccfa6f91dc0d2b6e331478e9bb970353768a9d08083a982299c0d1
4
- data.tar.gz: db65ab93061611f75d4cbe2016bf08800588cdbc3a1911aea60c498f2f15dc08
3
+ metadata.gz: 57af73071c5c324ef7f908176a695c2cbdee6d2a1be1d65f6d0b9a9055c10aa4
4
+ data.tar.gz: 45e45f3bc0766a8fe6354f3b036bcb3327a4c79df5c1026a9e84d3f8314b8b37
5
5
  SHA512:
6
- metadata.gz: 3a1b7e97a137c63e79b336cd83d20eedc4dfec249f41b36e7627359d449eed8c1db3890f83190bccd84a8987fed5d5df889deb6938b50d7ec5ec4b24f1f295a5
7
- data.tar.gz: 8e0c012fd0cf40cd33e7d3edf7dcad792705d4a3e9f26ba1244f13d41d76656ffed49497bb821367f32c8ede8dc57c24645a7f333c0522126079cd2c49541f13
6
+ metadata.gz: 242cdcc9c027b110adc0fc0c3615de37a627888a594b8104212c9631530c99d7b8fafcc1ab5f3bd7808cc08af53c988b309394583c6abf4a40b7b49b25c9318e
7
+ data.tar.gz: 286be675ceb5ad1839d5c500fb2e23219fa7dbce860dbe1308f5d884e0c350898b541de1288088e2330b46b1022f93786ca925d8bff608b5cf903737350d090e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 3.1.0
2
+ * overriding backends via MINFRA_HIERA_BACKENDS
3
+ * overriding Yaml Backend to allow :extension: setting
4
+ # 3.0.2
5
+ * removing complex dns manipulation and hardcoding google servers
1
6
  # 3.0.1
2
7
  * fixing: dubblequotes in helm values should be escaped
3
8
  # 3.0.0
data/README.md CHANGED
@@ -17,7 +17,7 @@ Is a KIND (k8s in docker) based development environment.
17
17
  | | | default_stacks | | env.stacks or env.roles |
18
18
  | | | | | infra::allow_insecure_k8s_connections |
19
19
  | when set to 'true' all hiera lookups are logged on debug level | MINFRA_DEBUG_HIERA_LOOKUPS | | | |
20
-
20
+ | to override the backends in the hiera file, comma separated | MINFRA_HIERA_BACKENDS | | | |
21
21
 
22
22
  ## Expected hiera data
23
23
 
@@ -150,7 +150,13 @@ module Minfra
150
150
  root = base_path.join('hiera')
151
151
  root.join('hieradata',env_path).glob('*.eyaml').sort.each do |path|
152
152
  env_name = path.basename.sub(/(\..+)/,'').to_s
153
- @envs[env_name]=Env.new(hiera_root: root, hiera_env_path: env_path, name: env_name, hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true')
153
+ @envs[env_name]=Env.new(
154
+ hiera_root: root,
155
+ hiera_env_path: env_path,
156
+ name: env_name,
157
+ hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true',
158
+ backends: ENV.fetch('MINFRA_HIERA_BACKENDS','').split(',')
159
+ )
154
160
  end
155
161
  @env = @envs[@env_name] # set the current env
156
162
  end
@@ -25,9 +25,7 @@ module Minfra
25
25
 
26
26
  def restart
27
27
  run %(docker start #{kind_name}-control-plane)
28
- run %(docker exec #{kind_name}-control-plane bash -c "sed -e '/nameserver 127.0.0.11/ s/^#*/#/' /etc/resolv.conf | cat - >> /etc/resolv.conf")
29
- run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.8.8 >> /etc/resolv.conf")
30
- run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf")
28
+ set_kind_dns
31
29
  end
32
30
 
33
31
  def create
@@ -51,10 +49,9 @@ module Minfra
51
49
  run(%(KIND_EXPERIMENTAL_DOCKER_NETWORK=#{kind_name} kind create cluster --name "#{kind_name}" --config #{@config.kind_config_path}))
52
50
 
53
51
  info 'step: configuring kind'
54
- run %(docker exec #{kind_name}-control-plane bash -c "sed -e '/nameserver 127.0.0.11/ s/^#*/#/' /etc/resolv.conf | cat - >> /etc/resolv.conf")
55
- run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.8.8 >> /etc/resolv.conf")
56
- run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf")
57
-
52
+
53
+ set_kind_dns
54
+
58
55
  configs = [YAML.safe_load(File.read(kind_kube_path))]
59
56
 
60
57
  existing_config = YAML.safe_load(File.read(kube_config_path))
@@ -244,6 +241,11 @@ module Minfra
244
241
 
245
242
  private
246
243
 
244
+ def set_kind_dns
245
+ run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.8.8 > /etc/resolv.conf")
246
+ run %(docker exec #{kind_name}-control-plane bash -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf")
247
+ end
248
+
247
249
  def init(stack_name, _env, deployment, explicit_cluster)
248
250
  Minfra::Cli::StackM::KubeStackTemplate.new(stack_name,
249
251
  config,
@@ -2,13 +2,14 @@ module Minfra
2
2
  module Cli
3
3
  class Env
4
4
  attr_reader :name, :hiera
5
- def initialize(name:, hiera_root:, hiera_env_path:, hiera_debug_lookups: )
5
+ def initialize(name:, hiera_root:, hiera_env_path:, hiera_debug_lookups:, backends: )
6
6
  @name = name
7
7
  @hiera = HieraLooker.new(
8
8
  root: hiera_root,
9
9
  env_name: name,
10
10
  env_path: hiera_env_path,
11
- debug_lookups: hiera_debug_lookups
11
+ debug_lookups: hiera_debug_lookups,
12
+ backends: backends
12
13
  )
13
14
  end
14
15
 
@@ -5,13 +5,20 @@ module Minfra
5
5
  module Cli
6
6
  class HieraLooker
7
7
  include Logging
8
- def initialize(root:, env_name:, env_path:, debug_lookups: false)
8
+ def initialize(root:, env_name:, env_path:, debug_lookups: false, backends: nil)
9
9
  @root = Pathname.new(root)
10
10
  @env_name = env_name
11
11
  @cache = {}
12
12
 
13
13
  @hiera = Hiera.new(config: @root.join('hiera.yaml').to_s)
14
+ # now that hiera has loaded the backends let's patch 'em
15
+ require 'minfra/cli/hiera_yaml_backend_patch' if defined?(Hiera::Backend::Yaml_backend)
16
+
14
17
  Hiera.logger = :noop
18
+ if backends && !backends.empty?
19
+ @hiera.config[:backends] = backends
20
+ Hiera::Config.load_backends
21
+ end
15
22
 
16
23
  hiera_main_path = @root.join("hieradata/#{env_path}/#{env_name}.eyaml")
17
24
 
@@ -0,0 +1,50 @@
1
+ class Hiera
2
+ module Backend
3
+ class Yaml_backend
4
+
5
+ def lookup(key, scope, order_override, resolution_type, context)
6
+ answer = nil
7
+ found = false
8
+
9
+ Hiera.debug("Looking up #{key} in YAML backend")
10
+ Backend.datasourcefiles(:yaml, scope, Config[:yaml][:extension] || "yaml", order_override) do |source, yamlfile|
11
+ data = @cache.read_file(yamlfile, Hash) do |data|
12
+ YAML.load(data) || {}
13
+ end
14
+
15
+ next if data.empty?
16
+ next unless data.include?(key)
17
+ found = true
18
+
19
+ # Extra logging that we found the key. This can be outputted
20
+ # multiple times if the resolution type is array or hash but that
21
+ # should be expected as the logging will then tell the user ALL the
22
+ # places where the key is found.
23
+ Hiera.debug("Found #{key} in #{source}")
24
+
25
+ # for array resolution we just append to the array whatever
26
+ # we find, we then goes onto the next file and keep adding to
27
+ # the array
28
+ #
29
+ # for priority searches we break after the first found data item
30
+ new_answer = Backend.parse_answer(data[key], scope, {}, context)
31
+ case resolution_type.is_a?(Hash) ? :hash : resolution_type
32
+ when :array
33
+ raise Exception, "Hiera type mismatch for key '#{key}': expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
34
+ answer ||= []
35
+ answer << new_answer
36
+ when :hash
37
+ raise Exception, "Hiera type mismatch for key '#{key}': expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
38
+ answer ||= {}
39
+ answer = Backend.merge_answer(new_answer, answer, resolution_type)
40
+ else
41
+ answer = new_answer
42
+ break
43
+ end
44
+ end
45
+ throw :no_such_key unless found
46
+ return answer
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minfra
4
4
  module Cli
5
- VERSION = '3.0.1'
5
+ VERSION = '3.1.0'
6
6
  end
7
7
  end
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: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-04 00:00:00.000000000 Z
11
+ date: 2024-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -205,6 +205,7 @@ files:
205
205
  - lib/minfra/cli/errors.rb
206
206
  - lib/minfra/cli/helm_runner.rb
207
207
  - lib/minfra/cli/hiera_looker.rb
208
+ - lib/minfra/cli/hiera_yaml_backend_patch.rb
208
209
  - lib/minfra/cli/hook.rb
209
210
  - lib/minfra/cli/kubectl_runner.rb
210
211
  - lib/minfra/cli/logging.rb