kubes 0.8.8 → 0.9.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: 1c88d1788b4ecebd40180a69bcf8be5d7f8e8128ee40b1a4d7d862bc279697dd
4
- data.tar.gz: 8a072ba5a27be585a0e278ec1aaff1b16e3240c9ad8a86caa97536d912832f67
3
+ metadata.gz: db6959c3513133da9d5340dc8c332e15f86be47e5f72d47188243fafb21b3bd0
4
+ data.tar.gz: 94762322cb38b47c1d4167060545012dd6416515628801efdd969fc8dd189b91
5
5
  SHA512:
6
- metadata.gz: e2fb01f36269bc38b4123bc7321dc5f5787590af8b5ea74429aa0f494915378940ef7a22effd1edf67607c26a04ad040242009b0680b7e46a08747c257b8b357
7
- data.tar.gz: 5526ece8f8f78d7ca8fe9fac76ee4fb4171b6a9f505003382cafd9239a5d1d828b9c5fd2e61c1c3c3e01d1f7a5336cf72ed3f896128f15f5d46607eba1695a31
6
+ metadata.gz: 9a506b81df303fd915146596f792fcbd6b0ede5b93c81d6bcd75f0fa3123a47129086969decef3d44b273e6740d518facf91053c8f10e61ad3de6698c673a0e9
7
+ data.tar.gz: f2ddb1238b542b0279069a5b7417d4ed458384729cdd3859511b55222161c6443131ade97534f91fe19df9f20fae3074943a40120a3470bbf91142cd8d419a89
data/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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.0] - 2022-08-24
7
+ - [#66](https://github.com/boltops-tools/kubes/pull/66) show layering improvements: show resource layers also
8
+ - only show error if exit_on_fail
9
+
10
+ ## [0.8.10] - 2022-08-18
11
+ - [#65](https://github.com/boltops-tools/kubes/pull/65) show variables layers support
12
+ - improve new secret generator
13
+
14
+ ## [0.8.9] - 2022-08-11
15
+ - [#64](https://github.com/boltops-tools/kubes/pull/64) extra variable layering
16
+ - add extra layering docs
17
+
6
18
  ## [0.8.8] - 2022-08-11
7
19
  - add Kubes.extra method
8
20
  - update managed_certificate and ingress apiVersion
@@ -0,0 +1,62 @@
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 turning a config to show the **found** layers. Currently, only variables layering is shown.
12
+
13
+ .kubes/config.rb
14
+
15
+ ```ruby
16
+ Kubes.configure do |config|
17
+ config.layering.show = true
18
+ end
19
+ ```
20
+
21
+ This will show the **found** layers.
22
+
23
+ $ kubes compile
24
+ Compiling .kubes/resources/shared/namespace.yaml
25
+ .kubes/variables/base.rb
26
+ .kubes/variables/dev.rb
27
+ Compiling .kubes/resources/web/deployment.yaml
28
+ .kubes/variables/base.rb
29
+ .kubes/variables/dev.rb
30
+ Compiling .kubes/resources/web/service.yaml
31
+ .kubes/variables/base.rb
32
+ .kubes/variables/dev.rb
33
+
34
+ ## All Considered Layers
35
+
36
+ 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.
37
+
38
+ $ export KUBES_LAYERING_SHOW_ALL=1
39
+ Compiling .kubes/resources/web/deployment.yaml
40
+ Rendering .kubes/resources/web/deployment.yaml
41
+ .kubes/variables/base.rb
42
+ .kubes/variables/dev.rb
43
+ .kubes/variables/base/all.rb
44
+ .kubes/variables/base/all/dev.rb
45
+ .kubes/variables/base/deployment.rb
46
+ .kubes/variables/base/deployment/base.rb
47
+ .kubes/variables/base/deployment/dev.rb
48
+ .kubes/variables/web/deployment.rb
49
+ .kubes/variables/web/deployment/base.rb
50
+ .kubes/variables/web/deployment/dev.rb
51
+ Rendering .kubes/resources/base/all.yaml
52
+ .kubes/variables/base.rb
53
+ .kubes/variables/dev.rb
54
+ .kubes/variables/base/all.rb
55
+ .kubes/variables/base/all/dev.rb
56
+ .kubes/variables/base/deployment.rb
57
+ .kubes/variables/base/deployment/base.rb
58
+ .kubes/variables/base/deployment/dev.rb
59
+ .kubes/variables/web/deployment.rb
60
+ .kubes/variables/web/deployment/base.rb
61
+ .kubes/variables/web/deployment/dev.rb
62
+ ...
@@ -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" %}
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: Extra Layering
3
+ category: layering
4
+ order: 8
5
+ ---
6
+
7
+ Setting KUBES_EXTRA will process extra layers.
8
+
9
+ ## Variables
10
+
11
+ Example
12
+
13
+ KUBES_EXTRA=2 kubes deploy
14
+
15
+ Will process:
16
+
17
+ .kubes/variables/dev.rb
18
+ .kubes/variables/dev-2.rb
@@ -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,7 +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 %})
7
+ {% assign docs = site.docs | where: "categories","layering" | sort: "order" %}
8
+ {% for doc in docs -%}
9
+ * [{{ doc.title }}]({{ doc.url }})
10
+ {% endfor %}
@@ -123,11 +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>
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 %}
131
130
  </ul>
132
131
  </li>
133
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
@@ -59,15 +60,23 @@ module Kubes::Compiler::Shared
59
60
  layers = [
60
61
  "base.rb",
61
62
  "#{Kubes.env}.rb",
63
+ "#{Kubes.env}-#{Kubes.extra}.rb",
62
64
  "base/all.rb",
63
65
  "base/all/#{Kubes.env}.rb",
66
+ "base/all/#{Kubes.env}-#{Kubes.extra}.rb",
64
67
  "base/#{kind}.rb",
65
68
  "base/#{kind}/base.rb",
66
69
  "base/#{kind}/#{Kubes.env}.rb",
70
+ "base/#{kind}/#{Kubes.env}-#{Kubes.extra}.rb",
67
71
  "#{role}/#{kind}.rb",
68
72
  "#{role}/#{kind}/base.rb",
69
73
  "#{role}/#{kind}/#{Kubes.env}.rb",
74
+ "#{role}/#{kind}/#{Kubes.env}-#{Kubes.extra}.rb",
70
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
+
71
80
  if Kubes.app
72
81
  app_layers = ["#{Kubes.app}.rb"]
73
82
  app_layers += layers.map do |path|
@@ -76,10 +85,34 @@ module Kubes::Compiler::Shared
76
85
  layers += app_layers
77
86
  end
78
87
 
79
- layers.each do |layer|
80
- 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)
81
92
  evaluate_file(path)
82
93
  end
83
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
84
117
  end
85
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,6 +1,7 @@
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|
@@ -10,12 +11,22 @@ class Kubes::Compiler::Strategy
10
11
  Result.new(@save_file, data)
11
12
  end
12
13
 
14
+ def show_layers
15
+ logger.info "Compiling #{pretty_path(@path)}"
16
+ logger.info " Resource layers:"
17
+ all_layers = pre_layers + [@path] + post_layers
18
+ all_layers.each do |layer|
19
+ logger.info " #{pretty_path(layer)}"
20
+ end
21
+ end
22
+
13
23
  # Render via to Erb or one of the DSL syntax classes or Core/Blocks class
14
24
  def render(path)
15
25
  if path.include?('.rb')
16
26
  klass = dsl_class(path) # IE: Kubes::Compiler::Dsl::Syntax::Deployment or Kubes::Compiler::Dsl::Core::Blocks
17
27
  klass.new(@options.merge(path: path, data: @data)).run
18
28
  else
29
+ logger.info "Rendering #{pretty_path(path)}" if ENV['KUBES_LAYERING_SHOW_RENDERING']
19
30
  Erb.new(@options.merge(data: @data)).render_result(path)
20
31
  end
21
32
  end
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.8"
2
+ VERSION = "0.9.0"
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.8
4
+ version: 0.9.0
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,7 +367,9 @@ 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
372
+ - docs/_docs/layering/extra.md
371
373
  - docs/_docs/layering/merge-dsl.md
372
374
  - docs/_docs/layering/merge-options.md
373
375
  - docs/_docs/layering/mix.md
@@ -721,6 +723,7 @@ files:
721
723
  - lib/kubes/logging.rb
722
724
  - lib/kubes/plugin.rb
723
725
  - lib/kubes/util/consider.rb
726
+ - lib/kubes/util/pretty.rb
724
727
  - lib/kubes/util/sh.rb
725
728
  - lib/kubes/util/sure.rb
726
729
  - lib/kubes/util/time.rb