kubes 0.6.6 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +7 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  4. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  8. data/CHANGELOG.md +17 -0
  9. data/docs/_docs/config/reference.md +1 -1
  10. data/docs/_docs/dsl/multiple-resources.md +19 -21
  11. data/docs/_docs/helpers/google.md +1 -1
  12. data/docs/_docs/helpers/google/gke.md +7 -3
  13. data/docs/_docs/helpers/google/secrets.md +1 -1
  14. data/docs/_docs/intro/concepts.md +8 -9
  15. data/docs/_docs/intro/docker-image.md +2 -2
  16. data/docs/_docs/intro/ordering.md +9 -10
  17. data/docs/_docs/patterns/multiple-envs.md +6 -6
  18. data/docs/_docs/resources/role.md +8 -9
  19. data/docs/_docs/yaml.md +4 -5
  20. data/docs/_docs/yaml/multiple-files.md +22 -0
  21. data/docs/_docs/yaml/multiple-resources.md +89 -0
  22. data/docs/_includes/commands.html +8 -9
  23. data/docs/_includes/config/hooks/options.md +1 -0
  24. data/docs/_includes/layering/layers.md +7 -4
  25. data/docs/_includes/sidebar.html +6 -1
  26. data/docs/_includes/vs/kubes/structure.md +12 -13
  27. data/kubes.gemspec +1 -1
  28. data/lib/kubes/cli/compile.rb +1 -1
  29. data/lib/kubes/command.rb +2 -1
  30. data/lib/kubes/compiler/dsl/core/base.rb +3 -7
  31. data/lib/kubes/compiler/dsl/core/blocks.rb +5 -1
  32. data/lib/kubes/compiler/dsl/syntax/endpoint.rb +34 -0
  33. data/lib/kubes/compiler/dsl/syntax/resource.rb +0 -1
  34. data/lib/kubes/compiler/layering.rb +3 -7
  35. data/lib/kubes/compiler/shared/helpers.rb +4 -2
  36. data/lib/kubes/compiler/shared/runtime_helpers.rb +78 -0
  37. data/lib/kubes/compiler/strategy.rb +1 -15
  38. data/lib/kubes/compiler/strategy/base.rb +0 -56
  39. data/lib/kubes/compiler/strategy/dispatcher.rb +60 -0
  40. data/lib/kubes/compiler/strategy/erb.rb +8 -14
  41. data/lib/kubes/compiler/strategy/result.rb +6 -2
  42. data/lib/kubes/compiler/util/normalize.rb +2 -2
  43. data/lib/kubes/compiler/util/yaml_dump.rb +7 -4
  44. data/lib/kubes/config.rb +1 -1
  45. data/lib/kubes/docker/strategy/image_name.rb +7 -3
  46. data/lib/kubes/version.rb +1 -1
  47. data/lib/templates/new/resource/dsl/endpoint.rb +3 -0
  48. data/lib/templates/new/resource/yaml/endpoint.yaml +9 -0
  49. data/spec/kubes/compiler/strategy/{dsl_spec.rb → dispatcher_spec.rb} +10 -9
  50. metadata +19 -10
  51. data/lib/kubes/compiler/shared/custom_helpers.rb +0 -17
  52. data/lib/kubes/compiler/shared/custom_variables.rb +0 -38
  53. data/lib/kubes/compiler/shared/plugin_helpers.rb +0 -14
  54. data/lib/kubes/compiler/strategy/dsl.rb +0 -4
@@ -37,16 +37,15 @@ Kubes will delete in the reverse order.
37
37
 
38
38
  Resources in the `shared` folder will be applied first. Example:
39
39
 
40
- .kubes
41
- └── resources
42
- ├── clock
43
- │ └── deployment.yaml
44
- ├── web
45
- ├── deployment.yaml
46
- └── service.yaml
47
- └── shared
48
- ├── config_map.yaml
49
- └── secret.yaml
40
+ .kubes/resources
41
+ ├── clock
42
+ │ └── deployment.yaml
43
+ ├── web
44
+ ├── deployment.yaml
45
+ └── service.yaml
46
+ └── shared
47
+ ├── config_map.yaml
48
+ └── secret.yaml
50
49
 
51
50
  Results in:
52
51
 
@@ -1,14 +1,14 @@
1
1
  ---
2
- title: Multiple Enviroments with Layering
3
- nav_text: Multiple Enviroments
2
+ title: Multiple Environments with Layering
3
+ nav_text: Multiple Environments
4
4
  categories: patterns
5
5
  ---
6
6
 
7
- You can use Kubes to easily create multiple enviroments with the same YAML configs. This is thanks to [Kubes Layering]({% link _docs/layering.md %}). We'll walk through an example to help understand how it works.
7
+ You can use Kubes to easily create multiple environments with the same YAML configs. This is thanks to [Kubes Layering]({% link _docs/layering.md %}). We'll walk through an example to help understand how it works.
8
8
 
9
- ## Creating Multiple Enviroments
9
+ ## Creating Multiple Environments
10
10
 
11
- To create multiple enviroments like dev and prod just change KUBES_ENV. Example:
11
+ To create multiple environments like dev and prod just change KUBES_ENV. Example:
12
12
 
13
13
  KUBES_ENV=dev kubes deploy
14
14
  KUBES_ENV=prod kubes deploy
@@ -17,7 +17,7 @@ Different env files will be layered and merged to produce YAML files specific to
17
17
 
18
18
  ## Project Structure
19
19
 
20
- Here's an example structure, so we can understand how layering works to create multiple enviroments.
20
+ Here's an example structure, so we can understand how layering works to create multiple environments.
21
21
 
22
22
  .kubes/resources/
23
23
  ├── base
@@ -8,15 +8,14 @@ Role-based resources are your main project's resources. Kubes groups resources
8
8
 
9
9
  Here's an example structure to help explain how role-based resources work.
10
10
 
11
- .kubes
12
- └── resources
13
- ├── clock
14
- │ └── deployment.yaml
15
- ├── web
16
- ├── deployment.yaml
17
- └── service.yaml
18
- └── worker
19
- └── deployment.yaml
11
+ .kubes/resources
12
+ ├── clock
13
+ │ └── deployment.yaml
14
+ ├── web
15
+ ├── deployment.yaml
16
+ └── service.yaml
17
+ └── worker
18
+ └── deployment.yaml
20
19
 
21
20
  ## Resource Roles
22
21
 
@@ -4,11 +4,10 @@ title: Kubes YAML
4
4
 
5
5
  You can write your Kubernetes resources in YAML format.
6
6
 
7
- .kubes
8
- └── resources
9
- └── web
10
- ├── deployment.yaml
11
- └── service.yaml
7
+ .kubes/resources
8
+ └── web
9
+ ├── deployment.yaml
10
+ └── service.yaml
12
11
 
13
12
  ## YAML and Templating
14
13
 
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: YAML Multiple Resources with Multiple Files
3
+ ---
4
+
5
+ You can also create multiple resources of same kind by appending a dash followed by anything. Example:
6
+
7
+ .kubes/resources
8
+ └── web
9
+ ├── deployment-1.yaml
10
+ ├── deployment-2.yaml
11
+ ├── service-1.yaml
12
+ └── service-2.yaml
13
+
14
+ Only words before the dash are used to infer the resource kind.
15
+
16
+ Filename | Resource Kind
17
+ --- | ---
18
+ deployment-1.yaml | Deployment
19
+ deployment-2.yaml | Deployment
20
+ service-1.yaml | Service
21
+ service-2.yaml | Service
22
+
@@ -0,0 +1,89 @@
1
+ ---
2
+ title: YAML Multiple Resources
3
+ ---
4
+
5
+ Kubes encourages a structure with files that matches the resource kind. Example:
6
+
7
+ .kubes/resources
8
+ └── web
9
+ ├── deployment.yaml
10
+ └── service.yaml
11
+
12
+ This structure is nicely organized and covers 80% of use cases. An astute user may point out that this struture assumes one resource of each kind.
13
+
14
+ Next, we'll cover how to create multiple resource of the same kinds.
15
+
16
+ ## Multiple Resources in Same YAML
17
+
18
+ You can simply define multiple resources in th same YAML file. Conventionally, you should name the resource files with plural names. An example helps explain:
19
+
20
+ .kubes/resources
21
+ └── web
22
+ └── deployments.yaml
23
+
24
+ .kubes/resources/web/deployments.yaml
25
+
26
+ ```yaml
27
+ - apiVersion: apps/v1
28
+ kind: Deployment
29
+ metadata:
30
+ name: web-1
31
+ labels:
32
+ role: web
33
+ spec:
34
+ selector:
35
+ matchLabels:
36
+ role: web
37
+ template:
38
+ metadata:
39
+ labels:
40
+ role: web
41
+ spec:
42
+ containers:
43
+ - name: web
44
+ image: <%= docker_image %>
45
+ - apiVersion: apps/v1
46
+ kind: Deployment
47
+ metadata:
48
+ name: web-2
49
+ labels:
50
+ role: web
51
+ spec:
52
+ selector:
53
+ matchLabels:
54
+ role: web
55
+ template:
56
+ metadata:
57
+ labels:
58
+ role: web
59
+ spec:
60
+ containers:
61
+ - name: web
62
+ image: <%= docker_image %>
63
+ ```
64
+
65
+ Notice that the YAML contains an Array of definitions now.
66
+
67
+ ## Layering
68
+
69
+ Layering works just fine with multiple resource definitions. The layering is processed on each item of the Array.
70
+
71
+ Notes:
72
+
73
+ * The layering definitions for the pre layers must be in singular form.
74
+ * The layering definitions for the post layers must be in a folder with plural form, but define a singular resource override.
75
+ * Resources in the main "middle" layer is the only one that allows for multiple resource definitions.
76
+
77
+ Multiple resources layering structure.
78
+
79
+ .kubes/resources/
80
+ ├── base
81
+ │ ├── all.yaml # SINGULAR
82
+ │ └── deployment.yaml # SINGULAR
83
+ └── web
84
+ ├── deployments # PLURAL
85
+ │ ├── dev.yaml # SINGULAR
86
+ │ └── prod.yaml # SINGULAR
87
+ └── deployments.yaml # PLURAL
88
+
89
+ The main difference is the pluralized filenames.
@@ -30,15 +30,14 @@ kubes delete -y
30
30
  <h3>Structure</h3>
31
31
  <div class="commands">
32
32
  {% highlight sh %}
33
- .kubes
34
- └── resources
35
- ├── clock
36
- │ └── deployment.yaml
37
- ├── worker
38
- └── deployment.yaml
39
- └── web
40
- ├── deployment.yaml
41
- └── service.yaml
33
+ .kubes/resources
34
+ ├── clock
35
+ │ └── deployment.yaml
36
+ ├── worker
37
+ │ └── deployment.yaml
38
+ └── web
39
+ ├── deployment.yaml
40
+ └── service.yaml
42
41
  {% endhighlight %}
43
42
  </div>
44
43
  </div>
@@ -18,3 +18,4 @@ exit_on_fail | Whether or not to continue process if the script returns an faile
18
18
  ## Ruby Hooks
19
19
 
20
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 %})
21
+
@@ -21,11 +21,14 @@ Here's an example structure, so we can understand how layering works.
21
21
 
22
22
  To explain the layering, here's the general processing order that Kubes takes.
23
23
 
24
- 1. The `.kubes/resources/base` folder is treated as a base layer. It gets processed as pre-layers by Kubes.
25
- 2. Then Kubes will process your `.kubes/resources/ROLE` definitions.
26
- 3. Lastly, Kubes processes any post-layers in the `.kubes/resources/ROLE/KIND` folders.
24
+ 1. **Pre Layers**: The `.kubes/resources/base` folder is treated as a base layer. It gets processed as pre-layers by Kubes.
25
+ 2. **Main Layer**: Then Kubes will process your `.kubes/resources/ROLE` definitions.
26
+ 3. **Post Layers**: Lastly, Kubes processes any post-layers in the `.kubes/resources/ROLE/KIND` folders.
27
27
 
28
- Note, both YAML and DSL forms support layering. They can be mixed together.
28
+ Notes
29
+
30
+ * Both YAML and DSL forms support layering. They can be mixed together.
31
+ * In the Main Layer you can define single or multiple resource definitions.
29
32
 
30
33
  ## Full Layering
31
34
 
@@ -86,7 +86,12 @@
86
86
  </ul>
87
87
  </li>
88
88
  <li><a href="{% link _docs/generators.md %}">Generators</a></li>
89
- <li><a href="{% link _docs/yaml.md %}">YAML</a></li>
89
+ <li><a href="{% link _docs/yaml.md %}">YAML</a>
90
+ <ul>
91
+ <li><a href="{% link _docs/yaml/multiple-resources.md %}">Multiple Resources</a></li>
92
+ <li><a href="{% link _docs/yaml/multiple-files.md %}">Multiple Files</a></li>
93
+ </ul>
94
+ </li>
90
95
  <li><a href="{% link _docs/layering.md %}">Layering</a>
91
96
  <ul>
92
97
  <li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
@@ -2,19 +2,18 @@
2
2
 
3
3
  On the other hand, Kubes defines a conventional project structure. Here's a project directory example:
4
4
 
5
- .kubes
6
- └── resources
7
- ├── base
8
- ├── all.yaml
9
- │ └── deployment.yaml
10
- ├── shared
11
- └── namespace.yaml
12
- └── web
13
- ├── deployment
14
- ├── dev.yaml
15
- │ └── prod.yaml
16
- ├── deployment.yaml
17
- └── service.yaml
5
+ .kubes/resources
6
+ ├── base
7
+ ├── all.yaml
8
+ └── deployment.yaml
9
+ ├── shared
10
+ │ └── namespace.yaml
11
+ └── web
12
+ ├── deployment
13
+ ├── dev.yaml
14
+ └── prod.yaml
15
+ ├── deployment.yaml
16
+ └── service.yaml
18
17
 
19
18
  A Kubes project structure also supports introduces a role concept or folder. The folder structure only shows a web role for simplicity. You can always add more roles. For example:
20
19
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  # core helper libs
32
32
  spec.add_dependency "kubes_aws", "~> 0.3.1"
33
- spec.add_dependency "kubes_google", "~> 0.3.3"
33
+ spec.add_dependency "kubes_google", "~> 0.3.5"
34
34
 
35
35
  spec.add_development_dependency "bundler"
36
36
  spec.add_development_dependency "byebug"
@@ -16,7 +16,7 @@ class Kubes::CLI
16
16
 
17
17
  # auto build docker image and push image if kubes docker build not yet called
18
18
  def build_docker_image
19
- return if File.exist?("#{Kubes.root}/.kubes/state/docker_image.txt")
19
+ return if File.exist?(Kubes.config.state.path)
20
20
  Build.new(@options).run
21
21
  end
22
22
  end
@@ -57,7 +57,8 @@ module Kubes
57
57
  end
58
58
 
59
59
  def check_project!(command_name)
60
- return if %w[-h help init new].include?(command_name)
60
+ return if command_name.nil?
61
+ return if %w[-h -v completion completion_script help init new version].include?(command_name)
61
62
  Kubes.check_project!
62
63
  end
63
64
 
@@ -3,22 +3,18 @@ module Kubes::Compiler::Dsl::Core
3
3
  extend Fields
4
4
  include DslEvaluator
5
5
  include Helpers
6
- include Kubes::Compiler::Shared::CustomHelpers
7
- include Kubes::Compiler::Shared::CustomVariables
8
- include Kubes::Compiler::Shared::PluginHelpers
6
+ include Kubes::Compiler::Shared::RuntimeHelpers
9
7
 
10
8
  def initialize(options={})
11
9
  @options = options
12
10
  @name = options[:name]
13
11
  @path = options[:path]
14
- load_plugin_helpers
15
- load_custom_variables
16
- load_custom_helpers
12
+ load_runtime_helpers
17
13
  end
18
14
 
19
15
  def run
20
16
  evaluate_file(@path) # main resource definition
21
- result if respond_to?(:result) # block form doesnt have result
17
+ result
22
18
  end
23
19
  end
24
20
  end
@@ -5,7 +5,11 @@ module Kubes::Compiler::Dsl::Core
5
5
  @results = {} # Hash key is the name of resource, using it so we can keep a map to handle layering
6
6
  @block_form = true # pluralizes the layer names
7
7
  super # handles layering and evaluating the main DSL file
8
- self
8
+ result # Array
9
+ end
10
+
11
+ def result
12
+ @results.values # Array
9
13
  end
10
14
 
11
15
  def syntax_instance(meth, name)
@@ -0,0 +1,34 @@
1
+ module Kubes::Compiler::Dsl::Syntax
2
+ class Endpoint < Resource
3
+ fields :subsets
4
+
5
+ # kubectl explain endpoints.subsets
6
+ fields :addresses, # <[]Object>
7
+ :notReadyAddresses, # <[]Object>
8
+ :ports # <[]Object>
9
+
10
+ def default_kind
11
+ return @kind_from_block if @kind_from_block
12
+ "Endpoints" # always plural
13
+ end
14
+
15
+ def default_apiVersion
16
+ "v1"
17
+ end
18
+
19
+ def default_top
20
+ top = super
21
+ top.merge(
22
+ subsets: subsets
23
+ )
24
+ end
25
+
26
+ def default_subsets
27
+ [{
28
+ addresses: addresses,
29
+ notReadyAddresses: notReadyAddresses,
30
+ ports: ports,
31
+ }]
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,6 @@
1
1
  module Kubes::Compiler::Dsl::Syntax
2
2
  class Resource < Kubes::Compiler::Dsl::Core::Base
3
3
  include Kubes::Compiler::Util::Normalize
4
- include Kubes::Compiler::Shared::Helpers
5
4
 
6
5
  fields :apiVersion, # <string>
7
6
  :kind, # <string>
@@ -5,14 +5,10 @@ class Kubes::Compiler
5
5
 
6
6
  ext = File.extname(@path)
7
7
  kind = File.basename(@path).sub(ext,'') # IE: deployment
8
- all = "all"
9
- if @block_form
10
- kind = kind.pluralize
11
- all = all.pluralize
12
- end
8
+ kind = kind.pluralize if @block_form
13
9
  layers = [
14
- "#{all}",
15
- "#{all}/#{Kubes.env}",
10
+ "all",
11
+ "all/#{Kubes.env}",
16
12
  "#{kind}",
17
13
  "#{kind}/#{Kubes.env}",
18
14
  ]
@@ -1,4 +1,5 @@
1
1
  require "base64"
2
+ require "json"
2
3
 
3
4
  module Kubes::Compiler::Shared
4
5
  module Helpers
@@ -17,11 +18,12 @@ module Kubes::Compiler::Shared
17
18
  end
18
19
 
19
20
  def built_image_helper
20
- path = Kubes.config.state.docker_image_path
21
+ path = Kubes.config.state.path
21
22
  unless File.exist?(path)
22
23
  raise Kubes::MissingDockerImage.new("Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build")
23
24
  end
24
- IO.read(path)
25
+ data = JSON.load(IO.read(path))
26
+ data['image']
25
27
  end
26
28
 
27
29
  def with_extra(value)