kubes 0.3.5 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +6 -5
  4. data/docs/_docs/config/args.md +10 -0
  5. data/docs/_docs/config/args/docker.md +19 -0
  6. data/docs/_docs/config/{kubectl/args.md → args/kubectl.md} +2 -0
  7. data/docs/_docs/config/docker.md +4 -40
  8. data/docs/_docs/config/hooks.md +10 -0
  9. data/docs/_docs/config/hooks/docker.md +70 -0
  10. data/docs/_docs/config/hooks/kubectl.md +83 -0
  11. data/docs/_docs/config/hooks/kubes.md +67 -0
  12. data/docs/_docs/config/hooks/ruby.md +76 -0
  13. data/docs/_docs/config/kubectl.md +2 -2
  14. data/docs/_docs/config/reference.md +20 -0
  15. data/docs/_docs/config/skip.md +58 -0
  16. data/docs/_docs/dsl/resources.md +1 -1
  17. data/docs/_docs/helpers.md +3 -2
  18. data/docs/_docs/intro.md +3 -1
  19. data/docs/_docs/learn/dsl/review-project.md +4 -2
  20. data/docs/_docs/learn/yaml/review-project.md +4 -2
  21. data/docs/_docs/patterns.md +4 -1
  22. data/docs/_docs/patterns/clock-web-worker.md +2 -0
  23. data/docs/_docs/patterns/migrations.md +123 -0
  24. data/docs/_docs/patterns/secrets.md +82 -0
  25. data/docs/_includes/config/hooks/options.md +20 -0
  26. data/docs/_includes/layering/layers.md +1 -1
  27. data/docs/_includes/sidebar.html +28 -13
  28. data/docs/_sass/theme.scss +25 -1
  29. data/kubes.gemspec +3 -0
  30. data/lib/kubes.rb +4 -1
  31. data/lib/kubes/cli.rb +20 -5
  32. data/lib/kubes/cli/apply.rb +2 -1
  33. data/lib/kubes/cli/base.rb +11 -0
  34. data/lib/kubes/cli/compile.rb +8 -0
  35. data/lib/kubes/cli/delete.rb +1 -1
  36. data/lib/kubes/cli/exec.rb +37 -6
  37. data/lib/kubes/cli/get.rb +1 -1
  38. data/lib/kubes/cli/init.rb +7 -2
  39. data/lib/kubes/cli/logs.rb +27 -3
  40. data/lib/kubes/cli/prune.rb +95 -0
  41. data/lib/kubes/compiler.rb +11 -7
  42. data/lib/kubes/compiler/decorator/base.rb +7 -1
  43. data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
  44. data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
  45. data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
  46. data/lib/kubes/compiler/decorator/post.rb +77 -0
  47. data/lib/kubes/compiler/decorator/pre.rb +12 -0
  48. data/lib/kubes/compiler/shared/helpers.rb +7 -2
  49. data/lib/kubes/compiler/strategy.rb +2 -2
  50. data/lib/kubes/compiler/strategy/base.rb +2 -3
  51. data/lib/kubes/compiler/strategy/dsl.rb +2 -2
  52. data/lib/kubes/compiler/strategy/erb.rb +8 -1
  53. data/lib/kubes/compiler/strategy/erb/yaml_error.rb +60 -0
  54. data/lib/kubes/compiler/strategy/result.rb +4 -6
  55. data/lib/kubes/compiler/util/normalize.rb +1 -1
  56. data/lib/kubes/compiler/util/save_file.rb +8 -0
  57. data/lib/kubes/config.rb +16 -11
  58. data/lib/kubes/docker/strategy/build/docker.rb +1 -1
  59. data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
  60. data/lib/kubes/docker/strategy/image_name.rb +1 -1
  61. data/lib/kubes/docker/strategy/push/docker.rb +1 -1
  62. data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
  63. data/lib/kubes/docker/strategy/utils.rb +1 -1
  64. data/lib/kubes/hooks/builder.rb +29 -15
  65. data/lib/kubes/hooks/concern.rb +10 -0
  66. data/lib/kubes/hooks/dsl.rb +2 -1
  67. data/lib/kubes/hooks/runner.rb +22 -0
  68. data/lib/kubes/kubectl.rb +21 -18
  69. data/lib/kubes/kubectl/batch.rb +8 -5
  70. data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
  71. data/lib/kubes/kubectl/fetch/base.rb +12 -9
  72. data/lib/kubes/kubectl/fetch/deployment.rb +12 -13
  73. data/lib/kubes/kubectl/fetch/pods.rb +4 -15
  74. data/lib/kubes/kubectl/kustomize.rb +1 -1
  75. data/lib/kubes/kubectl/ordering.rb +12 -0
  76. data/lib/kubes/util/consider.rb +2 -1
  77. data/lib/kubes/util/sh.rb +1 -1
  78. data/lib/kubes/version.rb +1 -1
  79. data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
  80. data/spec/fixtures/decorators/deployment/both/valueFrom.yaml +33 -0
  81. data/spec/fixtures/decorators/deployment/both/volumes.yaml +40 -0
  82. data/spec/fixtures/prune/capture.yaml +57 -0
  83. data/spec/fixtures/prune/fetch_items.yaml +268 -0
  84. data/spec/kubes/cli/prune_spec.rb +38 -0
  85. data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +52 -6
  86. data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
  87. metadata +56 -19
  88. data/docs/_docs/config/kubectl/hooks.md +0 -39
  89. data/lib/kubes/compiler/decorator.rb +0 -17
  90. data/lib/kubes/compiler/decorator/compile.rb +0 -12
  91. data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
  92. data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
  93. data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
  94. data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
  95. data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
  96. data/lib/kubes/compiler/decorator/write.rb +0 -14
  97. data/lib/kubes/docker/strategy/hooks.rb +0 -9
@@ -0,0 +1,38 @@
1
+ describe Kubes::CLI::Prune do
2
+ let(:prune) do
3
+ prune = described_class.new
4
+ allow(prune).to receive(:sure?)
5
+ allow(prune).to receive(:capture_items).and_return(capture)
6
+ allow(prune).to receive(:logger).and_return(null)
7
+ prune
8
+ end
9
+ let(:null) { double(:null).as_null_object }
10
+
11
+ let(:fetcher) do
12
+ fetcher = double(:fetcher).as_null_object
13
+ allow(fetcher).to receive(:fetch_items).and_return(fetch_items)
14
+ fetcher
15
+ end
16
+ before(:each) do
17
+ allow(Kubes::Kubectl::Fetch::Base).to receive(:new).and_return(fetcher)
18
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:md5s).and_return(built_kinds)
19
+ end
20
+
21
+ context("old resources") do
22
+ let(:fetch_items) { fixture("fetch_items.yaml") }
23
+ let(:capture) { fixture("capture.yaml") }
24
+ let(:built_kinds) do
25
+ {"Secret"=>{"demo-secret"=>"CURRENT111"}}
26
+ end
27
+
28
+ it "run" do
29
+ allow(Kubes::Kubectl).to receive(:execute)
30
+ prune.run
31
+ expect(Kubes::Kubectl).to have_received(:execute).at_least(:once)
32
+ end
33
+ end
34
+
35
+ def fixture(file)
36
+ YAML.load_file("spec/fixtures/prune/#{file}")
37
+ end
38
+ end
@@ -1,11 +1,14 @@
1
- describe Kubes::Compiler::Decorator::Resources::Deployment do
1
+ describe Kubes::Compiler::Decorator::Post do
2
2
  let(:decorator) { described_class.new(data) }
3
3
 
4
4
  def fixture(name)
5
5
  YAML.load_file("spec/fixtures/decorators/deployment/#{name}.yaml")
6
6
  end
7
7
  before(:each) do
8
- allow(Kubes::Compiler::Decorator).to receive(:fetch).and_return("fakehash")
8
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).and_return("fakehash")
9
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("Secret", "demo-secret").and_return("fakehash")
10
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("ConfigMap", "demo-config-map").and_return("fakehash-config")
11
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("ConfigMap", "demo-config-map-2").and_return("fakehash-config2")
9
12
  end
10
13
 
11
14
  context "secret" do
@@ -56,7 +59,7 @@ describe Kubes::Compiler::Decorator::Resources::Deployment do
56
59
  decorator.run
57
60
  data = decorator.data
58
61
  name = data['spec']['template']['spec']['containers'][0]['envFrom'][0]['configMapRef']['name']
59
- expect(name).to eq("demo-config-map-fakehash")
62
+ expect(name).to eq("demo-config-map-fakehash-config")
60
63
  end
61
64
  end
62
65
 
@@ -66,7 +69,7 @@ describe Kubes::Compiler::Decorator::Resources::Deployment do
66
69
  decorator.run
67
70
  data = decorator.data
68
71
  name = data['spec']['template']['spec']['containers'][0]['env'][0]['valueFrom']['configMapKeyRef']['name']
69
- expect(name).to eq("demo-config-map-fakehash")
72
+ expect(name).to eq("demo-config-map-fakehash-config")
70
73
  end
71
74
  end
72
75
 
@@ -76,7 +79,7 @@ describe Kubes::Compiler::Decorator::Resources::Deployment do
76
79
  decorator.run
77
80
  data = decorator.data
78
81
  name = data['spec']['template']['spec']['volumes'][0]['configMap']['name']
79
- expect(name).to eq("demo-config-map-fakehash")
82
+ expect(name).to eq("demo-config-map-fakehash-config")
80
83
  end
81
84
  end
82
85
 
@@ -85,7 +88,50 @@ describe Kubes::Compiler::Decorator::Resources::Deployment do
85
88
  it "data" do
86
89
  decorator.run
87
90
  name = data['spec']['template']['spec']['containers'][0]['envFrom'][0]['configMapRef']['name']
88
- expect(name).to eq("demo-config-map-fakehash")
91
+ expect(name).to eq("demo-config-map-fakehash-config")
92
+ end
93
+ end
94
+ end
95
+
96
+ context "both" do
97
+ describe "envFrom" do
98
+ let(:data) { fixture("both/envFrom") }
99
+ it "run" do
100
+ decorator.run
101
+ data = decorator.data
102
+ envFrom = data['spec']['template']['spec']['containers'][0]['envFrom']
103
+ name = envFrom[0]['secretRef']['name']
104
+ expect(name).to eq("demo-secret-fakehash")
105
+ name = envFrom[1]['configMapRef']['name']
106
+ expect(name).to eq("demo-config-map-fakehash-config")
107
+ name = envFrom[2]['configMapRef']['name']
108
+ expect(name).to eq("demo-config-map-2-fakehash-config2")
109
+ end
110
+ end
111
+
112
+ describe "valueFrom" do
113
+ let(:data) { fixture("both/valueFrom") }
114
+ it "run" do
115
+ decorator.run
116
+ data = decorator.data
117
+ valueFrom = data['spec']['template']['spec']['containers'][0]['env'][0]['valueFrom']
118
+ name = valueFrom['configMapKeyRef']['name']
119
+ expect(name).to eq("demo-config-map-fakehash-config")
120
+ name = valueFrom['secretKeyRef']['name']
121
+ expect(name).to eq("demo-secret-fakehash")
122
+ end
123
+ end
124
+
125
+ describe "volumes" do
126
+ let(:data) { fixture("both/volumes") }
127
+ it "run" do
128
+ decorator.run
129
+ data = decorator.data
130
+ volumes = data['spec']['template']['spec']['volumes']
131
+ name = volumes[0]['configMap']['name']
132
+ expect(name).to eq("demo-config-map-fakehash-config")
133
+ name = volumes[1]['secret']['secretName']
134
+ expect(name).to eq("demo-secret-fakehash")
89
135
  end
90
136
  end
91
137
  end
@@ -1,11 +1,11 @@
1
- describe Kubes::Compiler::Decorator::Resources::Pod do
1
+ describe Kubes::Compiler::Decorator::Post do
2
2
  let(:decorator) { described_class.new(data) }
3
3
 
4
4
  def fixture(name)
5
5
  YAML.load_file("spec/fixtures/decorators/pod/#{name}.yaml")
6
6
  end
7
7
  before(:each) do
8
- allow(Kubes::Compiler::Decorator).to receive(:fetch).and_return("fakehash")
8
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).and_return("fakehash")
9
9
  end
10
10
 
11
11
  context("secret") do
@@ -38,15 +38,6 @@ describe Kubes::Compiler::Decorator::Resources::Pod do
38
38
  expect(name).to eq("demo-secret-fakehash")
39
39
  end
40
40
  end
41
-
42
- describe "run" do
43
- let(:data) { fixture("secret/envFrom") }
44
- it "data" do
45
- decorator.run
46
- name = data['spec']['containers'][0]['envFrom'][0]['secretRef']['name']
47
- expect(name).to eq("demo-secret-fakehash")
48
- end
49
- end
50
41
  end
51
42
 
52
43
  context "configMap" do
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.3.5
4
+ version: 0.4.4
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-08-23 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: kubes_google
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: bundler
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -234,12 +248,20 @@ files:
234
248
  - docs/_config.yml
235
249
  - docs/_docs/ci/cloudbuild.md
236
250
  - docs/_docs/config.md
251
+ - docs/_docs/config/args.md
252
+ - docs/_docs/config/args/docker.md
253
+ - docs/_docs/config/args/kubectl.md
237
254
  - docs/_docs/config/builder.md
238
255
  - docs/_docs/config/docker.md
239
256
  - docs/_docs/config/env.md
257
+ - docs/_docs/config/hooks.md
258
+ - docs/_docs/config/hooks/docker.md
259
+ - docs/_docs/config/hooks/kubectl.md
260
+ - docs/_docs/config/hooks/kubes.md
261
+ - docs/_docs/config/hooks/ruby.md
240
262
  - docs/_docs/config/kubectl.md
241
- - docs/_docs/config/kubectl/args.md
242
- - docs/_docs/config/kubectl/hooks.md
263
+ - docs/_docs/config/reference.md
264
+ - docs/_docs/config/skip.md
243
265
  - docs/_docs/contributing.md
244
266
  - docs/_docs/dsl.md
245
267
  - docs/_docs/dsl/multiple-resources.md
@@ -300,12 +322,15 @@ files:
300
322
  - docs/_docs/next-steps.md
301
323
  - docs/_docs/patterns.md
302
324
  - docs/_docs/patterns/clock-web-worker.md
325
+ - docs/_docs/patterns/migrations.md
326
+ - docs/_docs/patterns/secrets.md
303
327
  - docs/_docs/resources.md
304
328
  - docs/_docs/resources/base.md
305
329
  - docs/_docs/resources/role.md
306
330
  - docs/_docs/resources/shared.md
307
331
  - docs/_docs/yaml.md
308
332
  - docs/_includes/commands.html
333
+ - docs/_includes/config/hooks/options.md
309
334
  - docs/_includes/content.html
310
335
  - docs/_includes/dsl/methods.md
311
336
  - docs/_includes/dsl/rolling_deployment.md
@@ -476,19 +501,16 @@ files:
476
501
  - lib/kubes/cli/help/exec.md
477
502
  - lib/kubes/cli/init.rb
478
503
  - lib/kubes/cli/logs.rb
504
+ - lib/kubes/cli/prune.rb
479
505
  - lib/kubes/cli/sequence.rb
480
506
  - lib/kubes/command.rb
481
507
  - lib/kubes/compiler.rb
482
- - lib/kubes/compiler/decorator.rb
483
508
  - lib/kubes/compiler/decorator/base.rb
484
- - lib/kubes/compiler/decorator/compile.rb
485
- - lib/kubes/compiler/decorator/resources/base.rb
486
- - lib/kubes/compiler/decorator/resources/container.rb
487
- - lib/kubes/compiler/decorator/resources/container/mapping.rb
488
- - lib/kubes/compiler/decorator/resources/deployment.rb
489
- - lib/kubes/compiler/decorator/resources/pod.rb
490
- - lib/kubes/compiler/decorator/resources/secret.rb
491
- - lib/kubes/compiler/decorator/write.rb
509
+ - lib/kubes/compiler/decorator/hashable.rb
510
+ - lib/kubes/compiler/decorator/hashable/field.rb
511
+ - lib/kubes/compiler/decorator/hashable/storage.rb
512
+ - lib/kubes/compiler/decorator/post.rb
513
+ - lib/kubes/compiler/decorator/pre.rb
492
514
  - lib/kubes/compiler/dsl/core/base.rb
493
515
  - lib/kubes/compiler/dsl/core/blocks.rb
494
516
  - lib/kubes/compiler/dsl/core/fields.rb
@@ -518,9 +540,11 @@ files:
518
540
  - lib/kubes/compiler/strategy/base.rb
519
541
  - lib/kubes/compiler/strategy/dsl.rb
520
542
  - lib/kubes/compiler/strategy/erb.rb
543
+ - lib/kubes/compiler/strategy/erb/yaml_error.rb
521
544
  - lib/kubes/compiler/strategy/pass.rb
522
545
  - lib/kubes/compiler/strategy/result.rb
523
546
  - lib/kubes/compiler/util/normalize.rb
547
+ - lib/kubes/compiler/util/save_file.rb
524
548
  - lib/kubes/compiler/util/yaml_dump.rb
525
549
  - lib/kubes/completer.rb
526
550
  - lib/kubes/completer/script.rb
@@ -532,20 +556,21 @@ files:
532
556
  - lib/kubes/docker/strategy/build/base.rb
533
557
  - lib/kubes/docker/strategy/build/docker.rb
534
558
  - lib/kubes/docker/strategy/build/gcloud.rb
535
- - lib/kubes/docker/strategy/hooks.rb
536
559
  - lib/kubes/docker/strategy/image_name.rb
537
560
  - lib/kubes/docker/strategy/push/base.rb
538
561
  - lib/kubes/docker/strategy/push/docker.rb
539
562
  - lib/kubes/docker/strategy/push/gcloud.rb
540
563
  - lib/kubes/docker/strategy/utils.rb
541
564
  - lib/kubes/hooks/builder.rb
565
+ - lib/kubes/hooks/concern.rb
542
566
  - lib/kubes/hooks/dsl.rb
567
+ - lib/kubes/hooks/runner.rb
543
568
  - lib/kubes/kubectl.rb
544
569
  - lib/kubes/kubectl/args/base.rb
545
570
  - lib/kubes/kubectl/args/kustomize.rb
546
571
  - lib/kubes/kubectl/args/standard.rb
547
572
  - lib/kubes/kubectl/batch.rb
548
- - lib/kubes/kubectl/decider.rb
573
+ - lib/kubes/kubectl/dispatcher.rb
549
574
  - lib/kubes/kubectl/fetch/base.rb
550
575
  - lib/kubes/kubectl/fetch/deployment.rb
551
576
  - lib/kubes/kubectl/fetch/pods.rb
@@ -579,6 +604,9 @@ files:
579
604
  - spec/fixtures/artifacts/demo-web/deployment.yaml
580
605
  - spec/fixtures/artifacts/demo-web/service.yaml
581
606
  - spec/fixtures/blocks/deployments.rb
607
+ - spec/fixtures/decorators/deployment/both/envFrom.yaml
608
+ - spec/fixtures/decorators/deployment/both/valueFrom.yaml
609
+ - spec/fixtures/decorators/deployment/both/volumes.yaml
582
610
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
583
611
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
584
612
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml
@@ -604,11 +632,14 @@ files:
604
632
  - spec/fixtures/project/.kubes/resources/deployment.rb
605
633
  - spec/fixtures/project/.kubes/resources/foobar.rb
606
634
  - spec/fixtures/project/.kubes/resources/service.rb
635
+ - spec/fixtures/prune/capture.yaml
636
+ - spec/fixtures/prune/fetch_items.yaml
607
637
  - spec/fixtures/services/minimum.rb
608
638
  - spec/fixtures/syntax/network_policy.rb
609
639
  - spec/fixtures/syntax/pod.rb
610
- - spec/kubes/compiler/decorator/resources/deployment_spec.rb
611
- - spec/kubes/compiler/decorator/resources/pod_spec.rb
640
+ - spec/kubes/cli/prune_spec.rb
641
+ - spec/kubes/compiler/decorator/post/deployment_spec.rb
642
+ - spec/kubes/compiler/decorator/post/pod_spec.rb
612
643
  - spec/kubes/compiler/strategy/dsl_spec.rb
613
644
  - spec/kubes/compiler_spec.rb
614
645
  - spec/kubes/dsl/daemon_set.rb
@@ -648,6 +679,9 @@ test_files:
648
679
  - spec/fixtures/artifacts/demo-web/deployment.yaml
649
680
  - spec/fixtures/artifacts/demo-web/service.yaml
650
681
  - spec/fixtures/blocks/deployments.rb
682
+ - spec/fixtures/decorators/deployment/both/envFrom.yaml
683
+ - spec/fixtures/decorators/deployment/both/valueFrom.yaml
684
+ - spec/fixtures/decorators/deployment/both/volumes.yaml
651
685
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
652
686
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
653
687
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml
@@ -673,11 +707,14 @@ test_files:
673
707
  - spec/fixtures/project/.kubes/resources/deployment.rb
674
708
  - spec/fixtures/project/.kubes/resources/foobar.rb
675
709
  - spec/fixtures/project/.kubes/resources/service.rb
710
+ - spec/fixtures/prune/capture.yaml
711
+ - spec/fixtures/prune/fetch_items.yaml
676
712
  - spec/fixtures/services/minimum.rb
677
713
  - spec/fixtures/syntax/network_policy.rb
678
714
  - spec/fixtures/syntax/pod.rb
679
- - spec/kubes/compiler/decorator/resources/deployment_spec.rb
680
- - spec/kubes/compiler/decorator/resources/pod_spec.rb
715
+ - spec/kubes/cli/prune_spec.rb
716
+ - spec/kubes/compiler/decorator/post/deployment_spec.rb
717
+ - spec/kubes/compiler/decorator/post/pod_spec.rb
681
718
  - spec/kubes/compiler/strategy/dsl_spec.rb
682
719
  - spec/kubes/compiler_spec.rb
683
720
  - spec/kubes/dsl/daemon_set.rb
@@ -1,39 +0,0 @@
1
- ---
2
- title: Kubectl Hooks
3
- ---
4
-
5
- Here are some examples of running custom hooks before and after the kubectl commands.
6
-
7
- .kubes/config/kubectl/hooks.rb
8
-
9
- ```ruby
10
- before("apply",
11
- execute: "kubectl apply -f .kubes/shared/namespace.yaml",
12
- )
13
-
14
- after("delete",
15
- execute: "echo 'delete hook',
16
- )
17
- ```
18
-
19
- You can use hooks to do things that may not make sense to do in the `.kubes/resources` definition. Here's an example of automatically creating the namespace.
20
-
21
- .kubes/shared/namespace.yaml
22
-
23
- ```yaml
24
- apiVersion: v1
25
- kind: Namespace
26
- metadata:
27
- name: demo
28
- ```
29
-
30
- ### exit on fail
31
-
32
- By default, if the hook commands fail, then terraspace will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
33
-
34
- ```ruby
35
- before("apply"
36
- execute: "/command/will/fail/but/will/continue",
37
- exit_on_fail: false,
38
- )
39
- ```
@@ -1,17 +0,0 @@
1
- class Kubes::Compiler
2
- module Decorator
3
- @@md5s = {}
4
- def store(name, md5)
5
- @@md5s[name] = md5
6
- end
7
-
8
- def fetch(name)
9
- @@md5s[name]
10
- end
11
-
12
- def md5s
13
- @@md5s
14
- end
15
- extend self
16
- end
17
- end
@@ -1,12 +0,0 @@
1
- module Kubes::Compiler::Decorator
2
- class Compile < Base
3
- def process(item)
4
- case item['kind']
5
- when "ConfigMap", "Secret"
6
- Resources::Secret.new(item).run
7
- else
8
- item # pass through
9
- end
10
- end
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- module Kubes::Compiler::Decorator::Resources
2
- class Base
3
- attr_reader :data
4
- def initialize(data)
5
- @data = data
6
- end
7
-
8
- def run
9
- return @data unless Kubes.config.suffix_hash
10
- perform
11
- end
12
- end
13
- end
@@ -1,76 +0,0 @@
1
- module Kubes::Compiler::Decorator::Resources
2
- class Container
3
- include Mapping
4
-
5
- def initialize(data, kind:, fields_for:)
6
- @data = data
7
- # These methods are defined in Mapping
8
- kind == "Deployment" ? deployment_keys : pod_keys
9
- fields_for == "Secret" ? secrets_fields : configMaps_fields
10
- end
11
-
12
- def run
13
- envFrom!
14
- valueFrom!
15
- volumes!
16
- @data
17
- end
18
-
19
- # spec.envFrom.configMapRef
20
- # spec.envFrom.secretRef
21
- def envFrom!
22
- return @data unless containers
23
-
24
- containers.each do |container|
25
- next unless envFrom_list = container.dig('envFrom') # intentional assignment
26
-
27
- envFrom_list.each do |envFrom|
28
- next unless name = envFrom.dig(@envFrom_field, 'name') # intentional assignment
29
-
30
- md5 = Kubes::Compiler::Decorator.fetch(name)
31
- envFrom[@envFrom_field]['name'] = [name, md5].compact.join('-')
32
- end
33
- end
34
- end
35
-
36
- # spec.valueFrom.configMapKeyRef
37
- # spec.valueFrom.secretKeyRef
38
- def valueFrom!
39
- return @data unless containers
40
-
41
- containers.each do |container|
42
- next unless env_list = container.dig('env') # intentional assignment
43
-
44
- env_list.each do |env|
45
- next unless name = env.dig('valueFrom',@valueFrom_field,'name') # intentional assignment
46
-
47
- md5 = Kubes::Compiler::Decorator.fetch(name)
48
- env['valueFrom'][@valueFrom_field]['name'] = [name, md5].compact.join('-')
49
- end
50
- end
51
- end
52
-
53
- # spec.volumes.configMap.name
54
- # spec.volumes.secret.secretName
55
- def volumes!
56
- volumes = @data.dig(*@volumes_key.split('.'))
57
- return @data unless volumes
58
-
59
- volumes.each do |volume|
60
- # Example:
61
- # next unless field = volume.dig('secret') # intentional assignment
62
- # next unless name = field['secretName'] # intentional assignment
63
- next unless field = volume.dig(@volume_field) # intentional assignment
64
- next unless name = field[@volume_field_name] # intentional assignment
65
-
66
- md5 = Kubes::Compiler::Decorator.fetch(name)
67
- field[@volume_field_name] = [name, md5].compact.join('-')
68
- end
69
- end
70
-
71
- private
72
- def containers
73
- @data.dig(*@containers_key.split('.'))
74
- end
75
- end
76
- end