kubes 0.4.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d309f1eb882767efd06378aa5bff9fbe8e162db4ebcd19b9ffec2637929d8b0
4
- data.tar.gz: a60c4ae73920a38cda6780f435475922f318409e34aed8dec827df0b8483d6c5
3
+ metadata.gz: cb9cf7b5db064114c31e2af08890c009831a4b68baf556052e672a71cf08f562
4
+ data.tar.gz: 70bdcad829b4cee02f69b4cf36fbac8e41023445c407f484bc171e2a67d9bd99
5
5
  SHA512:
6
- metadata.gz: 600df214d8b09d66bbea43b3114dc8dd3b41011025e76e2741ce2a076fa4af1ab8f07b68e54f1aeaaa72d166a1c9c2970c34f22f314b14b99384c00d8818aee4
7
- data.tar.gz: 491bf32c8f78ce324aa500d57976345e28696d2fa483b6c8671d92c62191a3c84ffe11048b743251903c4b9b2ff1a0dc7c92b86211b9b909f8fcb5d813c79b7a
6
+ metadata.gz: '08dfce3916b92c0498915d0e7bf5d75608f111013eca67f5d9802f30250e0412c76afcd08f7ad2dd7d72ca413d13390a6d07b9d2c56b182fd0c04247ae1f9708'
7
+ data.tar.gz: dd255951bb8421f80d666492cd1e03ac363364abb441c4ded7db33562cd6450f6f2f397230c84c20a24f9b98d72e00cd3463cfde8c2ed1e93875dcd2aaa5ec58
@@ -3,6 +3,11 @@
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.4.1]
7
+ - kubes init: default namespace now includes Kubes.env
8
+ - fix kubes deploy: compile it gets called once and output folder kept
9
+ - include kubes_google dependency helpers
10
+
6
11
  ## [0.4.0]
7
12
  - #26 features: kubes vs kubectl hooks, prune, etc
8
13
  - hooks: kubes, kubectl, docker breaking changes.
@@ -58,7 +58,7 @@ Results in:
58
58
 
59
59
  ## exit_on_fail option
60
60
 
61
- 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.
61
+ By default, if the hook commands fail, then kubes will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
62
62
 
63
63
  ```ruby
64
64
  before("build"
@@ -70,7 +70,7 @@ The `on` option is used to match the path the gets applied: .kubes/resources/**w
70
70
 
71
71
  ## exit on fail
72
72
 
73
- 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.
73
+ By default, if the hook commands fail, then kubes will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
74
74
 
75
75
  ```ruby
76
76
  before("apply"
@@ -46,7 +46,7 @@ metadata:
46
46
  apiVersion: v1
47
47
  kind: Secret
48
48
  data:
49
- foo: <%= ENV['SECRET_FOO']
49
+ foo: <%= ENV['SECRET_FOO'] %>
50
50
  ```
51
51
 
52
52
  ## Ruby Object
@@ -11,10 +11,12 @@ We'll create a namespace for the app resources:
11
11
  .kubes/resources/shared/namespace.rb
12
12
 
13
13
  ```ruby
14
- name "demo"
14
+ name "demo-#{Kubes.env}"
15
15
  labels(app: "demo")
16
16
  ```
17
17
 
18
+ Notice, the `#{Kubes.env}`. Kubes adds the env to the namespace by default. You can change this with the `init --namespace` option.
19
+
18
20
  ## Deployment
19
21
 
20
22
  The `web/deployment.rb` file is a little more interesting:
@@ -39,7 +41,7 @@ Also let's check the files in the base folder.
39
41
  .kubes/resources/base/all.rb
40
42
 
41
43
  ```ruby
42
- namespace "default"
44
+ namespace "demo-#{Kubes.env}"
43
45
  labels(app: "demo")
44
46
  ```
45
47
 
@@ -14,11 +14,13 @@ We'll create a namespace for the app resources:
14
14
  apiVersion: v1
15
15
  kind: Namespace
16
16
  metadata:
17
- name: demo
17
+ name: demo-<%= Kubes.env %>
18
18
  labels:
19
19
  app: demo
20
20
  ```
21
21
 
22
+ Notice, the `<%= Kubes.env %>`. Kubes adds the env to the namespace by default. You can change this with the `init --namespace` option.
23
+
22
24
  ## Deployment
23
25
 
24
26
  The `web/deployment.yaml` file is a little more interesting:
@@ -57,7 +59,7 @@ Also let's check the files in the base folder.
57
59
 
58
60
  ```yaml
59
61
  metadata:
60
- namespace: demo
62
+ namespace: demo-<%= Kubes.env %>
61
63
  ```
62
64
 
63
65
  .kubes/resources/base/deployment.yaml
@@ -10,7 +10,7 @@ The command name corresponds to the `{{ include.command }}` commands: apply, del
10
10
 
11
11
  Name | Description
12
12
  ---|---
13
- label | A human-friendly label so you can see what hooks is being run during `kubes apply`
13
+ label | A human-friendly label so you can see what hooks is being run.
14
14
  execute | The script or command to run. IE: path/to/some/script.sh
15
15
  exit_on_fail | Whether or not to continue process if the script returns an failed exit code.
16
16
  {% if include.command == "kubectl" %}on | What resource to run the hook on. IE: shared/namespace, web/deployment, web/service. Note: This option is only used by kubectl hooks.{% endif %}
@@ -28,6 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "thor"
29
29
  spec.add_dependency "zeitwerk"
30
30
 
31
+ # core helper libs
32
+ spec.add_dependency "kubes_google"
33
+
31
34
  spec.add_development_dependency "bundler"
32
35
  spec.add_development_dependency "byebug"
33
36
  spec.add_development_dependency "cli_markdown"
@@ -14,6 +14,9 @@ require "memoist"
14
14
  require "rainbow/ext/string"
15
15
  require "yaml"
16
16
 
17
+ # core helper libraries
18
+ require "kubes_google"
19
+
17
20
  DslEvaluator.backtrace_reject = ".kubes"
18
21
 
19
22
  require "kubes/autoloader"
@@ -1,8 +1,16 @@
1
1
  class Kubes::CLI
2
2
  class Compile < Base
3
+ # Separate command like prune can call compile. Apply also calls Prune.
4
+ # Instead of moving Compile out of Prune, will use this class variable.
5
+ # In case we have other cases where compile is called in another area.
6
+ # We only want compiled to be called once so hooks only fire once.
7
+ # Done here so we don't clean and remove the .kubes/output folder.
8
+ @@compiled = false
3
9
  def run
10
+ return if @@compiled
4
11
  Clean.new(@options.merge(mute: true)).run
5
12
  Kubes::Compiler.new(@options).run
13
+ @@compiled = true
6
14
  end
7
15
  end
8
16
  end
@@ -6,7 +6,7 @@ class Kubes::CLI
6
6
  [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
7
7
  [:type, aliases: ["t"], default: "yaml", desc: "Type: dsl or yaml"],
8
8
  [:repo, required: true, desc: "Docker repo name. Example: user/repo. Configures .kubes/config.rb"],
9
- [:namespace, aliases: ["n"], desc: "Namespace to use, defaults to the app option"],
9
+ [:namespace, aliases: ["n"], desc: "Namespace to use, defaults to APP-ENV. IE: demo-dev"],
10
10
  ]
11
11
  end
12
12
 
@@ -19,7 +19,12 @@ class Kubes::CLI
19
19
  end
20
20
 
21
21
  def namespace
22
- @options[:namespace] || @options[:app]
22
+ @options[:namespace] || default_namespace
23
+ end
24
+
25
+ def default_namespace
26
+ env = @options[:type] == "yaml" ? '<%= Kubes.env %>' : '#{Kubes.env}'
27
+ "#{app}-#{env}"
23
28
  end
24
29
 
25
30
  def excludes
@@ -8,13 +8,7 @@ module Kubes
8
8
  @options = options
9
9
  end
10
10
 
11
- # Separate command like prune can call compile. Apply also calls Prune.
12
- # Instead of moving Compile out of Prune, will use this class variable.
13
- # In case we have other cases where compile is called in another area.
14
- # We only want compiled to be called once so hooks only fire once.
15
- @@compiled = false
16
11
  def run
17
- return if @@compiled
18
12
  Kubes.config # trigger config load. So can set ENV['VAR'] in config/envs/dev.rb etc
19
13
  run_hooks("kubes.rb", name: "compile") do
20
14
  results = resources.map do |path|
@@ -28,7 +22,6 @@ module Kubes
28
22
  end
29
23
 
30
24
  puts "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
31
- @@compiled = true
32
25
  end
33
26
 
34
27
  def resources
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -0,0 +1,33 @@
1
+ ---
2
+ metadata:
3
+ namespace: default
4
+ labels:
5
+ app: demo
6
+ role: web
7
+ name: demo-web
8
+ spec:
9
+ selector:
10
+ matchLabels:
11
+ app: demo
12
+ role: web
13
+ template:
14
+ metadata:
15
+ labels:
16
+ app: demo
17
+ role: web
18
+ spec:
19
+ containers:
20
+ - name: demo-web
21
+ image: gcr.io/project/demo-web:kubes-2020-06-23T00-07-54
22
+ env:
23
+ - name: MYSQL_ROOT_PASSWORD
24
+ valueFrom:
25
+ configMapKeyRef:
26
+ name: demo-config-map
27
+ key: password
28
+ secretKeyRef:
29
+ name: demo-secret
30
+ key: password
31
+ replicas: 1
32
+ apiVersion: apps/v1
33
+ kind: Deployment
@@ -0,0 +1,40 @@
1
+ ---
2
+ metadata:
3
+ namespace: default
4
+ labels:
5
+ app: demo
6
+ role: web
7
+ name: demo-web
8
+ spec:
9
+ selector:
10
+ matchLabels:
11
+ app: demo
12
+ role: web
13
+ template:
14
+ metadata:
15
+ labels:
16
+ app: demo
17
+ role: web
18
+ spec:
19
+ containers:
20
+ - name: demo-web
21
+ image: gcr.io/project/demo-web:kubes-2020-06-23T00-07-54
22
+ volumeMounts:
23
+ - mountPath: /config-map
24
+ name: config-map-volume
25
+ volumes:
26
+ - configMap:
27
+ name: demo-config-map
28
+ items:
29
+ - key: k1
30
+ path: config-map.conf
31
+ name: config-map-volume
32
+ - secret:
33
+ secretName: demo-secret
34
+ items:
35
+ - key: k1
36
+ path: secrets.conf
37
+ name: secrets-volume
38
+ replicas: 1
39
+ apiVersion: apps/v1
40
+ kind: Pod
@@ -5,6 +5,7 @@ describe Kubes::Compiler::Decorator::Post do
5
5
  YAML.load_file("spec/fixtures/decorators/deployment/#{name}.yaml")
6
6
  end
7
7
  before(:each) do
8
+ allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).and_return("fakehash")
8
9
  allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("Secret", "demo-secret").and_return("fakehash")
9
10
  allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("ConfigMap", "demo-config-map").and_return("fakehash-config")
10
11
  allow(Kubes::Compiler::Decorator::Hashable::Storage).to receive(:fetch).with("ConfigMap", "demo-config-map-2").and_return("fakehash-config2")
@@ -107,5 +108,31 @@ describe Kubes::Compiler::Decorator::Post do
107
108
  expect(name).to eq("demo-config-map-2-fakehash-config2")
108
109
  end
109
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")
135
+ end
136
+ end
110
137
  end
111
138
  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.4.0
4
+ version: 0.4.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-10-11 00:00:00.000000000 Z
11
+ date: 2020-10-13 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
@@ -588,6 +602,8 @@ files:
588
602
  - spec/fixtures/artifacts/demo-web/service.yaml
589
603
  - spec/fixtures/blocks/deployments.rb
590
604
  - spec/fixtures/decorators/deployment/both/envFrom.yaml
605
+ - spec/fixtures/decorators/deployment/both/valueFrom.yaml
606
+ - spec/fixtures/decorators/deployment/both/volumes.yaml
591
607
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
592
608
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
593
609
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml
@@ -661,6 +677,8 @@ test_files:
661
677
  - spec/fixtures/artifacts/demo-web/service.yaml
662
678
  - spec/fixtures/blocks/deployments.rb
663
679
  - spec/fixtures/decorators/deployment/both/envFrom.yaml
680
+ - spec/fixtures/decorators/deployment/both/valueFrom.yaml
681
+ - spec/fixtures/decorators/deployment/both/volumes.yaml
664
682
  - spec/fixtures/decorators/deployment/configMap/envFrom.yaml
665
683
  - spec/fixtures/decorators/deployment/configMap/valueFrom.yaml
666
684
  - spec/fixtures/decorators/deployment/configMap/volumes.yaml