kubes 0.8.9 → 0.9.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: 1089172c4489c77f34abd1cc5df408e11467950f40ae67ee062377f078c131d1
4
- data.tar.gz: 1c29e074651e78963aa1fbc83314e49b6da006c7902056c2ef108dd91302b8a7
3
+ metadata.gz: 2481a18249c348869a45a16c59ab5718f7e0e0eabb0ad5d613720e162b0b6150
4
+ data.tar.gz: baab953af69e63ee3697dc995abdac3a49e734d825d4b60dbe253618c0adea69
5
5
  SHA512:
6
- metadata.gz: ac9080b9f30461b48d4d4fbf5e6a9ca6be2a53385a0cde1b649e6da26c265ddb7adb7f3c66714ad179ebac3f3ae3ebd9ea112bc5a0f5e65beab7d51d30f9574d
7
- data.tar.gz: c6424d462ba9c7b834fcf1944fd75275ae6fa8b6abf7ea7b29fa9575fa6f5ae0853529ca10b32e1eeff11ac094e2ee920008c326936e2c1bd5e153cb8dc3f915
6
+ metadata.gz: db322cd2a2c7154f56f6980b2e76319d211ad84290d8d5fbf1ce11e502b65260a2f7b9202636cf59d9a03a25ed84d96024598e97117a465679383cd733679cce
7
+ data.tar.gz: 67e8ad348fd9bebc223c2b83c038c74999f7e1afc573fe94a989b161f7f1fde6cd35410b9fb120497dd93f565009f0793d6d8bc8208721f0aefd98324d4d6ed4
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.9.1] - 2022-08-24
7
+ - [#67](https://github.com/boltops-tools/kubes/pull/67) small improvement to show layering: show compiled output path
8
+
9
+ ## [0.9.0] - 2022-08-24
10
+ - [#66](https://github.com/boltops-tools/kubes/pull/66) show layering improvements: show resource layers also
11
+ - only show error if exit_on_fail
12
+
13
+ ## [0.8.10] - 2022-08-18
14
+ - [#65](https://github.com/boltops-tools/kubes/pull/65) show variables layers support
15
+ - improve new secret generator
16
+
6
17
  ## [0.8.9] - 2022-08-11
7
18
  - [#64](https://github.com/boltops-tools/kubes/pull/64) extra variable layering
8
19
  - add extra layering docs
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: "Debug Layering"
3
+ category: layering
4
+ order: 9
5
+ ---
6
+
7
+ Kube's Layering abilities are so powerful that they can be difficult to debug when overly used. It is recommended that you chose only a few layers that make sense for your goals and stick to them. Essentially, limit the rope length. Here are also some debugging tips.
8
+
9
+ ## Enable Logging
10
+
11
+ You can debug layers by setting `KUBES_LAYERING_SHOW=1`.
12
+
13
+ export KUBES_LAYERING_SHOW=1
14
+
15
+ You can also turn on show layering with a config.
16
+
17
+ .kubes/config.rb
18
+
19
+ ```ruby
20
+ Kubes.configure do |config|
21
+ config.layering.show = true
22
+ end
23
+ ```
24
+
25
+ This will show the **found** layers.
26
+
27
+ $ kubes compile
28
+ Compiling .kubes/resources/web/deployment.yaml
29
+ Resource layers:
30
+ .kubes/resources/base/all.yaml
31
+ .kubes/resources/base/deployment.yaml
32
+ .kubes/resources/web/deployment.yaml
33
+ .kubes/resources/web/deployment/dev.yaml
34
+ Variables layers:
35
+ .kubes/variables/base.rb
36
+ .kubes/variables/dev.rb
37
+
38
+ ## All Considered Layers
39
+
40
+ If you want to also see all the considered layers use `KUBES_LAYERING_SHOW_ALL=1`. Note, this will show a lot of layers. Kubes considers many layers and for files `base/all.yml` also perform layering and results are ultimately merged together. Here's an example snippet of the output.
41
+
42
+ $ export KUBES_LAYERING_SHOW_ALL=1
43
+ Compiling .kubes/resources/web/deployment.yaml
44
+ Resource layers:
45
+ .kubes/resources/base/all.yaml
46
+ .kubes/resources/base/deployment.yaml
47
+ .kubes/resources/web/deployment.yaml
48
+ .kubes/resources/web/deployment/dev.yaml
49
+ Variables layers:
50
+ .kubes/variables/base.rb
51
+ .kubes/variables/dev.rb
52
+ .kubes/variables/base/all.rb
53
+ .kubes/variables/base/all/dev.rb
54
+ .kubes/variables/base/deployment.rb
55
+ .kubes/variables/base/deployment/base.rb
56
+ .kubes/variables/base/deployment/dev.rb
57
+ .kubes/variables/web/deployment.rb
58
+ .kubes/variables/web/deployment/base.rb
59
+ .kubes/variables/web/deployment/dev.rb
60
+ ...
@@ -1,5 +1,8 @@
1
1
  ---
2
2
  title: DSL Layering
3
+ nav_text: DSL
4
+ category: layering
5
+ order: 2
3
6
  ---
4
7
 
5
8
  {% include layering/layers.md ext="rb" %}
@@ -1,5 +1,7 @@
1
1
  ---
2
2
  title: Extra Layering
3
+ category: layering
4
+ order: 8
3
5
  ---
4
6
 
5
7
  Setting KUBES_EXTRA will process extra layers.
@@ -1,5 +1,8 @@
1
1
  ---
2
2
  title: DSL Merge Behavior
3
+ nav_text: DSL Merge
4
+ category: layering
5
+ order: 4
3
6
  ---
4
7
 
5
8
  Generally, the merge should behave as expected. For example, map or Hash fields are merged together from multiple layers. Strings are simply replaced.
@@ -1,5 +1,7 @@
1
1
  ---
2
2
  title: Merge Options
3
+ category: layering
4
+ order: 5
3
5
  ---
4
6
 
5
7
  Underneath the hood, Kubes uses the [danielsdeleo/deep_merge](https://github.com/danielsdeleo/deep_merge) library to merge layers together. You can control the merge behavior options with [config.merger.options]({% link _docs/config/reference.md %}).
@@ -1,5 +1,8 @@
1
1
  ---
2
2
  title: Mixed Layering
3
+ nav_text: Mix and Match
4
+ category: layering
5
+ order: 3
3
6
  ---
4
7
 
5
8
  You can mix and match the YAML and DSL forms together and layering still works.
@@ -1,5 +1,8 @@
1
1
  ---
2
2
  title: YAML Layering
3
+ nav_text: YAML
4
+ category: layering
5
+ order: 1
3
6
  ---
4
7
 
5
8
  {% include layering/layers.md ext="yaml" %}
@@ -4,8 +4,7 @@ title: Layering
4
4
 
5
5
  Kubes supports layering files together so you can use the same Kubernetes files to build multiple environments like dev and prod.
6
6
 
7
- * [YAML Layering]({% link _docs/layering/yaml.md %})
8
- * [DSL Layering]({% link _docs/layering/dsl.md %})
9
- * [Mix Layering]({% link _docs/layering/mix.md %})
10
- * [Merge Behavior]({% link _docs/layering/merge-dsl.md %})
11
- * [Extra Layering]({% link _docs/layering/extra.md %})
7
+ {% assign docs = site.docs | where: "categories","layering" | sort: "order" %}
8
+ {% for doc in docs -%}
9
+ * [{{ doc.title }}]({{ doc.url }})
10
+ {% endfor %}
@@ -123,12 +123,10 @@
123
123
  </li>
124
124
  <li><a href="{% link _docs/layering.md %}">Layering</a>
125
125
  <ul>
126
- <li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
127
- <li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
128
- <li><a href="{% link _docs/layering/mix.md %}">Mix</a></li>
129
- <li><a href="{% link _docs/layering/merge-dsl.md %}">Merge DSL</a></li>
130
- <li><a href="{% link _docs/layering/merge-options.md %}">Merge Options</a></li>
131
- <li><a href="{% link _docs/layering/extra.md %}">Extra Layering</a></li>
126
+ {% assign docs = site.docs | where: "categories","layering" | sort: "order" %}
127
+ {% for doc in docs -%}
128
+ <li><a href="{{ doc.url }}">{% if doc.nav_text %}{{ doc.nav_text }}{% else %}{{ doc.title }}{% endif %}</a></li>
129
+ {% endfor %}
132
130
  </ul>
133
131
  </li>
134
132
  <li><a href="{% link _docs/dsl.md %}">DSL</a>
@@ -1,6 +1,7 @@
1
1
  module Kubes::Compiler::Shared
2
2
  module RuntimeHelpers
3
3
  include Kubes::Compiler::Shared::Helpers
4
+ include Kubes::Util::Pretty
4
5
 
5
6
  def load_runtime_helpers
6
7
  load_plugin_helpers
@@ -72,6 +73,10 @@ module Kubes::Compiler::Shared
72
73
  "#{role}/#{kind}/#{Kubes.env}.rb",
73
74
  "#{role}/#{kind}/#{Kubes.env}-#{Kubes.extra}.rb",
74
75
  ]
76
+ # filter out the -.rb layers when Kubes.extra is not set
77
+ # IE: .kubes/variables/dev-.rb
78
+ layers.reject! { |layer| layer.ends_with?('-.rb') }
79
+
75
80
  if Kubes.app
76
81
  app_layers = ["#{Kubes.app}.rb"]
77
82
  app_layers += layers.map do |path|
@@ -80,10 +85,34 @@ module Kubes::Compiler::Shared
80
85
  layers += app_layers
81
86
  end
82
87
 
83
- layers.each do |layer|
84
- path = "#{Kubes.root}/.kubes/variables/#{layer}"
88
+ layer_paths = layers.map { |layer| "#{Kubes.root}/.kubes/variables/#{layer}" }
89
+ layer_paths = layer_paths.select { |path| File.exist?(path) } unless ENV['KUBES_LAYERING_SHOW_ALL']
90
+ layer_paths.each do |path|
91
+ show_variable_layer_path(path)
85
92
  evaluate_file(path)
86
93
  end
87
94
  end
95
+
96
+ @@header_shown = {} # key is main @path
97
+ @@shown = {}
98
+ def show_variable_layer_path(path)
99
+ main_path = @path # main path is main resource file
100
+
101
+ show_header = !@@header_shown.dig(main_path)
102
+ if show_header && Kubes.config.layering.show
103
+ logger.info " Variables layers:"
104
+ @@header_shown[main_path] = true
105
+ end
106
+ # Examples:
107
+ # .kubes/resources/web/deployment.yaml
108
+ # .kubes/resources/shared/namespace.yaml
109
+ show_once = !@@shown.dig(main_path, path)
110
+ show_layer = Kubes.config.layering.show && show_once
111
+ if show_layer
112
+ logger.info " #{pretty_path(path)}"
113
+ @@shown[main_path] ||= {}
114
+ @@shown[main_path][path] = true
115
+ end
116
+ end
88
117
  end
89
118
  end
@@ -4,6 +4,7 @@ class Kubes::Compiler::Strategy
4
4
  include Kubes::Compiler::Util::Normalize
5
5
  include Kubes::Compiler::Util::SaveFile
6
6
  include Kubes::Logging
7
+ include Kubes::Util::Pretty
7
8
 
8
9
  def initialize(options={})
9
10
  @options = options
@@ -1,21 +1,33 @@
1
1
  class Kubes::Compiler::Strategy
2
2
  class Dispatcher < Base
3
3
  def dispatch
4
+ show_layers if Kubes.config.layering.show
4
5
  result = render(@path) # main
5
6
  results = [result].flatten # ensure array
6
7
  data = results.map! do |main|
7
8
  hash = Kubes.deep_merge!(pre_layer, main)
8
9
  Kubes.deep_merge!(hash, post_layer)
9
10
  end
11
+ logger.info "Compiled .kubes/output/#{@save_file}" if Kubes.config.layering.show
10
12
  Result.new(@save_file, data)
11
13
  end
12
14
 
15
+ def show_layers
16
+ logger.info "Compiling #{pretty_path(@path)}"
17
+ logger.info " Resource layers:"
18
+ all_layers = pre_layers + [@path] + post_layers
19
+ all_layers.each do |layer|
20
+ logger.info " #{pretty_path(layer)}"
21
+ end
22
+ end
23
+
13
24
  # Render via to Erb or one of the DSL syntax classes or Core/Blocks class
14
25
  def render(path)
15
26
  if path.include?('.rb')
16
27
  klass = dsl_class(path) # IE: Kubes::Compiler::Dsl::Syntax::Deployment or Kubes::Compiler::Dsl::Core::Blocks
17
28
  klass.new(@options.merge(path: path, data: @data)).run
18
29
  else
30
+ logger.info "Rendering #{pretty_path(path)}" if ENV['KUBES_LAYERING_SHOW_RENDERING']
19
31
  Erb.new(@options.merge(data: @data)).render_result(path)
20
32
  end
21
33
  end
@@ -24,7 +24,7 @@ module Kubes
24
24
 
25
25
  write_full
26
26
 
27
- logger.info "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
27
+ logger.info "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
28
28
  end
29
29
 
30
30
  def resources
@@ -51,7 +51,7 @@ module Kubes
51
51
  IO.write(dest, content)
52
52
  end
53
53
 
54
- logger.debug "Compiled #{pretty(dest)}"
54
+ logger.debug "Written #{pretty(dest)}"
55
55
  end
56
56
 
57
57
  def write_full
@@ -62,7 +62,7 @@ module Kubes
62
62
  path = "#{Kubes.root}/.kubes/tmp/full.yaml" # write to tmp instead of output so it doesnt interfere with kubes get
63
63
  FileUtils.mkdir_p(File.dirname(path))
64
64
  IO.write(path, content)
65
- logger.debug "Compiled #{pretty(path)}"
65
+ logger.debug "Written #{pretty(path)}"
66
66
  end
67
67
 
68
68
  def show_compiled_message?
data/lib/kubes/config.rb CHANGED
@@ -33,6 +33,9 @@ module Kubes
33
33
  config.repo = nil # expected to be set by .kubes/config.rb
34
34
  config.repo_auto_auth = true
35
35
 
36
+ config.layering = ActiveSupport::OrderedOptions.new
37
+ config.layering.show = ENV['KUBES_LAYERING_SHOW'] || false
38
+
36
39
  config.logger = Logger.new($stderr)
37
40
  config.logger.level = ENV['KUBES_LOG_LEVEL'] || :info
38
41
 
@@ -0,0 +1,7 @@
1
+ module Kubes::Util
2
+ module Pretty
3
+ def pretty_path(path)
4
+ path.sub("#{Kubes.root}/",'')
5
+ end
6
+ end
7
+ end
data/lib/kubes/util/sh.rb CHANGED
@@ -24,7 +24,7 @@ module Kubes::Util
24
24
  logger.info "=> #{command}" if show_command
25
25
  success = system(env, command)
26
26
  unless success
27
- logger.error "ERROR: running #{command}".color(:red)
27
+ logger.error "ERROR: running #{command}".color(:red) if exit_on_fail
28
28
  exit $?.exitstatus if exit_on_fail
29
29
  end
30
30
  success
data/lib/kubes/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.8.9"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  Kubes.configure do |config|
2
2
  config.repo = "<%= @options[:repo] %>"
3
- config.logger.level = "info"
3
+ # config.logger.level = "debug"
4
+ # config.layering.show = true
4
5
  # auto-switching
5
6
  # config.kubectl.context = "dev-cluster"
6
7
  # config.kubectl.context_keep = true # keep context after switching
@@ -5,5 +5,5 @@ metadata:
5
5
  labels:
6
6
  app: <%= app %>
7
7
  data:
8
- username: dXNlcg==
9
- password: cGFzcw==
8
+ username: <%%= base64("user") %>
9
+ password: <%%= base64("pass") %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.9
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -367,6 +367,7 @@ files:
367
367
  - docs/_docs/intro/ordering/custom.md
368
368
  - docs/_docs/intro/structure.md
369
369
  - docs/_docs/layering.md
370
+ - docs/_docs/layering/debug.md
370
371
  - docs/_docs/layering/dsl.md
371
372
  - docs/_docs/layering/extra.md
372
373
  - docs/_docs/layering/merge-dsl.md
@@ -722,6 +723,7 @@ files:
722
723
  - lib/kubes/logging.rb
723
724
  - lib/kubes/plugin.rb
724
725
  - lib/kubes/util/consider.rb
726
+ - lib/kubes/util/pretty.rb
725
727
  - lib/kubes/util/sh.rb
726
728
  - lib/kubes/util/sure.rb
727
729
  - lib/kubes/util/time.rb