kubes 0.6.5 → 0.7.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 +4 -4
- data/.github/ISSUE_TEMPLATE.md +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
- data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
- data/.github/ISSUE_TEMPLATE/question.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
- data/CHANGELOG.md +16 -0
- data/docs/_docs/dsl/multiple-resources.md +19 -21
- data/docs/_docs/helpers/google.md +1 -1
- data/docs/_docs/helpers/google/gke.md +7 -3
- data/docs/_docs/helpers/google/secrets.md +1 -1
- data/docs/_docs/intro/concepts.md +8 -9
- data/docs/_docs/intro/ordering.md +9 -10
- data/docs/_docs/resources/role.md +8 -9
- data/docs/_docs/yaml.md +4 -5
- data/docs/_docs/yaml/multiple-files.md +22 -0
- data/docs/_docs/yaml/multiple-resources.md +89 -0
- data/docs/_includes/commands.html +8 -9
- data/docs/_includes/config/hooks/options.md +1 -0
- data/docs/_includes/layering/layers.md +7 -4
- data/docs/_includes/sidebar.html +6 -1
- data/docs/_includes/vs/kubes/structure.md +12 -13
- data/kubes.gemspec +2 -2
- data/lib/kubes/command.rb +1 -1
- data/lib/kubes/compiler/dsl/core/base.rb +3 -7
- data/lib/kubes/compiler/dsl/core/blocks.rb +5 -1
- data/lib/kubes/compiler/dsl/syntax/endpoint.rb +34 -0
- data/lib/kubes/compiler/dsl/syntax/resource.rb +0 -1
- data/lib/kubes/compiler/layering.rb +3 -7
- data/lib/kubes/compiler/shared/runtime_helpers.rb +78 -0
- data/lib/kubes/compiler/strategy.rb +1 -15
- data/lib/kubes/compiler/strategy/base.rb +0 -56
- data/lib/kubes/compiler/strategy/dispatcher.rb +60 -0
- data/lib/kubes/compiler/strategy/erb.rb +8 -14
- data/lib/kubes/compiler/strategy/result.rb +6 -2
- data/lib/kubes/compiler/util/normalize.rb +2 -2
- data/lib/kubes/compiler/util/yaml_dump.rb +7 -4
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/new/resource/dsl/endpoint.rb +3 -0
- data/lib/templates/new/resource/yaml/endpoint.yaml +9 -0
- data/spec/kubes/compiler/strategy/{dsl_spec.rb → dispatcher_spec.rb} +10 -9
- metadata +21 -12
- data/lib/kubes/compiler/shared/custom_helpers.rb +0 -17
- data/lib/kubes/compiler/shared/custom_variables.rb +0 -38
- data/lib/kubes/compiler/shared/plugin_helpers.rb +0 -14
- data/lib/kubes/compiler/strategy/dsl.rb +0 -4
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
└──
|
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
|
|
data/docs/_docs/yaml.md
CHANGED
@@ -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
|
-
└──
|
9
|
-
|
10
|
-
|
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.rb # SINGULAR
|
82
|
+
│ └── deployment.rb # SINGULAR
|
83
|
+
└── web
|
84
|
+
├── deployments # PLURAL
|
85
|
+
│ ├── dev.rb # SINGULAR
|
86
|
+
│ └── prod.rb # SINGULAR
|
87
|
+
└── deployments.rb # 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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
|
data/docs/_includes/sidebar.html
CHANGED
@@ -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
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
|
data/kubes.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency "zeitwerk"
|
30
30
|
|
31
31
|
# core helper libs
|
32
|
-
spec.add_dependency "kubes_aws", "~> 0.3.
|
33
|
-
spec.add_dependency "kubes_google", "~> 0.3.
|
32
|
+
spec.add_dependency "kubes_aws", "~> 0.3.1"
|
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"
|
data/lib/kubes/command.rb
CHANGED
@@ -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::
|
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
|
-
|
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
|
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
|
-
|
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
|
@@ -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
|
-
|
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
|
-
"
|
15
|
-
"
|
10
|
+
"all",
|
11
|
+
"all/#{Kubes.env}",
|
16
12
|
"#{kind}",
|
17
13
|
"#{kind}/#{Kubes.env}",
|
18
14
|
]
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Kubes::Compiler::Shared
|
2
|
+
module RuntimeHelpers
|
3
|
+
include Kubes::Compiler::Shared::Helpers
|
4
|
+
|
5
|
+
def load_runtime_helpers
|
6
|
+
load_custom_variables # also load custom variables
|
7
|
+
load_plugin_helpers
|
8
|
+
load_custom_helpers
|
9
|
+
end
|
10
|
+
|
11
|
+
@@custom_helpers_loaded = false
|
12
|
+
def load_custom_helpers
|
13
|
+
return if @@custom_helpers_loaded
|
14
|
+
paths = Dir.glob("#{Kubes.root}/.kubes/helpers/**/*.rb")
|
15
|
+
paths.sort_by! { |p| p.size } # so namespaces are loaded first
|
16
|
+
|
17
|
+
paths.each do |path|
|
18
|
+
filename = path.sub(%r{.*.kubes/helpers/},'').sub('.rb','')
|
19
|
+
module_name = filename.camelize
|
20
|
+
base_class_for_helper.send :include, module_name.constantize
|
21
|
+
end
|
22
|
+
@@custom_helpers_loaded = true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Load plugin helper methods from project
|
26
|
+
@@plugin_helpers_loaded = false
|
27
|
+
def load_plugin_helpers
|
28
|
+
return if @@plugin_helpers_loaded
|
29
|
+
Kubes::Plugin.plugins.each do |klass|
|
30
|
+
helpers_class = "#{klass}::Helpers".constantize # IE: KubesAws::Helpers
|
31
|
+
base_class_for_helper.send :include, helpers_class
|
32
|
+
end
|
33
|
+
@@plugin_helpers_loaded = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def base_class_for_helper
|
37
|
+
if self.is_a?(Kubes::Compiler::Strategy::Erb)
|
38
|
+
Kubes::Compiler::Strategy::Erb
|
39
|
+
else
|
40
|
+
Kubes::Compiler::Dsl::Core::Base
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
include DslEvaluator
|
45
|
+
# Load custom variables from project
|
46
|
+
@@custom_variables_loaded = false
|
47
|
+
def load_custom_variables
|
48
|
+
return if Kubes.kustomize?
|
49
|
+
|
50
|
+
ext = File.extname(@path)
|
51
|
+
role = @path.sub(%r{.*\.kubes/resources/},'').sub(ext,'').split('/').first # IE: web
|
52
|
+
kind = File.basename(@path).sub(ext,'') # IE: deployment
|
53
|
+
all = "all"
|
54
|
+
if @block_form
|
55
|
+
kind = kind.pluralize
|
56
|
+
all = all.pluralize
|
57
|
+
end
|
58
|
+
|
59
|
+
layers = [
|
60
|
+
"base.rb",
|
61
|
+
"#{Kubes.env}.rb",
|
62
|
+
"base/all.rb",
|
63
|
+
"base/all/#{Kubes.env}.rb",
|
64
|
+
"base/#{kind}.rb",
|
65
|
+
"base/#{kind}/base.rb",
|
66
|
+
"base/#{kind}/#{Kubes.env}.rb",
|
67
|
+
"#{role}/#{kind}.rb",
|
68
|
+
"#{role}/#{kind}/base.rb",
|
69
|
+
"#{role}/#{kind}/#{Kubes.env}.rb",
|
70
|
+
]
|
71
|
+
|
72
|
+
layers.each do |layer|
|
73
|
+
path = "#{Kubes.root}/.kubes/variables/#{layer}"
|
74
|
+
evaluate_file(path)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|