kubes 0.3.3 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +6 -5
- data/docs/_docs/ci/cloudbuild.md +2 -0
- data/docs/_docs/config/args.md +10 -0
- data/docs/_docs/config/args/docker.md +19 -0
- data/docs/_docs/config/args/kubectl.md +19 -0
- data/docs/_docs/config/docker.md +4 -40
- data/docs/_docs/config/env.md +1 -1
- data/docs/_docs/config/hooks.md +10 -0
- data/docs/_docs/config/hooks/docker.md +70 -0
- data/docs/_docs/config/hooks/kubectl.md +83 -0
- data/docs/_docs/config/hooks/kubes.md +67 -0
- data/docs/_docs/config/hooks/ruby.md +76 -0
- data/docs/_docs/config/kubectl.md +3 -54
- data/docs/_docs/config/reference.md +20 -0
- data/docs/_docs/config/skip.md +58 -0
- data/docs/_docs/dsl/resources.md +1 -1
- data/docs/_docs/dsl/resources/backend_config.md +1 -1
- data/docs/_docs/helpers.md +3 -2
- data/docs/_docs/intro.md +6 -3
- data/docs/_docs/learn/dsl/review-project.md +4 -2
- data/docs/_docs/learn/yaml/review-project.md +4 -2
- data/docs/_docs/{auto-context.md → misc/auto-context.md} +0 -0
- data/docs/_docs/{kustomize.md → misc/kustomize.md} +0 -0
- data/docs/_docs/misc/separate-steps.md +21 -0
- data/docs/_docs/patterns.md +4 -1
- data/docs/_docs/patterns/clock-web-worker.md +2 -0
- data/docs/_docs/patterns/migrations.md +123 -0
- data/docs/_docs/patterns/secrets.md +82 -0
- data/docs/_includes/config/hooks/options.md +20 -0
- data/docs/_includes/sidebar.html +35 -11
- data/docs/_reference/kubes-exec.md +14 -6
- data/docs/_reference/kubes-init.md +1 -0
- data/docs/_reference/kubes-logs.md +1 -0
- data/docs/_sass/theme.scss +25 -1
- data/kubes.gemspec +3 -0
- data/lib/kubes.rb +3 -0
- data/lib/kubes/cli.rb +20 -5
- data/lib/kubes/cli/apply.rb +2 -1
- data/lib/kubes/cli/base.rb +11 -0
- data/lib/kubes/cli/compile.rb +8 -0
- data/lib/kubes/cli/delete.rb +1 -1
- data/lib/kubes/cli/exec.rb +37 -6
- data/lib/kubes/cli/get.rb +3 -2
- data/lib/kubes/cli/init.rb +39 -2
- data/lib/kubes/cli/logs.rb +29 -4
- data/lib/kubes/cli/prune.rb +95 -0
- data/lib/kubes/compiler.rb +11 -7
- data/lib/kubes/compiler/decorator/base.rb +7 -1
- data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
- data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
- data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
- data/lib/kubes/compiler/decorator/post.rb +77 -0
- data/lib/kubes/compiler/decorator/pre.rb +12 -0
- data/lib/kubes/compiler/shared/helpers.rb +7 -2
- data/lib/kubes/compiler/strategy.rb +2 -2
- data/lib/kubes/compiler/strategy/base.rb +1 -1
- data/lib/kubes/compiler/strategy/result.rb +4 -6
- data/lib/kubes/config.rb +16 -11
- data/lib/kubes/docker/strategy/build/docker.rb +1 -1
- data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/image_name.rb +1 -1
- data/lib/kubes/docker/strategy/push/docker.rb +1 -1
- data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/utils.rb +1 -1
- data/lib/kubes/hooks/builder.rb +29 -15
- data/lib/kubes/hooks/concern.rb +10 -0
- data/lib/kubes/hooks/dsl.rb +2 -1
- data/lib/kubes/hooks/runner.rb +22 -0
- data/lib/kubes/kubectl.rb +21 -18
- data/lib/kubes/kubectl/batch.rb +8 -5
- data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
- data/lib/kubes/kubectl/fetch/base.rb +13 -10
- data/lib/kubes/kubectl/fetch/deployment.rb +12 -13
- data/lib/kubes/kubectl/fetch/pods.rb +4 -15
- data/lib/kubes/kubectl/kustomize.rb +1 -1
- data/lib/kubes/kubectl/ordering.rb +12 -0
- data/lib/kubes/util/consider.rb +2 -1
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/base/all.rb.tt +6 -1
- data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
- data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
- data/spec/fixtures/decorators/deployment/both/valueFrom.yaml +33 -0
- data/spec/fixtures/decorators/deployment/both/volumes.yaml +40 -0
- data/spec/fixtures/prune/capture.yaml +57 -0
- data/spec/fixtures/prune/fetch_items.yaml +268 -0
- data/spec/kubes/cli/prune_spec.rb +38 -0
- data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +52 -6
- data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
- metadata +57 -19
- data/lib/kubes/compiler/decorator.rb +0 -17
- data/lib/kubes/compiler/decorator/compile.rb +0 -12
- data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
- data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
- data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
- data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
- data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
- data/lib/kubes/compiler/decorator/write.rb +0 -14
- data/lib/kubes/docker/strategy/hooks.rb +0 -9
@@ -0,0 +1,20 @@
|
|
1
|
+
## General Form
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
before(COMMAND_NAME, OPTIONS)
|
5
|
+
````
|
6
|
+
|
7
|
+
The command name corresponds to the `{{ include.command }}` commands: apply, delete, etc.
|
8
|
+
|
9
|
+
## Hook Options
|
10
|
+
|
11
|
+
Name | Description
|
12
|
+
---|---
|
13
|
+
label | A human-friendly label so you can see what hooks is being run.
|
14
|
+
execute | The script or command to run. IE: path/to/some/script.sh
|
15
|
+
exit_on_fail | Whether or not to continue process if the script returns an failed exit code.
|
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 %}
|
17
|
+
|
18
|
+
## Ruby Hooks
|
19
|
+
|
20
|
+
Instead of using a script for the hook `execute` option, you can also use a Ruby object. This provides some more control over the current process. See: [Ruby Hooks]({% link _docs/config/hooks/ruby.md %})
|
data/docs/_includes/sidebar.html
CHANGED
@@ -53,13 +53,37 @@
|
|
53
53
|
</li>
|
54
54
|
<li><a href="{% link _docs/config.md %}">Config</a>
|
55
55
|
<ul>
|
56
|
+
<li><a href="{% link _docs/config/args.md %}">Args</a>
|
57
|
+
<ul>
|
58
|
+
{% assign docs = site.docs | where: "categories","args" %}
|
59
|
+
{% for doc in docs -%}
|
60
|
+
<li><a href="{{ doc.url }}">{{ doc.nav_text }}</a></li>
|
61
|
+
{% endfor %}
|
62
|
+
</ul>
|
63
|
+
</li>
|
64
|
+
<li><a href="{% link _docs/config/hooks.md %}">Hooks</a>
|
65
|
+
<ul>
|
66
|
+
{% assign docs = site.docs | where: "categories","hooks" %}
|
67
|
+
{% for doc in docs -%}
|
68
|
+
<li><a href="{{ doc.url }}">{{ doc.nav_text }}</a></li>
|
69
|
+
{% endfor %}
|
70
|
+
</ul>
|
71
|
+
</li>
|
56
72
|
<li><a href="{% link _docs/config/docker.md %}">Docker</a></li>
|
57
73
|
<li><a href="{% link _docs/config/env.md %}">Env</a></li>
|
58
|
-
<li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a></li>
|
59
74
|
<li><a href="{% link _docs/config/builder.md %}">Builder</a></li>
|
75
|
+
<li><a href="{% link _docs/config/skip.md %}">Skip Option</a></li>
|
76
|
+
<li><a href="{% link _docs/config/reference.md %}">Reference</a></li>
|
60
77
|
</ul>
|
61
78
|
</li>
|
62
79
|
<li><a href="{% link _docs/yaml.md %}">YAML</a></li>
|
80
|
+
<li><a href="{% link _docs/layering.md %}">Layering</a>
|
81
|
+
<ul>
|
82
|
+
<li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
|
83
|
+
<li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
|
84
|
+
<li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
|
85
|
+
</ul>
|
86
|
+
</li>
|
63
87
|
<li><a href="{% link _docs/dsl.md %}">DSL</a>
|
64
88
|
<ul>
|
65
89
|
<li><a href="{% link _docs/dsl/resources.md %}">Resources</a>
|
@@ -73,17 +97,13 @@
|
|
73
97
|
<li><a href="{% link _docs/dsl/multiple-resources.md %}">Multiple Resources</a>
|
74
98
|
</ul>
|
75
99
|
</li>
|
76
|
-
<li><a href="{% link _docs/layering.md %}">Layering</a>
|
77
|
-
<ul>
|
78
|
-
<li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
|
79
|
-
<li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
|
80
|
-
<li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
|
81
|
-
</ul>
|
82
|
-
</li>
|
83
100
|
<li><a href="{% link _docs/helpers.md %}">Helpers</a></li>
|
84
101
|
<li><a href="{% link _docs/patterns.md %}">Patterns</a>
|
85
102
|
<ul>
|
86
|
-
|
103
|
+
{% assign docs = site.docs | where: "categories","patterns" %}
|
104
|
+
{% for doc in docs -%}
|
105
|
+
<li><a href="{{ doc.url }}">{{ doc.nav_text }}</a></li>
|
106
|
+
{% endfor %}
|
87
107
|
</ul>
|
88
108
|
</li>
|
89
109
|
<li><a href="{% link _docs/extra-env.md %}">Extra Env</a>
|
@@ -92,8 +112,12 @@
|
|
92
112
|
<li><a href="{% link _docs/extra-env/dsl.md %}">DSL</a></li>
|
93
113
|
</ul>
|
94
114
|
</li>
|
95
|
-
<li
|
96
|
-
|
115
|
+
<li>Misc
|
116
|
+
<ul>
|
117
|
+
<li><a href="{% link _docs/misc/kustomize.md %}">Kustomize Support</a></li>
|
118
|
+
<li><a href="{% link _docs/misc/separate-steps.md %}">Separate Steps</a></li>
|
119
|
+
<li><a href="{% link _docs/misc/auto-context.md %}">Auto Context</a></li>
|
120
|
+
</ul>
|
97
121
|
<li>CI/CD
|
98
122
|
<ul>
|
99
123
|
<li><a href="{% link _docs/ci/cloudbuild.md %}">CloudBuild</a></li>
|
@@ -21,13 +21,20 @@ The exec command finds the latest pod from the deployment and runs `kubectl exec
|
|
21
21
|
|
22
22
|
## Multiple Deployments
|
23
23
|
|
24
|
-
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` option. Examples:
|
24
|
+
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` or `-n` option. Examples:
|
25
25
|
|
26
|
-
kubes exec --name
|
27
|
-
kubes exec
|
28
|
-
kubes exec
|
29
|
-
kubes exec
|
30
|
-
kubes exec
|
26
|
+
kubes exec --name web
|
27
|
+
kubes exec -n web
|
28
|
+
kubes exec -n clock
|
29
|
+
kubes exec -n worker
|
30
|
+
kubes exec -n web sh
|
31
|
+
kubes exec -n web ls -l
|
32
|
+
|
33
|
+
## Multiple Pod Containers
|
34
|
+
|
35
|
+
If you have have multiple containers in your pod. You can specify the specfic container with the `--container` or `-c` option. Examples:
|
36
|
+
|
37
|
+
kubes exec --name web
|
31
38
|
|
32
39
|
|
33
40
|
## Options
|
@@ -36,6 +43,7 @@ If you have have multiple deployments in your `.kubes/resources` then the comman
|
|
36
43
|
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
37
44
|
# Default: true
|
38
45
|
n, [--name=NAME] # deployment name to use. IE: demo-web
|
46
|
+
c, [--container=CONTAINER] # Container name. If omitted, the first container in the pod will be chosen
|
39
47
|
[--verbose], [--no-verbose]
|
40
48
|
[--noop], [--no-noop]
|
41
49
|
```
|
@@ -20,6 +20,7 @@ a, --app=APP # Docker repo name. Example: web. Generates .ku
|
|
20
20
|
t, [--type=TYPE] # Type: dsl or yaml
|
21
21
|
# Default: yaml
|
22
22
|
--repo=REPO # Docker repo name. Example: user/repo. Configures .kubes/config.rb
|
23
|
+
n, [--namespace=NAMESPACE] # Namespace to use, defaults to the app option
|
23
24
|
[--verbose], [--no-verbose]
|
24
25
|
[--noop], [--no-noop]
|
25
26
|
```
|
@@ -18,6 +18,7 @@ logs from all deployment pods
|
|
18
18
|
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
19
19
|
# Default: true
|
20
20
|
n, [--name=NAME] # deployment name to use. IE: demo-web
|
21
|
+
c, [--container=CONTAINER] # Container name. If omitted, the first container in the pod will be chosen
|
21
22
|
f, [--follow], [--no-follow] # Follow logs
|
22
23
|
# Default: true
|
23
24
|
[--verbose], [--no-verbose]
|
data/docs/_sass/theme.scss
CHANGED
@@ -290,4 +290,28 @@ ul.toc {
|
|
290
290
|
text-align: center;
|
291
291
|
padding: 20px;
|
292
292
|
}
|
293
|
-
}
|
293
|
+
}
|
294
|
+
|
295
|
+
// https://coolestguidesontheplanet.com/videodrome/youtube/
|
296
|
+
// I added another box wrapper to control the width
|
297
|
+
.video-box {
|
298
|
+
max-width: 600px;
|
299
|
+
text-align: left;
|
300
|
+
margin: 0 auto 0 0;
|
301
|
+
padding-bottom: 20px;
|
302
|
+
.video-container {
|
303
|
+
position:relative;
|
304
|
+
padding-bottom:56.25%;
|
305
|
+
padding-top:30px;
|
306
|
+
height:0;
|
307
|
+
overflow:hidden;
|
308
|
+
}
|
309
|
+
|
310
|
+
.video-container iframe, .video-container object, .video-container embed {
|
311
|
+
position:absolute;
|
312
|
+
top:0;
|
313
|
+
left:0;
|
314
|
+
width:100%;
|
315
|
+
height:100%;
|
316
|
+
}
|
317
|
+
}
|
data/kubes.gemspec
CHANGED
@@ -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"
|
data/lib/kubes.rb
CHANGED
data/lib/kubes/cli.rb
CHANGED
@@ -9,12 +9,18 @@ module Kubes
|
|
9
9
|
compile_option = Proc.new {
|
10
10
|
option :compile, type: :boolean, default: true, desc: "whether or not to compile the .kube/resources"
|
11
11
|
}
|
12
|
-
|
13
|
-
option :
|
12
|
+
pod_option = Proc.new {
|
13
|
+
option :pod, aliases: %w[p], desc: "pod to use. IE: web"
|
14
|
+
}
|
15
|
+
deployment_option = Proc.new {
|
16
|
+
option :deployment, aliases: %w[d], desc: "deployment name to use. IE: demo-web"
|
14
17
|
}
|
15
18
|
container_option = Proc.new {
|
16
19
|
option :container, aliases: %w[c], desc: "Container name. If omitted, the first container in the pod will be chosen"
|
17
20
|
}
|
21
|
+
yes_option = Proc.new {
|
22
|
+
option :yes, aliases: %w[y], type: :boolean, desc: "Skip are you sure prompt"
|
23
|
+
}
|
18
24
|
|
19
25
|
desc "docker SUBCOMMAND", "Docker subcommands"
|
20
26
|
long_desc Help.text(:docker)
|
@@ -45,7 +51,7 @@ module Kubes
|
|
45
51
|
desc "delete [ROLE] [RESOURCE]", "Delete Kubernetes resources within the app folder"
|
46
52
|
long_desc Help.text(:delete)
|
47
53
|
image_option.call
|
48
|
-
|
54
|
+
yes_option.call
|
49
55
|
def delete(role=nil, resource=nil)
|
50
56
|
Delete.new(options.merge(role: role, resource: resource)).run
|
51
57
|
end
|
@@ -69,7 +75,8 @@ module Kubes
|
|
69
75
|
desc "exec", "Exec into the latest container from the deployment"
|
70
76
|
long_desc Help.text(:exec)
|
71
77
|
compile_option.call
|
72
|
-
|
78
|
+
pod_option.call
|
79
|
+
deployment_option.call
|
73
80
|
container_option.call
|
74
81
|
def exec(*cmd)
|
75
82
|
Exec.new(options.merge(cmd: cmd)).run
|
@@ -88,13 +95,21 @@ module Kubes
|
|
88
95
|
desc "logs", "logs from all deployment pods"
|
89
96
|
long_desc Help.text(:logs)
|
90
97
|
compile_option.call
|
91
|
-
|
98
|
+
pod_option.call
|
99
|
+
deployment_option.call
|
92
100
|
container_option.call
|
93
101
|
option :follow, aliases: %w[f], type: :boolean, default: true, desc: "Follow logs"
|
94
102
|
def logs(*cmd)
|
95
103
|
Logs.new(options.merge(cmd: cmd)).run
|
96
104
|
end
|
97
105
|
|
106
|
+
desc "prune", "Prune old resources like secret and config maps"
|
107
|
+
long_desc Help.text(:prune)
|
108
|
+
yes_option.call
|
109
|
+
def prune
|
110
|
+
Prune.new(options).run
|
111
|
+
end
|
112
|
+
|
98
113
|
long_desc Help.text(:init)
|
99
114
|
Init.options.each { |args| option(*args) }
|
100
115
|
register(Init, "init", "init", "Init project")
|
data/lib/kubes/cli/apply.rb
CHANGED
@@ -3,7 +3,8 @@ class Kubes::CLI
|
|
3
3
|
def run
|
4
4
|
compile
|
5
5
|
logger.info "Deploying kubes resources"
|
6
|
-
Kubes::Kubectl::
|
6
|
+
Kubes::Kubectl::Dispatcher.new(:apply, @options).run
|
7
|
+
Prune.new(@options.merge(yes: true, quiet: true)).run if Kubes.config.auto_prune # prune old secrets and config maps
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
data/lib/kubes/cli/base.rb
CHANGED
@@ -9,5 +9,16 @@ class Kubes::CLI
|
|
9
9
|
def compile
|
10
10
|
Compile.new(@options).run unless @options[:compile] == false
|
11
11
|
end
|
12
|
+
|
13
|
+
def pod_name
|
14
|
+
return unless @options[:pod]
|
15
|
+
|
16
|
+
pods = Kubes::Kubectl::Fetch::Pods.new(@options)
|
17
|
+
items = pods.fetch(:pod)
|
18
|
+
metas = items.map { |i| i['metadata'] }
|
19
|
+
metas.select! { |i| i['name'].include?(@options[:pod]) }
|
20
|
+
meta = metas.sort { i['creationTimestamp'] }.last
|
21
|
+
meta['name'] if meta
|
22
|
+
end
|
12
23
|
end
|
13
24
|
end
|
data/lib/kubes/cli/compile.rb
CHANGED
@@ -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
|
data/lib/kubes/cli/delete.rb
CHANGED
data/lib/kubes/cli/exec.rb
CHANGED
@@ -1,15 +1,49 @@
|
|
1
1
|
class Kubes::CLI
|
2
2
|
class Exec < Base
|
3
|
+
extend Memoist
|
4
|
+
include Kubes::Logging
|
3
5
|
include Kubes::Util::Sh
|
4
6
|
|
5
7
|
def run
|
6
8
|
compile
|
7
|
-
|
9
|
+
pod = find_pod
|
8
10
|
|
11
|
+
unless pod
|
12
|
+
logger.info <<~EOL
|
13
|
+
Unable to find a pod to exec into. This means there was no deployment found.
|
14
|
+
You can also try using the -p option and specifying enough of the pod name. Example:
|
15
|
+
|
16
|
+
kubes exec -p web
|
17
|
+
|
18
|
+
EOL
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
container = " -c #{@options[:container]}" unless @options[:container].nil?
|
23
|
+
cmd = @options[:cmd].empty? ? "bash" : @options[:cmd].join(' ')
|
24
|
+
sh("kubectl exec #{ns} -ti #{pod}#{container} -- #{cmd}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_pod
|
28
|
+
pod_name || deployment_pod
|
29
|
+
end
|
30
|
+
|
31
|
+
def ns
|
32
|
+
"-n #{metadata['namespace']}" if metadata
|
33
|
+
end
|
34
|
+
|
35
|
+
def metadata
|
36
|
+
deployment = Kubes::Kubectl::Fetch::Deployment.new(@options)
|
37
|
+
deployment.metadata if deployment.found
|
38
|
+
end
|
39
|
+
memoize :metadata
|
40
|
+
|
41
|
+
def deployment_pod
|
42
|
+
return unless metadata
|
9
43
|
labels = metadata['labels'].map { |k,v| "#{k}=#{v}" }.join(',')
|
10
44
|
ns = metadata['namespace']
|
11
45
|
|
12
|
-
resp =
|
46
|
+
resp = sh_capture("kubectl get pod -l #{labels} -n #{ns} -o json")
|
13
47
|
data = JSON.load(resp)
|
14
48
|
pod = latest_pod(data['items'])
|
15
49
|
|
@@ -18,10 +52,7 @@ class Kubes::CLI
|
|
18
52
|
exit 1
|
19
53
|
end
|
20
54
|
|
21
|
-
|
22
|
-
container = " -c #{@options[:container]}" unless @options[:container].nil?
|
23
|
-
cmd = @options[:cmd].empty? ? "bash" : @options[:cmd].join(' ')
|
24
|
-
sh("kubectl exec -n #{ns} -ti #{name}#{container} -- #{cmd}")
|
55
|
+
pod['metadata']['name']
|
25
56
|
end
|
26
57
|
|
27
58
|
# get latest running pod
|
data/lib/kubes/cli/get.rb
CHANGED
@@ -2,9 +2,10 @@ class Kubes::CLI
|
|
2
2
|
class Get < Base
|
3
3
|
def run
|
4
4
|
compile
|
5
|
-
Kubes::Kubectl.run(:get, @options)
|
5
|
+
Kubes::Kubectl.run(:get, @options.merge(exit_on_fail: false))
|
6
|
+
return unless @options[:show_pods]
|
6
7
|
pods = Kubes::Kubectl::Fetch::Pods.new(@options)
|
7
|
-
pods.show
|
8
|
+
pods.show
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
data/lib/kubes/cli/init.rb
CHANGED
@@ -6,6 +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 APP-ENV. IE: demo-dev"],
|
9
10
|
]
|
10
11
|
end
|
11
12
|
|
@@ -17,6 +18,42 @@ class Kubes::CLI
|
|
17
18
|
@options[:app]
|
18
19
|
end
|
19
20
|
|
21
|
+
def namespace
|
22
|
+
@options[:namespace] || default_namespace
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_namespace
|
26
|
+
env = @options[:type] == "yaml" ? '<%= Kubes.env %>' : '#{Kubes.env}'
|
27
|
+
"#{app}-#{env}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def excludes
|
31
|
+
if namespace == "default"
|
32
|
+
case options[:type]
|
33
|
+
when "dsl"
|
34
|
+
%w[
|
35
|
+
namespace.rb.tt
|
36
|
+
]
|
37
|
+
else
|
38
|
+
%w[
|
39
|
+
all.yaml.tt
|
40
|
+
namespace.yaml.tt
|
41
|
+
]
|
42
|
+
end
|
43
|
+
else
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def directory_options
|
49
|
+
if excludes.empty?
|
50
|
+
{}
|
51
|
+
else
|
52
|
+
pattern = Regexp.new(excludes.join('|'))
|
53
|
+
{exclude_pattern: pattern }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
20
57
|
public
|
21
58
|
def create_dockefile
|
22
59
|
return if File.exist?("Dockerfile")
|
@@ -32,13 +69,13 @@ class Kubes::CLI
|
|
32
69
|
def create_dsl_files
|
33
70
|
return unless @options[:type] == "dsl"
|
34
71
|
set_source("dsl")
|
35
|
-
directory ".", "."
|
72
|
+
directory ".", ".", directory_options
|
36
73
|
end
|
37
74
|
|
38
75
|
def create_yaml_files
|
39
76
|
return if @options[:type] == "dsl"
|
40
77
|
set_source("yaml")
|
41
|
-
directory ".", "."
|
78
|
+
directory ".", ".", directory_options
|
42
79
|
end
|
43
80
|
|
44
81
|
def message
|