kubes 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -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 +74 -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/intro.md +3 -1
  18. data/docs/_docs/patterns/migrations.md +121 -0
  19. data/docs/_includes/config/hooks/options.md +20 -0
  20. data/docs/_includes/sidebar.html +25 -12
  21. data/docs/_sass/theme.scss +25 -1
  22. data/lib/kubes/cli.rb +20 -5
  23. data/lib/kubes/cli/apply.rb +2 -1
  24. data/lib/kubes/cli/base.rb +11 -0
  25. data/lib/kubes/cli/delete.rb +1 -1
  26. data/lib/kubes/cli/exec.rb +37 -6
  27. data/lib/kubes/cli/get.rb +1 -1
  28. data/lib/kubes/cli/logs.rb +27 -3
  29. data/lib/kubes/cli/prune.rb +95 -0
  30. data/lib/kubes/compiler.rb +18 -7
  31. data/lib/kubes/compiler/decorator/base.rb +7 -1
  32. data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
  33. data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
  34. data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
  35. data/lib/kubes/compiler/decorator/post.rb +77 -0
  36. data/lib/kubes/compiler/decorator/pre.rb +12 -0
  37. data/lib/kubes/compiler/strategy.rb +2 -2
  38. data/lib/kubes/compiler/strategy/base.rb +1 -1
  39. data/lib/kubes/compiler/strategy/result.rb +4 -6
  40. data/lib/kubes/config.rb +16 -11
  41. data/lib/kubes/docker/strategy/build/docker.rb +1 -1
  42. data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
  43. data/lib/kubes/docker/strategy/image_name.rb +1 -1
  44. data/lib/kubes/docker/strategy/push/docker.rb +1 -1
  45. data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
  46. data/lib/kubes/docker/strategy/utils.rb +1 -1
  47. data/lib/kubes/hooks/builder.rb +29 -15
  48. data/lib/kubes/hooks/concern.rb +10 -0
  49. data/lib/kubes/hooks/dsl.rb +2 -1
  50. data/lib/kubes/hooks/runner.rb +22 -0
  51. data/lib/kubes/kubectl.rb +21 -18
  52. data/lib/kubes/kubectl/batch.rb +8 -5
  53. data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
  54. data/lib/kubes/kubectl/fetch/base.rb +12 -9
  55. data/lib/kubes/kubectl/fetch/deployment.rb +12 -13
  56. data/lib/kubes/kubectl/fetch/pods.rb +4 -15
  57. data/lib/kubes/kubectl/kustomize.rb +1 -1
  58. data/lib/kubes/kubectl/ordering.rb +12 -0
  59. data/lib/kubes/util/consider.rb +2 -1
  60. data/lib/kubes/util/sh.rb +1 -1
  61. data/lib/kubes/version.rb +1 -1
  62. data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
  63. data/spec/fixtures/prune/capture.yaml +57 -0
  64. data/spec/fixtures/prune/fetch_items.yaml +268 -0
  65. data/spec/kubes/cli/prune_spec.rb +38 -0
  66. data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +25 -6
  67. data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
  68. metadata +35 -19
  69. data/docs/_docs/config/kubectl/hooks.md +0 -39
  70. data/lib/kubes/compiler/decorator.rb +0 -17
  71. data/lib/kubes/compiler/decorator/compile.rb +0 -12
  72. data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
  73. data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
  74. data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
  75. data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
  76. data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
  77. data/lib/kubes/compiler/decorator/write.rb +0 -14
  78. data/lib/kubes/docker/strategy/hooks.rb +0 -9
@@ -6,5 +6,5 @@ title: Kubectl Customizations
6
6
 
7
7
  Kubes calls out the `kubectl` command. You can customize the command.
8
8
 
9
- * [Args]({% link _docs/config/kubectl/args.md %}): Customize the CLI args.
10
- * [Hooks]({% link _docs/config/kubectl/hooks.md %}): Run hooks before and after the kubectl commands.
9
+ * [Args]({% link _docs/config/args/kubectl.md %}): Customize the CLI args.
10
+ * [Hooks]({% link _docs/config/hooks/kubectl.md %}): Run hooks before and after the kubectl commands.
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: Config Reference
3
+ ---
4
+
5
+ Name | Description | Default
6
+ ---|---|---
7
+ auto_prune | Prune and delete old hashed resources like Secret and ConfigMap. | true
8
+ builder | What docker build command to use. Can use `docker` or `gcloud` to build the Docker image. | docker
9
+ kubectl.context | What kubectl context to auto-switch to. | nil
10
+ kubectl.context_keep | Whether or not to keep the context switched | true
11
+ kubectl.exit_on_fail.apply | Whether or not continue if the `kubectl apply` fails. Note, can use `KUBES_EXIT_ON_FAIL=0` env var to set to false. | true
12
+ kubectl.exit_on_fail.delete | Whether or not continue if the `kubectl delete` fails. | false
13
+ kubectl.order.kinds | Change ordering for Kubernetes Kinds. | See [source code](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/config.rb#L52)
14
+ kubectl.order.roles | Change ordering for Kubes Roles. | See [source code](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/config.rb#L44)
15
+ logger | Logger object | Logger.new($stdout)
16
+ logger.level | Logger level. Can also be set with `KUBES_LOG_LEVEL` env var | info
17
+ repo | The Docker repo to use. Required to be set. | nil
18
+ skip | List of resources to skip. Can also be set with the `KUBES_SKIP` env var. `KUBES_SKIP` should be a list of strings separated by spaces. It adds onto the `config.skip` option. | []
19
+ state.docker_image_path | Where to store the state file with the last build Docker image. | .kubes/state/docker_image.txt
20
+ suffix_hash | Whether or not to append suffix hash to ConfigMap and Secret | true
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: Skip Option
3
+ ---
4
+
5
+ You can tell Kubes to skip resources to deploy. This can useful if you want to still resources with Kubes and have it compile `.kubes/output` files, but wish to deploy them outside of Kubes manually.
6
+
7
+ ## Example
8
+
9
+ Here's an example with a Job.
10
+
11
+ .kubes/resources/cleanup/job.yaml:
12
+
13
+ ```yaml
14
+ apiVersion: batch/v1
15
+ kind: Job
16
+ metadata:
17
+ name: cleanup
18
+ spec:
19
+ template:
20
+ spec:
21
+ containers:
22
+ - name: cleanup
23
+ image: <%= built_image %>
24
+ command: ["bin/cleanup.sh"]
25
+ restartPolicy: Never
26
+ ```
27
+
28
+ To skip the cleanup job, use the `config.skip` option:
29
+
30
+ ```ruby
31
+ Kubes.configure do |config|
32
+ config.skip = ["cleanup/job"]
33
+ end
34
+ ```
35
+
36
+ Now when you deploy, the `cleanup/job` resource will not be deployed:
37
+
38
+ kubes deploy # deploys everything except cleanup/job
39
+
40
+ ## Deploy Outside of Kubes
41
+
42
+ Then to deploy outside of kubes.
43
+
44
+ $ kubes compile # not necessary if already ran: kubes deploy
45
+ Compiled .kubes/resources files to .kubes/output
46
+ $ kubectl apply -f .kubes/output/cleanup/job.yaml
47
+ job.batch/cleanup created
48
+ $ kubectl delete -f .kubes/output/cleanup/job.yaml
49
+ job.batch "cleanup" deleted
50
+ $
51
+
52
+ ## Env Var KUBES_SKIP
53
+
54
+ You can also us ethe `KUBES_SKIP` env var. It takes list of strings separated by a space. It adds onto the `config.skip` option. Example:
55
+
56
+ KUBES_SKIP="cleanup/job" kubes delete
57
+
58
+ This can be useful for one-off use cases.
@@ -6,7 +6,7 @@ Here's a list of the resources supported by the Kubes DSL.
6
6
 
7
7
  {% assign docs = site.docs | where: "categories","dsl" %}
8
8
  {% for doc in docs -%}
9
- * [{{ doc.title }}]({{ doc.url }})
9
+ * [{{ doc.nav_text }}]({{ doc.url }})
10
10
  {% endfor %}
11
11
 
12
12
  For resources, that are not supported, you can use the [Generic resource]({% link _docs/dsl/resources/generic.md %}) or use [YAML]({% link _docs/yaml.md %}) instead. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
@@ -4,12 +4,14 @@ title: What is Kubes?
4
4
 
5
5
  {% include reference.md %}
6
6
 
7
+ <div class="video-box"><div class="video-container"><iframe src="https://www.youtube.com/embed/M4zHL0mfKNU" frameborder="0" allowfullscreen=""></iframe></div></div>
8
+
7
9
  ## Features:
8
10
 
9
11
  * Automation: [Builds the Docker image]({% link _docs/config/docker.md %}) and updates the compiled YAML files
10
12
  * Syntactic Sugar: Use an [ERB/YAML]({% link _docs/yaml.md %}) or a [DSL]({% link _docs/dsl.md %}) to write your Kubernetes YAML files. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
11
13
  * Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with [layering]({% link _docs/layering.md %}).
12
- * CLI Customizations: You can customize the [cli args]({% link _docs/config/kubectl/args.md %}). You can also run [hooks]({% link _docs/config/kubectl/hooks.md %}) before and after kubectl commands.
14
+ * CLI Customizations: You can customize the [cli args]({% link _docs/config/args/kubectl.md %}). You can also run [hooks]({% link _docs/config/hooks/kubectl.md %}) before and after kubectl commands.
13
15
  * Automated Suffix Hashes: Automatically appends a suffix hash to ConfigMap and Secret resources. More details in [ConfigMap]({% link _docs/dsl/resources/config_map.md %}) and [Secret]({% link _docs/dsl/resources/secret.md %}) docs.
14
16
  * Kustomize Support: If you’re a kustomization user, you can use it with Kubes. More details in [Kustomize Support Docs]({% link _docs/misc/kustomize.md %}).
15
17
  * Auto Context Switching: Map dev to a specific kubectl context and prod to another kubectl context and Kubes can switch them automatically so you won't have to remember. More details in [Auto Context Docs]({% link _docs/misc/auto-context.md %}).
@@ -0,0 +1,121 @@
1
+ ---
2
+ title: Database Migrations
3
+ ---
4
+
5
+ A common task is to run database migrations. You can use Kubes hooks to achieve this as part of the `kubes deploy` process.
6
+
7
+ 1. Create Migrate Job YAML
8
+ 2. Set up Kubes Hooks
9
+
10
+ ## 1. Create Migrate Job YAML
11
+
12
+ First, let's create the migrate job YAML. Here's a starter example:
13
+
14
+ .kubes/resources/migrate/job.yaml
15
+
16
+ ```yaml
17
+ apiVersion: batch/v1
18
+ kind: Job
19
+ metadata:
20
+ name: migrate
21
+ spec:
22
+ template:
23
+ spec:
24
+ containers:
25
+ - name: migrate
26
+ image: <%= built_image %>
27
+ command: ["bin/job/migrate.sh"]
28
+ restartPolicy: Never
29
+ backoffLimit: 4
30
+ ```
31
+
32
+ The Kubernetes job calls a `job/migrate.sh` script. Something like this:
33
+
34
+ bin/job/migrate.sh
35
+
36
+ #!/bin/bash
37
+ rails db:migrate
38
+
39
+ ## 2. Set up Kubes Hooks
40
+
41
+ Set up the [kubes hooks]({% link _docs/config/hooks/kubectl.md %}) to help the migrate job run properly.
42
+
43
+ .kubes/config/hooks/kubectl.rb
44
+
45
+ ```ruby
46
+ before("apply",
47
+ on: "migrate/job",
48
+ execute: "bin/hooks/migrate/delete.sh",
49
+ exit_on_fail: false,
50
+ )
51
+
52
+ after("apply",
53
+ on: "migrate/job",
54
+ execute: "bin/hooks/migrate/wait.sh",
55
+ )
56
+ ```
57
+
58
+ Here's what the `bin/hook/migrate` scripts could look like:
59
+
60
+ bin/hooks/migrate/delete.sh
61
+
62
+ #!/bin/bash
63
+ kubectl delete job/migrate
64
+
65
+ bin/hooks/migrate/wait.sh
66
+
67
+ #!/bin/bash
68
+ kubectl wait --for=condition=Complete job/migrate --timeout=300s
69
+
70
+ The `migrate/delete.sh` script first cleans up old migrate jobs that may have been previously created.
71
+
72
+ The `migrate/wait.sh` script waits until the migration job finishes before continuing. Note, the default timeout is 30s, which may not be long enough for your migrations to finish, so we set it to 300s. The `kubectl wait` only returns if the migrate job finishes successfully. If the job fails after it exhausts all its retries, default 6, then you'll see an error like this:
73
+
74
+ + kubectl wait --for=condition=Complete job/migrate --timeout=30s
75
+ error: timed out waiting for the condition on jobs/migrate
76
+ ERROR: running bin/hooks/migrate.sh
77
+
78
+ There is also an [migration-example](https://github.com/boltops-tools/kubes-examples/tree/master/yaml/migration-example) repo with a smarter version of the wait script.
79
+
80
+ ## Example Deploy
81
+
82
+ Once that is set up, a `kubes deploy` will automatically run migrations. Here's an example deploy:
83
+
84
+ $ kubes deploy
85
+ => kubectl apply -f .kubes/output/shared/namespace.yaml
86
+ => bin/hooks/migrate/delete.sh
87
+ job.batch "migrate" deleted
88
+ => kubectl apply -f .kubes/output/migrate/job.yaml
89
+ job.batch/migrate created
90
+ Running hook: after apply on: migrate/job
91
+ => bin/hooks/migrate/wait.sh
92
+ Sun Oct 11 03:22:35 UTC 2020
93
+ Migration complete
94
+ => kubectl apply -f .kubes/output/web/service.yaml
95
+ service/web unchanged
96
+ => kubectl apply -f .kubes/output/web/deployment.yaml
97
+ deployment.apps/web configured
98
+ $
99
+
100
+ ## To Couple or Not to Couple?
101
+
102
+ While some companies prefer running the migration step as a part of the app deploy, some prefer to separate it out as a discrete step. Usually, the separate step is still called as part of a pipeline.
103
+
104
+ In practice, the decision usually comes down to:
105
+
106
+ * The size of your database. If your database is large and the migrations take a long time to run. It makes sense to separate it out.
107
+ * The risk tolerance of database migration operations. If it's quite risky to run DB migrations, you may want to separate it as discrete step so a human can review it.
108
+
109
+ For small apps and databases, it's often pragmatic to just run everything in a single step for simplicity.
110
+
111
+ ## Migration as Separate Step
112
+
113
+ If you would like it to run it as a discrete step, remove the hook in `.kubes/config/hooks/kubectl.rb`, and run it as a separate script like so:
114
+
115
+ bin/run/migrate.sh
116
+
117
+ #!/bin/bash
118
+ kubes compile
119
+ bin/hooks/migrate/delete.sh
120
+ bin/job/migrate.sh
121
+ bin/hooks/migrate/wait.sh
@@ -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 during `kubes apply`
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 %})
@@ -53,18 +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/docker.md %}">Docker</a></li>
57
- <li><a href="{% link _docs/config/env.md %}">Env</a></li>
58
- <li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a>
56
+ <li><a href="{% link _docs/config/args.md %}">Args</a>
59
57
  <ul>
60
- <li><a href="{% link _docs/config/kubectl/args.md %}">Args</a></li>
61
- <li><a href="{% link _docs/config/kubectl/hooks.md %}">Hooks</a></li>
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
62
  </ul>
63
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>
72
+ <li><a href="{% link _docs/config/docker.md %}">Docker</a></li>
73
+ <li><a href="{% link _docs/config/env.md %}">Env</a></li>
64
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>
65
77
  </ul>
66
78
  </li>
67
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>
68
87
  <li><a href="{% link _docs/dsl.md %}">DSL</a>
69
88
  <ul>
70
89
  <li><a href="{% link _docs/dsl/resources.md %}">Resources</a>
@@ -78,16 +97,10 @@
78
97
  <li><a href="{% link _docs/dsl/multiple-resources.md %}">Multiple Resources</a>
79
98
  </ul>
80
99
  </li>
81
- <li><a href="{% link _docs/layering.md %}">Layering</a>
82
- <ul>
83
- <li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
84
- <li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
85
- <li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
86
- </ul>
87
- </li>
88
100
  <li><a href="{% link _docs/helpers.md %}">Helpers</a></li>
89
101
  <li><a href="{% link _docs/patterns.md %}">Patterns</a>
90
102
  <ul>
103
+ <li><a href="{% link _docs/patterns/migrations.md %}">Database Migrations</a></li>
91
104
  <li><a href="{% link _docs/patterns/clock-web-worker.md %}">Clock Web Worker</a></li>
92
105
  </ul>
93
106
  </li>
@@ -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
+ }
@@ -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
- name_option = Proc.new {
13
- option :name, aliases: %w[n], desc: "deployment name to use. IE: demo-web"
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
- option :yes, aliases: %w[y], type: :boolean, desc: "Skip are you sure prompt"
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
- name_option.call
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
- name_option.call
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")
@@ -3,7 +3,8 @@ class Kubes::CLI
3
3
  def run
4
4
  compile
5
5
  logger.info "Deploying kubes resources"
6
- Kubes::Kubectl::Decider.new(:apply, @options).run
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
@@ -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
@@ -10,7 +10,7 @@ class Kubes::CLI
10
10
  end
11
11
 
12
12
  def perform(preview: false)
13
- Kubes::Kubectl::Decider.new(:delete, @options.merge(preview: preview)).run
13
+ Kubes::Kubectl::Dispatcher.new(:delete, @options.merge(preview: preview)).run
14
14
  end
15
15
  end
16
16
  end