kubes 0.6.5 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +7 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  4. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  8. data/CHANGELOG.md +16 -0
  9. data/docs/_docs/dsl/multiple-resources.md +19 -21
  10. data/docs/_docs/helpers/google.md +1 -1
  11. data/docs/_docs/helpers/google/gke.md +7 -3
  12. data/docs/_docs/helpers/google/secrets.md +1 -1
  13. data/docs/_docs/intro/concepts.md +8 -9
  14. data/docs/_docs/intro/ordering.md +9 -10
  15. data/docs/_docs/resources/role.md +8 -9
  16. data/docs/_docs/yaml.md +4 -5
  17. data/docs/_docs/yaml/multiple-files.md +22 -0
  18. data/docs/_docs/yaml/multiple-resources.md +89 -0
  19. data/docs/_includes/commands.html +8 -9
  20. data/docs/_includes/config/hooks/options.md +1 -0
  21. data/docs/_includes/layering/layers.md +7 -4
  22. data/docs/_includes/sidebar.html +6 -1
  23. data/docs/_includes/vs/kubes/structure.md +12 -13
  24. data/kubes.gemspec +2 -2
  25. data/lib/kubes/command.rb +1 -1
  26. data/lib/kubes/compiler/dsl/core/base.rb +3 -7
  27. data/lib/kubes/compiler/dsl/core/blocks.rb +5 -1
  28. data/lib/kubes/compiler/dsl/syntax/endpoint.rb +34 -0
  29. data/lib/kubes/compiler/dsl/syntax/resource.rb +0 -1
  30. data/lib/kubes/compiler/layering.rb +3 -7
  31. data/lib/kubes/compiler/shared/runtime_helpers.rb +78 -0
  32. data/lib/kubes/compiler/strategy.rb +1 -15
  33. data/lib/kubes/compiler/strategy/base.rb +0 -56
  34. data/lib/kubes/compiler/strategy/dispatcher.rb +60 -0
  35. data/lib/kubes/compiler/strategy/erb.rb +8 -14
  36. data/lib/kubes/compiler/strategy/result.rb +6 -2
  37. data/lib/kubes/compiler/util/normalize.rb +2 -2
  38. data/lib/kubes/compiler/util/yaml_dump.rb +7 -4
  39. data/lib/kubes/version.rb +1 -1
  40. data/lib/templates/new/resource/dsl/endpoint.rb +3 -0
  41. data/lib/templates/new/resource/yaml/endpoint.yaml +9 -0
  42. data/spec/kubes/compiler/strategy/{dsl_spec.rb → dispatcher_spec.rb} +10 -9
  43. metadata +21 -12
  44. data/lib/kubes/compiler/shared/custom_helpers.rb +0 -17
  45. data/lib/kubes/compiler/shared/custom_variables.rb +0 -38
  46. data/lib/kubes/compiler/shared/plugin_helpers.rb +0 -14
  47. data/lib/kubes/compiler/strategy/dsl.rb +0 -4
@@ -6,23 +6,9 @@ class Kubes::Compiler
6
6
  end
7
7
 
8
8
  def compile
9
- klass = strategy_class
10
- return false unless klass
11
-
12
- strategy = klass.new(@options.merge(path: @path)) # Dsl or Erb
13
- result = strategy.run
9
+ result = Dispatcher.new(@options.merge(path: @path)).dispatch
14
10
  result.decorate!(:pre) # compile pre phase decoration
15
11
  result
16
12
  end
17
-
18
- def strategy_class
19
- ext = File.extname(@path).sub('.','').to_sym
20
- map = {
21
- rb: Dsl,
22
- yaml: Erb,
23
- yml: Erb,
24
- }
25
- map[ext]
26
- end
27
13
  end
28
14
  end
@@ -9,62 +9,6 @@ class Kubes::Compiler::Strategy
9
9
  @options = options
10
10
  @path = options[:path]
11
11
  @save_file = save_file(@path)
12
- @data = @options[:data] || {}
13
- end
14
-
15
- def run
16
- render_files(pre_layers)
17
- render(@path) # main resource definition
18
- render_files(post_layers)
19
-
20
- Result.new(@save_file, @data)
21
- end
22
-
23
- def render_files(paths)
24
- paths.each do |path|
25
- next unless File.exist?(path) # layers may not exist
26
- render(path)
27
- end
28
- end
29
-
30
- # render and merge
31
- def render(path)
32
- result = render_strategy(path)
33
- if result.is_a?(Kubes::Compiler::Dsl::Core::Blocks)
34
- result = result.results
35
- end
36
- @data.deeper_merge!(result)
37
- end
38
-
39
- # Delegate to Dsl or Erb strategy again and pass @data down to allow rendering of a mix of yaml and rb files.
40
- def render_strategy(path)
41
- if path.include?('.rb')
42
- dsl_class.new(@options.merge(path: path, data: @data)).run
43
- else
44
- Erb.new(@options.merge(data: @data)).render_result(path)
45
- end
46
- end
47
-
48
- # Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render_strategy
49
- def dsl_class
50
- if block_form?
51
- Kubes::Compiler::Dsl::Core::Blocks
52
- else
53
- syntax_class
54
- end
55
- end
56
-
57
- def syntax_class
58
- klass_name = normalize_kind(@save_file) # IE: @save_file: web/service.yaml
59
- "Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
60
- rescue NameError
61
- logger.debug "Using default resource for: #{klass_name}"
62
- Kubes::Compiler::Dsl::Syntax::Resource # default
63
- end
64
-
65
- def block_form?
66
- type = extract_type(@save_file)
67
- type.pluralize == type
68
12
  end
69
13
  end
70
14
  end
@@ -0,0 +1,60 @@
1
+ class Kubes::Compiler::Strategy
2
+ class Dispatcher < Base
3
+ def dispatch
4
+ result = render(@path) # main
5
+ results = [result].flatten # ensure array
6
+ data = results.map! do |main|
7
+ hash = pre_layer.deeper_merge!(main) # need the ! or deep_merge returns original hash
8
+ hash.deeper_merge!(post_layer)
9
+ end
10
+ Result.new(@save_file, data)
11
+ end
12
+
13
+ # Render via to Erb or one of the DSL syntax classes or Core/Blocks class
14
+ def render(path)
15
+ if path.include?('.rb')
16
+ klass = dsl_class(path) # IE: Kubes::Compiler::Dsl::Syntax::Deployment or Kubes::Compiler::Dsl::Core::Blocks
17
+ klass.new(@options.merge(path: path, data: @data)).run
18
+ else
19
+ Erb.new(@options.merge(data: @data)).render_result(path)
20
+ end
21
+ end
22
+
23
+ # Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render
24
+ def dsl_class(path)
25
+ if block_form?(path)
26
+ Kubes::Compiler::Dsl::Core::Blocks
27
+ else
28
+ syntax_class
29
+ end
30
+ end
31
+
32
+ def syntax_class
33
+ klass_name = normalize_kind(@save_file) # IE: @save_file: web/service.yaml
34
+ "Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
35
+ rescue NameError
36
+ logger.debug "Using default resource for: #{klass_name}"
37
+ Kubes::Compiler::Dsl::Syntax::Resource # default
38
+ end
39
+
40
+ def block_form?(path)
41
+ type = extract_type(path)
42
+ type.pluralize == type
43
+ end
44
+
45
+ def pre_layer
46
+ merge_layers(pre_layers)
47
+ end
48
+
49
+ def post_layer
50
+ merge_layers(post_layers)
51
+ end
52
+
53
+ def merge_layers(layers)
54
+ layers.inject({}) do |hash, layer|
55
+ data = render(layer)
56
+ hash.deep_merge!(data)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -5,28 +5,22 @@ class Kubes::Compiler::Strategy
5
5
  extend Kubes::Compiler::Dsl::Core::Fields
6
6
  include Kubes::Compiler::Dsl::Core::Helpers
7
7
  include Kubes::Compiler::Layering
8
- include Kubes::Compiler::Shared::CustomHelpers
9
- include Kubes::Compiler::Shared::CustomVariables
10
- include Kubes::Compiler::Shared::Helpers
11
- include Kubes::Compiler::Shared::PluginHelpers
8
+ include Kubes::Compiler::Shared::RuntimeHelpers
12
9
 
13
10
  def initialize(options={})
14
11
  super
15
12
  # For ERB scope is in this same Strategy::Erb class
16
13
  # For DSL scope is within the each for the Resource classes. IE: kubes/compile/dsl/core/base.rb
17
- load_plugin_helpers
18
- load_custom_variables
19
- load_custom_helpers
14
+ load_runtime_helpers
20
15
  end
21
16
 
22
17
  def render_result(path)
23
- if File.exist?(path)
24
- yaml = RenderMePretty.result(path, context: self)
25
- result = yaml_load(path, yaml)
26
- result.is_a?(Hash) ? result : {} # in case of blank yaml doc a Boolean false is returned
27
- else
28
- {}
29
- end
18
+ return unless File.exist?(path)
19
+
20
+ yaml = RenderMePretty.result(path, context: self)
21
+ result = yaml_load(path, yaml)
22
+ # in case of blank yaml doc a Boolean false is returned. else Hash or Array is returned
23
+ %w[Array Hash].include?(result.class.to_s) ? result : {}
30
24
  end
31
25
 
32
26
  def yaml_load(path, yaml)
@@ -14,11 +14,15 @@ class Kubes::Compiler::Strategy
14
14
  # decorate(:pre) or decorate(:post)
15
15
  def decorate!(phase)
16
16
  klass = "Kubes::Compiler::Decorator::#{phase.to_s.camelize}".constantize
17
- @data = klass.new(@data).result
17
+ results = [@data].flatten
18
+ results.map! do |r|
19
+ klass.new(r).result
20
+ end
18
21
  end
19
22
 
20
23
  def content
21
- yaml_dump(@data)
24
+ result = @data.size == 1 ? @data.first : @data
25
+ yaml_dump(result)
22
26
  end
23
27
  end
24
28
  end
@@ -1,12 +1,12 @@
1
1
  module Kubes::Compiler::Util
2
2
  module Normalize
3
3
  def normalize_kind(path)
4
- info = path.sub(%r{.*/.kubes/resources/}, '')
5
- extract_type(info).underscore.camelize # Deployment, Service, Ingress, ManagedCertificate, etc
4
+ extract_type(path).underscore.camelize # Deployment, Service, Ingress, ManagedCertificate, etc
6
5
  end
7
6
 
8
7
  # info: web/service.yaml
9
8
  def extract_type(info)
9
+ info = info.sub(%r{.*/.kubes/resources/}, '')
10
10
  _, kind = info.split('/')
11
11
  kind.sub('.yaml','').sub('.yml','').sub('.rb','').sub(/-.*/,'')
12
12
  end
@@ -4,12 +4,15 @@ require "yaml"
4
4
  module Kubes::Compiler::Util
5
5
  module YamlDump
6
6
  def yaml_dump(data)
7
- if data.key?("kind") # single resource in YAML
7
+ case data
8
+ when Array
9
+ items = data.map do |i|
10
+ standardize_yaml(i)
11
+ end
12
+ items.map(&:to_yaml).join("")
13
+ else # single resource in YAML
8
14
  data = standardize_yaml(data)
9
15
  data.to_yaml
10
- else
11
- items = data.map { |k,v| standardize_yaml(v) }
12
- items.map(&:to_yaml).join("")
13
16
  end
14
17
  end
15
18
 
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.6.5"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,3 @@
1
+ name "<%= app %>"
2
+ addresses(["1.1.1.1"])
3
+ ports(["80"])
@@ -0,0 +1,9 @@
1
+ apiVersion: v1
2
+ kind: Endpoints
3
+ metadata:
4
+ name: <%= app %>
5
+ subsets:
6
+ - addresses:
7
+ - ip: 192.0.2.42
8
+ ports:
9
+ - port: 9376
@@ -1,12 +1,13 @@
1
- describe Kubes::Compiler::Strategy::Dsl do
2
- let(:dsl) { described_class.new(options) }
3
- let(:options) { {path: fixture(resource) } }
1
+ describe Kubes::Compiler::Strategy::Dispatcher do
2
+ let(:dispatcher) { described_class.new(options) }
3
+ let(:options) { {path: path } }
4
+ let(:path) { fixture(resource) }
4
5
 
5
6
  context "standard" do
6
7
  let(:resource) { "project/.kubes/resources/web/deployment" }
7
8
  it "run" do
8
- result = dsl.run
9
- expect(dsl.dsl_class).to eq(Kubes::Compiler::Dsl::Syntax::Deployment)
9
+ result = dispatcher.dispatch
10
+ expect(dispatcher.dsl_class(path)).to eq(Kubes::Compiler::Dsl::Syntax::Deployment)
10
11
  data = YAML.load(result.content)
11
12
  expect(data['kind']).to eq "Deployment"
12
13
  end
@@ -15,8 +16,8 @@ describe Kubes::Compiler::Strategy::Dsl do
15
16
  context "blocks" do
16
17
  let(:resource) { "blocks/deployments" }
17
18
  it "run" do
18
- result = dsl.run
19
- expect(dsl.dsl_class).to eq(Kubes::Compiler::Dsl::Core::Blocks)
19
+ result = dispatcher.dispatch
20
+ expect(dispatcher.dsl_class(path)).to eq(Kubes::Compiler::Dsl::Core::Blocks)
20
21
  resource = result.content.split('---').last
21
22
  data = YAML.load(resource)
22
23
  expect(data['kind']).to eq "Deployment"
@@ -27,8 +28,8 @@ describe Kubes::Compiler::Strategy::Dsl do
27
28
  context "multiple files" do
28
29
  let(:resource) { "multiple-files/.kubes/resources/web/deployment-1" }
29
30
  it "run" do
30
- result = dsl.run
31
- expect(dsl.dsl_class).to eq(Kubes::Compiler::Dsl::Syntax::Deployment)
31
+ result = dispatcher.dispatch
32
+ expect(dispatcher.dsl_class(path)).to eq(Kubes::Compiler::Dsl::Syntax::Deployment)
32
33
  data = YAML.load(result.content)
33
34
  expect(data['kind']).to eq "Deployment"
34
35
  end
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.6.5
4
+ version: 0.7.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: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,28 +142,28 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.3.0
145
+ version: 0.3.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.3.0
152
+ version: 0.3.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: kubes_google
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.3.2
159
+ version: 0.3.5
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.3.2
166
+ version: 0.3.5
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: bundler
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -244,6 +244,12 @@ extra_rdoc_files: []
244
244
  files:
245
245
  - ".dockerignore"
246
246
  - ".gcloudignore"
247
+ - ".github/ISSUE_TEMPLATE.md"
248
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
249
+ - ".github/ISSUE_TEMPLATE/documentation.md"
250
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
251
+ - ".github/ISSUE_TEMPLATE/question.md"
252
+ - ".github/PULL_REQUEST_TEMPLATE.md"
247
253
  - ".gitignore"
248
254
  - ".rspec"
249
255
  - CHANGELOG.md
@@ -377,6 +383,8 @@ files:
377
383
  - docs/_docs/vs/helm.md
378
384
  - docs/_docs/vs/kustomize.md
379
385
  - docs/_docs/yaml.md
386
+ - docs/_docs/yaml/multiple-files.md
387
+ - docs/_docs/yaml/multiple-resources.md
380
388
  - docs/_includes/commands.html
381
389
  - docs/_includes/config/hooks/options.md
382
390
  - docs/_includes/content.html
@@ -593,6 +601,7 @@ files:
593
601
  - lib/kubes/compiler/dsl/syntax/config_map.rb
594
602
  - lib/kubes/compiler/dsl/syntax/daemon_set.rb
595
603
  - lib/kubes/compiler/dsl/syntax/deployment.rb
604
+ - lib/kubes/compiler/dsl/syntax/endpoint.rb
596
605
  - lib/kubes/compiler/dsl/syntax/ingress.rb
597
606
  - lib/kubes/compiler/dsl/syntax/job.rb
598
607
  - lib/kubes/compiler/dsl/syntax/managed_certificate.rb
@@ -606,14 +615,12 @@ files:
606
615
  - lib/kubes/compiler/dsl/syntax/service.rb
607
616
  - lib/kubes/compiler/dsl/syntax/service_account.rb
608
617
  - lib/kubes/compiler/layering.rb
609
- - lib/kubes/compiler/shared/custom_helpers.rb
610
- - lib/kubes/compiler/shared/custom_variables.rb
611
618
  - lib/kubes/compiler/shared/helpers.rb
612
619
  - lib/kubes/compiler/shared/helpers/deprecated.rb
613
- - lib/kubes/compiler/shared/plugin_helpers.rb
620
+ - lib/kubes/compiler/shared/runtime_helpers.rb
614
621
  - lib/kubes/compiler/strategy.rb
615
622
  - lib/kubes/compiler/strategy/base.rb
616
- - lib/kubes/compiler/strategy/dsl.rb
623
+ - lib/kubes/compiler/strategy/dispatcher.rb
617
624
  - lib/kubes/compiler/strategy/erb.rb
618
625
  - lib/kubes/compiler/strategy/erb/yaml_error.rb
619
626
  - lib/kubes/compiler/strategy/pass.rb
@@ -674,6 +681,7 @@ files:
674
681
  - lib/templates/new/resource/dsl/config_map.rb
675
682
  - lib/templates/new/resource/dsl/daemon_set.rb
676
683
  - lib/templates/new/resource/dsl/deployment.rb
684
+ - lib/templates/new/resource/dsl/endpoint.rb
677
685
  - lib/templates/new/resource/dsl/ingress.rb
678
686
  - lib/templates/new/resource/dsl/job.rb
679
687
  - lib/templates/new/resource/dsl/managed_certificate.rb
@@ -689,6 +697,7 @@ files:
689
697
  - lib/templates/new/resource/yaml/config_map.yaml
690
698
  - lib/templates/new/resource/yaml/daemon_set.yaml
691
699
  - lib/templates/new/resource/yaml/deployment.yaml
700
+ - lib/templates/new/resource/yaml/endpoint.yaml
692
701
  - lib/templates/new/resource/yaml/ingress.yaml
693
702
  - lib/templates/new/resource/yaml/job.yaml
694
703
  - lib/templates/new/resource/yaml/managed_certificate.yaml
@@ -748,7 +757,7 @@ files:
748
757
  - spec/kubes/cli/prune_spec.rb
749
758
  - spec/kubes/compiler/decorator/post/deployment_spec.rb
750
759
  - spec/kubes/compiler/decorator/post/pod_spec.rb
751
- - spec/kubes/compiler/strategy/dsl_spec.rb
760
+ - spec/kubes/compiler/strategy/dispatcher_spec.rb
752
761
  - spec/kubes/compiler_spec.rb
753
762
  - spec/kubes/dsl/daemon_set.rb
754
763
  - spec/kubes/dsl/deployment_spec.rb
@@ -823,7 +832,7 @@ test_files:
823
832
  - spec/kubes/cli/prune_spec.rb
824
833
  - spec/kubes/compiler/decorator/post/deployment_spec.rb
825
834
  - spec/kubes/compiler/decorator/post/pod_spec.rb
826
- - spec/kubes/compiler/strategy/dsl_spec.rb
835
+ - spec/kubes/compiler/strategy/dispatcher_spec.rb
827
836
  - spec/kubes/compiler_spec.rb
828
837
  - spec/kubes/dsl/daemon_set.rb
829
838
  - spec/kubes/dsl/deployment_spec.rb
@@ -1,17 +0,0 @@
1
- module Kubes::Compiler::Shared
2
- module CustomHelpers
3
- # Load custom helper methods from project
4
- @@custom_helpers_loaded = false
5
- def load_custom_helpers
6
- return if @@custom_helpers_loaded
7
- paths = Dir.glob("#{Kubes.root}/.kubes/helpers/**/*.rb")
8
- paths.sort_by! { |p| p.size } # so namespaces are loaded first
9
- paths.each do |path|
10
- filename = path.sub(%r{.*.kubes/helpers/},'').sub('.rb','')
11
- module_name = filename.camelize
12
- self.class.send :include, module_name.constantize
13
- end
14
- @@custom_helpers_loaded = true
15
- end
16
- end
17
- end