kubes 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/docs/_config.yml +1 -1
  4. data/docs/_docs/ci/cloudbuild.md +2 -0
  5. data/docs/_docs/config/env.md +1 -1
  6. data/docs/_docs/config/kubectl.md +3 -54
  7. data/docs/_docs/config/kubectl/args.md +17 -0
  8. data/docs/_docs/config/kubectl/hooks.md +39 -0
  9. data/docs/_docs/dsl/resources/backend_config.md +1 -1
  10. data/docs/_docs/intro.md +4 -3
  11. data/docs/_docs/learn/yaml/new-project.md +0 -1
  12. data/docs/_docs/{auto-context.md → misc/auto-context.md} +0 -0
  13. data/docs/_docs/{kustomize.md → misc/kustomize.md} +0 -0
  14. data/docs/_docs/misc/separate-steps.md +21 -0
  15. data/docs/_includes/commands.html +2 -0
  16. data/docs/_includes/sidebar.html +12 -3
  17. data/docs/_reference/kubes-exec.md +14 -6
  18. data/docs/_reference/kubes-init.md +1 -0
  19. data/docs/_reference/kubes-logs.md +1 -0
  20. data/docs/_sass/theme.scss +2 -1
  21. data/docs/img/logos/kubes-white.png +0 -0
  22. data/docs/index.html +2 -2
  23. data/lib/kubes/cli.rb +5 -0
  24. data/lib/kubes/cli/exec.rb +2 -1
  25. data/lib/kubes/cli/get.rb +2 -1
  26. data/lib/kubes/cli/help/exec.md +13 -6
  27. data/lib/kubes/cli/init.rb +34 -2
  28. data/lib/kubes/cli/logs.rb +27 -2
  29. data/lib/kubes/compiler/dsl/syntax/deployment.rb +13 -0
  30. data/lib/kubes/kubectl/fetch/base.rb +1 -1
  31. data/lib/kubes/kubectl/fetch/deployment.rb +13 -2
  32. data/lib/kubes/version.rb +1 -1
  33. data/lib/templates/dsl/.kubes/resources/base/all.rb.tt +6 -1
  34. data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +1 -1
  35. data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
  36. data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
  37. data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +1 -1
  38. data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
  39. metadata +8 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6a93c63c1e8d4aeea46969a491b3065c97e9a1a290bfd871286e794c35cb0d6
4
- data.tar.gz: d8dbb91a1214bf8c42a5c9dd1e591dfcf6c41ffee6feb36af0af2f7b3a519ebd
3
+ metadata.gz: d239ce306b5a9eea427cab3ec5ca5f753f0eae3d1822fce65017c23172779562
4
+ data.tar.gz: 3d97c8d85e6f5bfd02babaf14140f186ebd22c3981fa8eed76ddcdbe7f24958d
5
5
  SHA512:
6
- metadata.gz: dfc13591d144fb99837297c4c766354ceed410df631e505e54517e9759b9b44b03ce9adb7738db167b55c877d7f47bbd644f1bb832df38c4213651243fcbe668
7
- data.tar.gz: 9ed84b118c29ec8531407f4b069840d1c576eb6f120f58ead3a8560242af44b62ca3b6339f4949a5433c64fc966003d65f2871134b0ed17984cc2f461b9537bd
6
+ metadata.gz: 74b0ad9bc27e15f1b8742d26f6b2c09e11e990a69623a7e0b54d12565dc08e3dec5d0c640bfd4f5457aa09f0069c0010a78d39dedc18bd9a2223ebdb34be9c31
7
+ data.tar.gz: 7f3508f0d3650677a48f1f0069f71b1801ddd0a760f052f725a81f564fd144b6eecbd8c08e79fd2e9ec571a0ada2308d4f84bdfbc6971f66a80a20eec8ffbaae
@@ -3,6 +3,22 @@
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.3.5]
7
+ - #25 small fixes: show pod and fetch items nil
8
+
9
+ ## [0.3.4]
10
+ - #24 fix namespace newline and logs for single container
11
+ - #23 init namespace option
12
+
13
+ ## [0.3.3]
14
+ - #22 logs -c option. fix kubes logs for pods with multiple containers
15
+
16
+ ## [0.3.2]
17
+ - #21 add namespace to logs command
18
+
19
+ ## [0.3.1]
20
+ - #20 improve sidecar support. kubes exec -c option also
21
+
6
22
  ## [0.3.0]
7
23
  - #19 new commands: exec, logs
8
24
  - delete preview
@@ -9,7 +9,7 @@ meta_author: Tung Nguyen
9
9
 
10
10
  # Google webmaster tools
11
11
  google_verify:
12
- google_analytics: "TODO: google_analytics"
12
+ google_analytics: "UA-98684555-14"
13
13
 
14
14
  # https://ssl.bing.com/webmaster/configure/verify/ownership Option 2 content= goes here
15
15
  bing_verify:
@@ -38,6 +38,8 @@ options:
38
38
  substitution_option: 'ALLOW_LOOSE'
39
39
  ```
40
40
 
41
+ Make sure to replace the substitutions with your own values. IE: _GCP_REGION, _GKE_CLUSTER, _KUBES_ENV, etc.
42
+
41
43
  ## Run CloudBuild
42
44
 
43
45
  Run cloudbuild with:
@@ -55,4 +55,4 @@ Kubes.configure do |config|
55
55
  end
56
56
  ```
57
57
 
58
- For more details refer to the [Auto Context Docs]({% link _docs/auto-context.md %}).
58
+ For more details refer to the [Auto Context Docs]({% link _docs/misc/auto-context.md %}).
@@ -1,61 +1,10 @@
1
1
  ---
2
- title: Kubectl Config
2
+ title: Kubectl Customizations
3
3
  ---
4
4
 
5
5
  ## General
6
6
 
7
7
  Kubes calls out the `kubectl` command. You can customize the command.
8
8
 
9
- ## Args
10
-
11
- Here are some examples of customizing the kubectl args.
12
-
13
- .kubes/config/kubectl/args.rb
14
-
15
- ```ruby
16
- command("apply",
17
- args: ["--validate=true"],
18
- )
19
-
20
- command("delete",
21
- args: ["--grace-period=-1"],
22
- )
23
- ```
24
-
25
- ## Hooks
26
-
27
- Here are some examples of running custom hooks before and after the kubectl commands.
28
-
29
- .kubes/config/kubectl/hooks.rb
30
-
31
- ```ruby
32
- before("apply",
33
- execute: "kubectl apply -f .kubes/shared/namespace.yaml",
34
- )
35
-
36
- after("delete",
37
- execute: "echo 'delete hook',
38
- )
39
- ```
40
-
41
- 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.
42
-
43
- .kubes/shared/namespace.yaml
44
-
45
- ```yaml
46
- apiVersion: v1
47
- kind: Namespace
48
- metadata:
49
- name: demo
50
- ```
51
-
52
- ### exit on fail
53
-
54
- 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.
55
-
56
- ```ruby
57
- before("apply"
58
- execute: "/command/will/fail/but/will/continue",
59
- exit_on_fail: false,
60
- )
61
- ```
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.
@@ -0,0 +1,17 @@
1
+ ---
2
+ title: Kubectl Args
3
+ ---
4
+
5
+ Here are some examples of customizing the kubectl args.
6
+
7
+ .kubes/config/kubectl/args.rb
8
+
9
+ ```ruby
10
+ command("apply",
11
+ args: ["--validate=true"],
12
+ )
13
+
14
+ command("delete",
15
+ args: ["--grace-period=-1"],
16
+ )
17
+ ```
@@ -0,0 +1,39 @@
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
+ ```
@@ -3,7 +3,7 @@ title: BackendConfig
3
3
  categories: dsl
4
4
  ---
5
5
 
6
- A BackendConfig is [custom resource definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) that allow you to further customize the load balancer.
6
+ A [BackendConfig](https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#create_backendconfig) is [custom resource definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) that allow you to further customize the load balancer.
7
7
 
8
8
  Here's an example of a BackendConfig.
9
9
 
@@ -9,7 +9,8 @@ title: What is Kubes?
9
9
  * Automation: [Builds the Docker image]({% link _docs/config/docker.md %}) and updates the compiled YAML files
10
10
  * 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
11
  * 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.md %}). You can also run hooks before and after kubectl commands.
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.
13
13
  * 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
- * Kustomize Support: If you’re a kustomization user, you can use it with Kubes. More details in [Kustomize Support Docs]({% link _docs/kustomize.md %}).
15
- * 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/auto-context.md %}).
14
+ * 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
+ * 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 %}).
16
+ * Ordering: Kubes run kubectl apply to create resources in the [correct order]({% link _docs/intro/ordering.md %}). For deleting, it kubes will run `kubectl delete` in the correct reverse order. The order is also [customizable]({% link _docs/intro/ordering/custom.md %}).
@@ -11,7 +11,6 @@ If you already a project with an existing Dockerfile, you can use that. If you d
11
11
 
12
12
  Let's generate a starter project:
13
13
 
14
- $ REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')
15
14
  $ kubes init --app demo --repo $REPO
16
15
  create Dockerfile
17
16
  create .kubes/config.rb
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: Separate Steps
3
+ ---
4
+
5
+ Sometimes you may want to run the 3 separate kubes steps directly. This may be useful if you are setting up CI/CD and need more control over the build process. Here are the 3 main steps:
6
+
7
+ To build and push the docker image:
8
+
9
+ kubes docker build
10
+ kubes docker push
11
+
12
+ Note, you must run a `kubes docker build` at least once. As the build step will store the image name in a `.kubes/state/docker_image.txt ` file for later use.
13
+
14
+ To compile the Kubernetes YAML files.
15
+
16
+ kubes compile
17
+
18
+ To apply the Kubernetes YAML files in the correct order and create resources on the cluster:
19
+
20
+ kubes apply
21
+
@@ -20,6 +20,8 @@ kubes compile
20
20
  kubes deploy
21
21
  kubes apply
22
22
  kubes get
23
+ kubes exec
24
+ kubes logs
23
25
  kubes delete -y
24
26
  {% endhighlight %}
25
27
  </div>
@@ -55,7 +55,12 @@
55
55
  <ul>
56
56
  <li><a href="{% link _docs/config/docker.md %}">Docker</a></li>
57
57
  <li><a href="{% link _docs/config/env.md %}">Env</a></li>
58
- <li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a></li>
58
+ <li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a>
59
+ <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>
62
+ </ul>
63
+ </li>
59
64
  <li><a href="{% link _docs/config/builder.md %}">Builder</a></li>
60
65
  </ul>
61
66
  </li>
@@ -92,8 +97,12 @@
92
97
  <li><a href="{% link _docs/extra-env/dsl.md %}">DSL</a></li>
93
98
  </ul>
94
99
  </li>
95
- <li><a href="{% link _docs/kustomize.md %}">Kustomize Support</a></li>
96
- <li><a href="{% link _docs/auto-context.md %}">Auto Context</a></li>
100
+ <li>Misc
101
+ <ul>
102
+ <li><a href="{% link _docs/misc/kustomize.md %}">Kustomize Support</a></li>
103
+ <li><a href="{% link _docs/misc/separate-steps.md %}">Separate Steps</a></li>
104
+ <li><a href="{% link _docs/misc/auto-context.md %}">Auto Context</a></li>
105
+ </ul>
97
106
  <li>CI/CD
98
107
  <ul>
99
108
  <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 demo-web
27
- kubes exec --name demo-clock
28
- kubes exec --name demo-worker
29
- kubes exec --name demo-web sh
30
- kubes exec --name demo-web ls -l
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 comma
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]
@@ -13,12 +13,13 @@
13
13
  margin: auto;
14
14
  text-align: center;
15
15
  display: block;
16
+ width: 80%;
16
17
  padding-bottom: 30px;
17
18
 
18
19
  @media (min-width: 575px) {
19
20
  position: absolute;
20
21
  top: 50%;
21
- max-width: none;
22
+ width: 100%;
22
23
  margin: 0;
23
24
  transform: translateY(-50%);
24
25
  }
@@ -9,13 +9,13 @@ sidebar: false
9
9
  <div class="col-sm-8 col-sm-offset-2">
10
10
  <div class="header-content">
11
11
  <div class="header-content-inner">
12
- <h1>Kubes</h1>
12
+ <h1>Kubes: Kubernetes Deployment Tool</h1>
13
13
  <h2>Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.</h2>
14
14
  </div>
15
15
  </div>
16
16
  </div>
17
17
  <div class="col-sm-4">
18
- <img src="/img/logos/kubes-sign.png" class="homepage-logo" />
18
+ <img src="/img/logos/kubes-white.png" class="homepage-logo" />
19
19
  </div>
20
20
  </div>
21
21
  </div>
@@ -12,6 +12,9 @@ module Kubes
12
12
  name_option = Proc.new {
13
13
  option :name, aliases: %w[n], desc: "deployment name to use. IE: demo-web"
14
14
  }
15
+ container_option = Proc.new {
16
+ option :container, aliases: %w[c], desc: "Container name. If omitted, the first container in the pod will be chosen"
17
+ }
15
18
 
16
19
  desc "docker SUBCOMMAND", "Docker subcommands"
17
20
  long_desc Help.text(:docker)
@@ -67,6 +70,7 @@ module Kubes
67
70
  long_desc Help.text(:exec)
68
71
  compile_option.call
69
72
  name_option.call
73
+ container_option.call
70
74
  def exec(*cmd)
71
75
  Exec.new(options.merge(cmd: cmd)).run
72
76
  end
@@ -85,6 +89,7 @@ module Kubes
85
89
  long_desc Help.text(:logs)
86
90
  compile_option.call
87
91
  name_option.call
92
+ container_option.call
88
93
  option :follow, aliases: %w[f], type: :boolean, default: true, desc: "Follow logs"
89
94
  def logs(*cmd)
90
95
  Logs.new(options.merge(cmd: cmd)).run
@@ -19,8 +19,9 @@ class Kubes::CLI
19
19
  end
20
20
 
21
21
  name = pod['metadata']['name']
22
+ container = " -c #{@options[:container]}" unless @options[:container].nil?
22
23
  cmd = @options[:cmd].empty? ? "bash" : @options[:cmd].join(' ')
23
- sh("kubectl exec -n #{ns} -ti #{name} -- #{cmd}")
24
+ sh("kubectl exec -n #{ns} -ti #{name}#{container} -- #{cmd}")
24
25
  end
25
26
 
26
27
  # get latest running pod
@@ -3,8 +3,9 @@ class Kubes::CLI
3
3
  def run
4
4
  compile
5
5
  Kubes::Kubectl.run(:get, @options)
6
+ return unless @options[:show_pods]
6
7
  pods = Kubes::Kubectl::Fetch::Pods.new(@options)
7
- pods.show if @options[:show_pods]
8
+ pods.show
8
9
  end
9
10
  end
10
11
  end
@@ -8,10 +8,17 @@ The exec command finds the latest pod from the deployment and runs `kubectl exec
8
8
 
9
9
  ## Multiple Deployments
10
10
 
11
- 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:
11
+ 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:
12
12
 
13
- kubes exec --name demo-web
14
- kubes exec --name demo-clock
15
- kubes exec --name demo-worker
16
- kubes exec --name demo-web sh
17
- kubes exec --name demo-web ls -l
13
+ kubes exec --name web
14
+ kubes exec -n web
15
+ kubes exec -n clock
16
+ kubes exec -n worker
17
+ kubes exec -n web sh
18
+ kubes exec -n web ls -l
19
+
20
+ ## Multiple Pod Containers
21
+
22
+ If you have have multiple containers in your pod. You can specify the specfic container with the `--container` or `-c` option. Examples:
23
+
24
+ kubes exec --name web
@@ -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 the app option"],
9
10
  ]
10
11
  end
11
12
 
@@ -17,6 +18,37 @@ class Kubes::CLI
17
18
  @options[:app]
18
19
  end
19
20
 
21
+ def namespace
22
+ @options[:namespace] || @options[:app]
23
+ end
24
+
25
+ def excludes
26
+ if namespace == "default"
27
+ case options[:type]
28
+ when "dsl"
29
+ %w[
30
+ namespace.rb.tt
31
+ ]
32
+ else
33
+ %w[
34
+ all.yaml.tt
35
+ namespace.yaml.tt
36
+ ]
37
+ end
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ def directory_options
44
+ if excludes.empty?
45
+ {}
46
+ else
47
+ pattern = Regexp.new(excludes.join('|'))
48
+ {exclude_pattern: pattern }
49
+ end
50
+ end
51
+
20
52
  public
21
53
  def create_dockefile
22
54
  return if File.exist?("Dockerfile")
@@ -32,13 +64,13 @@ class Kubes::CLI
32
64
  def create_dsl_files
33
65
  return unless @options[:type] == "dsl"
34
66
  set_source("dsl")
35
- directory ".", "."
67
+ directory ".", ".", directory_options
36
68
  end
37
69
 
38
70
  def create_yaml_files
39
71
  return if @options[:type] == "dsl"
40
72
  set_source("yaml")
41
- directory ".", "."
73
+ directory ".", ".", directory_options
42
74
  end
43
75
 
44
76
  def message
@@ -4,10 +4,35 @@ class Kubes::CLI
4
4
 
5
5
  def run
6
6
  compile
7
- metadata = Kubes::Kubectl::Fetch::Deployment.new(@options).metadata
7
+ deployment = Kubes::Kubectl::Fetch::Deployment.new(@options)
8
+ metadata = deployment.metadata
8
9
  name = metadata['name']
10
+ ns = metadata['namespace']
11
+
9
12
  follow = " -f" if @options[:follow]
10
- sh("kubectl logs deployment/#{name}#{follow}")
13
+ container = container(deployment)
14
+ c = " -c #{container}" if container
15
+ sh("kubectl logs deployment/#{name}#{follow} -n #{ns}#{c}")
16
+ end
17
+
18
+ private
19
+ def container(deployment)
20
+ container = @options[:container]
21
+ return container if container
22
+
23
+ spec = deployment.spec
24
+ containers = spec['template']['spec']['containers']
25
+ names = containers.map { |c| c['name'] }
26
+ if containers.size > 1
27
+ logger.info <<~EOL
28
+ INFO: More than one container found.
29
+ Container names: #{names.join(', ')}
30
+ Using #{names.first}
31
+ Note: You can specify the container to use with --container or -c
32
+ EOL
33
+
34
+ names.first
35
+ end
11
36
  end
12
37
  end
13
38
  end
@@ -3,6 +3,8 @@ module Kubes::Compiler::Dsl::Syntax
3
3
  fields :container, # <Object>
4
4
  "matchLabels:hash", # <map[string]string>
5
5
  :sidecar, # <Object>
6
+ :sidecar_name, # <string>
7
+ :sidecar_image, # <string>
6
8
  :templateMetadata, # <Object>
7
9
  :templateSpec # <Object>
8
10
 
@@ -185,6 +187,17 @@ module Kubes::Compiler::Dsl::Syntax
185
187
  [container, sidecar].compact
186
188
  end
187
189
 
190
+ def default_sidecar
191
+ {
192
+ name: sidecar_name,
193
+ image: sidecar_image,
194
+ }
195
+ end
196
+
197
+ def default_sidecar_name
198
+ "sidecar" if sidecar_image # othewise will create invalid sidecar field w/o image
199
+ end
200
+
188
201
  def default_container
189
202
  {
190
203
  args: args,
@@ -18,7 +18,7 @@ module Kubes::Kubectl::Fetch
18
18
  kubectl = Kubes::Kubectl.new(:get, @options.merge(o)) # kubes get -f .kubes/output
19
19
  resp = kubectl.run
20
20
  data = JSON.load(resp)
21
- data['items']
21
+ data['items'] || [] # Note: When fetching only 1 resource, items is not part of structure
22
22
  end
23
23
  end
24
24
  end
@@ -1,6 +1,16 @@
1
1
  module Kubes::Kubectl::Fetch
2
2
  class Deployment < Base
3
+ extend Memoist
4
+
3
5
  def metadata
6
+ deployment['metadata']
7
+ end
8
+
9
+ def spec
10
+ deployment['spec']
11
+ end
12
+
13
+ def deployment
4
14
  items = fetch_items
5
15
  # Not checking if deployment exists because kubes will error on `kubes get` from missing deployments already
6
16
  deployments = items.select { |i| i['kind'] == "Deployment" }
@@ -11,7 +21,7 @@ module Kubes::Kubectl::Fetch
11
21
  INFO: More than one deployment found.
12
22
  Deployment names: #{names.join(', ')}
13
23
  Using #{names.first}
14
- Note: You can specify the deployment to use with --name
24
+ Note: You can specify the deployment to use with --name or -n
15
25
  EOL
16
26
  end
17
27
 
@@ -20,8 +30,9 @@ module Kubes::Kubectl::Fetch
20
30
  logger.error "ERROR: No deployment found".color(:red)
21
31
  exit 1
22
32
  end
23
- deployment['metadata']
33
+ deployment
24
34
  end
35
+ memoize :deployment
25
36
 
26
37
  def find_deployment(deployments)
27
38
  if @options[:name]
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -1,2 +1,7 @@
1
- namespace "<%= app %>"
1
+ <%
2
+ unless namespace == "default"
3
+ namespace_line = %Q|namespace "#{namespace}"\n|
4
+ end
5
+ -%>
6
+ <%= namespace_line if namespace_line -%>
2
7
  labels(app: "<%= app %>")
@@ -1,2 +1,2 @@
1
- name "<%= app %>"
1
+ name "<%= namespace %>"
2
2
  labels(app: "<%= app %>")
@@ -1,7 +1,7 @@
1
1
  name "web"
2
2
  labels(role: "web")
3
3
 
4
- replicas 1
4
+ replicas 1 # overridden on a env basis
5
5
  image built_image # IE: user/<%= app %>:kubes-2020-06-13T19-55-16-43afc6e
6
6
 
7
7
  # revisionHistoryLimit 1 # uncomment to reduce old ReplicaSets, default is 10 https://bit.ly/3hqrzyP
@@ -1,2 +1,2 @@
1
1
  metadata:
2
- namespace: <%= app %>
2
+ namespace: <%= namespace %>
@@ -1,6 +1,6 @@
1
1
  apiVersion: v1
2
2
  kind: Namespace
3
3
  metadata:
4
- name: <%= app %>
4
+ name: <%= namespace %>
5
5
  labels:
6
6
  app: <%= app %>
@@ -5,7 +5,7 @@ metadata:
5
5
  labels:
6
6
  role: web
7
7
  spec:
8
- replicas: 1
8
+ replicas: 1 # overridden on a env basis
9
9
  selector:
10
10
  matchLabels:
11
11
  role: web
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.0
4
+ version: 0.3.5
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-01 00:00:00.000000000 Z
11
+ date: 2020-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -232,13 +232,14 @@ files:
232
232
  - docs/README.md
233
233
  - docs/Rakefile
234
234
  - docs/_config.yml
235
- - docs/_docs/auto-context.md
236
235
  - docs/_docs/ci/cloudbuild.md
237
236
  - docs/_docs/config.md
238
237
  - docs/_docs/config/builder.md
239
238
  - docs/_docs/config/docker.md
240
239
  - docs/_docs/config/env.md
241
240
  - docs/_docs/config/kubectl.md
241
+ - docs/_docs/config/kubectl/args.md
242
+ - docs/_docs/config/kubectl/hooks.md
242
243
  - docs/_docs/contributing.md
243
244
  - docs/_docs/dsl.md
244
245
  - docs/_docs/dsl/multiple-resources.md
@@ -269,7 +270,6 @@ files:
269
270
  - docs/_docs/intro/ordering.md
270
271
  - docs/_docs/intro/ordering/custom.md
271
272
  - docs/_docs/intro/structure.md
272
- - docs/_docs/kustomize.md
273
273
  - docs/_docs/layering.md
274
274
  - docs/_docs/layering/dsl.md
275
275
  - docs/_docs/layering/merge.md
@@ -294,6 +294,9 @@ files:
294
294
  - docs/_docs/learn/yaml/next-steps.md
295
295
  - docs/_docs/learn/yaml/review-project.md
296
296
  - docs/_docs/learn/yaml/update.md
297
+ - docs/_docs/misc/auto-context.md
298
+ - docs/_docs/misc/kustomize.md
299
+ - docs/_docs/misc/separate-steps.md
297
300
  - docs/_docs/next-steps.md
298
301
  - docs/_docs/patterns.md
299
302
  - docs/_docs/patterns/clock-web-worker.md
@@ -366,6 +369,7 @@ files:
366
369
  - docs/img/logos/filler-logo.png
367
370
  - docs/img/logos/kubes-black.png
368
371
  - docs/img/logos/kubes-sign.png
372
+ - docs/img/logos/kubes-white.png
369
373
  - docs/index.html
370
374
  - docs/js/app.js
371
375
  - docs/opal/app.rb