kubes 0.4.7 → 0.6.2
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/CHANGELOG.md +28 -0
- data/README.md +54 -8
- data/docs/_docs/config/hooks/kubes.md +1 -0
- data/docs/_docs/config/reference.md +1 -0
- data/docs/_docs/config/skip.md +1 -1
- data/docs/_docs/dsl/multiple-resources.md +6 -4
- data/docs/_docs/dsl/resources/job.md +62 -0
- data/docs/_docs/dsl/resources/secret.md +19 -2
- data/docs/_docs/extra-env/dsl.md +2 -2
- data/docs/_docs/extra-env/yaml.md +1 -1
- data/docs/_docs/generators.md +41 -0
- data/docs/_docs/helpers.md +17 -3
- data/docs/_docs/helpers/aws/advanced.md +10 -0
- data/docs/_docs/helpers/aws/advanced/secrets.md +131 -0
- data/docs/_docs/helpers/aws/advanced/ssm.md +78 -0
- data/docs/_docs/helpers/aws/secrets.md +18 -88
- data/docs/_docs/helpers/aws/ssm.md +20 -38
- data/docs/_docs/helpers/google/advanced.md +10 -0
- data/docs/_docs/helpers/google/advanced/secrets.md +78 -0
- data/docs/_docs/helpers/google/gke.md +33 -0
- data/docs/_docs/helpers/google/secrets.md +18 -27
- data/docs/_docs/helpers/google/service-account.md +8 -0
- data/docs/_docs/intro.md +2 -9
- data/docs/_docs/intro/docker-image.md +66 -0
- data/docs/_docs/intro/how-kubes-works.md +7 -11
- data/docs/_docs/layering.md +2 -0
- data/docs/_docs/layering/merge.md +1 -1
- data/docs/_docs/layering/mix.md +99 -0
- data/docs/_docs/learn/dsl/delete.md +10 -2
- data/docs/_docs/learn/dsl/review-project.md +2 -2
- data/docs/_docs/learn/yaml/delete.md +10 -2
- data/docs/_docs/learn/yaml/review-project.md +2 -2
- data/docs/_docs/patterns/clock-web-worker.md +3 -3
- data/docs/_docs/patterns/migrations.md +1 -1
- data/docs/_docs/patterns/multiple-envs.md +55 -0
- data/docs/_docs/variables.md +23 -0
- data/docs/_docs/variables/advanced.md +62 -0
- data/docs/_docs/variables/basic.md +137 -0
- data/docs/_docs/vs.md +10 -0
- data/docs/_docs/vs/custom.md +109 -0
- data/docs/_docs/vs/helm.md +243 -0
- data/docs/_docs/vs/kustomize.md +167 -0
- data/docs/_docs/yaml.md +2 -2
- data/docs/_includes/commands.html +2 -2
- data/docs/_includes/intro/features.md +11 -0
- data/docs/_includes/layering/layers.md +2 -4
- data/docs/_includes/sidebar.html +41 -0
- data/docs/_includes/vs/article.md +1 -0
- data/docs/_includes/vs/kubes/layering.md +10 -0
- data/docs/_includes/vs/kubes/structure.md +24 -0
- data/docs/_reference/kubes-delete.md +1 -1
- data/docs/_reference/kubes-exec.md +17 -1
- data/docs/_reference/kubes-init.md +2 -2
- data/docs/_reference/kubes-logs.md +2 -1
- data/docs/_reference/kubes-new-help.md +15 -0
- data/docs/_reference/kubes-new-helper.md +25 -0
- data/docs/_reference/kubes-new-resource.md +56 -0
- data/docs/_reference/kubes-new-variable.md +20 -0
- data/docs/_reference/kubes-new.md +26 -0
- data/docs/_reference/kubes-prune.md +22 -0
- data/docs/reference.md +2 -0
- data/kubes.gemspec +2 -2
- data/lib/kubes.rb +5 -3
- data/lib/kubes/auth.rb +4 -1
- data/lib/kubes/auth/base.rb +21 -0
- data/lib/kubes/auth/ecr.rb +1 -15
- data/lib/kubes/auth/gcr.rb +24 -0
- data/lib/kubes/cli.rb +9 -1
- data/lib/kubes/cli/apply.rb +0 -1
- data/lib/kubes/cli/build.rb +6 -0
- data/lib/kubes/cli/compile.rb +7 -0
- data/lib/kubes/cli/deploy.rb +1 -6
- data/lib/kubes/cli/exec.rb +5 -1
- data/lib/kubes/cli/help/exec.md +15 -0
- data/lib/kubes/cli/help/new/helper.md +4 -0
- data/lib/kubes/cli/help/new/resource.md +30 -0
- data/lib/kubes/cli/init.rb +1 -1
- data/lib/kubes/cli/new.rb +15 -0
- data/lib/kubes/cli/new/helper.rb +24 -0
- data/lib/kubes/cli/new/resource.rb +97 -0
- data/lib/kubes/cli/new/variable.rb +16 -0
- data/lib/kubes/cli/prune.rb +4 -2
- data/lib/kubes/cli/sequence.rb +1 -0
- data/lib/kubes/command.rb +7 -0
- data/lib/kubes/compiler.rb +19 -21
- data/lib/kubes/compiler/decorator/base.rb +1 -1
- data/lib/kubes/compiler/dsl/core/base.rb +6 -9
- data/lib/kubes/compiler/dsl/syntax/job.rb +217 -0
- data/lib/kubes/compiler/layering.rb +21 -7
- data/lib/kubes/compiler/shared/custom_variables.rb +38 -0
- data/lib/kubes/compiler/shared/helpers.rb +11 -2
- data/lib/kubes/compiler/shared/helpers/deprecated.rb +37 -0
- data/lib/kubes/compiler/shared/plugin_helpers.rb +14 -0
- data/lib/kubes/compiler/strategy.rb +7 -6
- data/lib/kubes/compiler/strategy/base.rb +59 -2
- data/lib/kubes/compiler/strategy/dsl.rb +0 -29
- data/lib/kubes/compiler/strategy/erb.rb +10 -22
- data/lib/kubes/compiler/util/normalize.rb +6 -3
- data/lib/kubes/compiler/util/yaml_dump.rb +4 -4
- data/lib/kubes/config.rb +14 -1
- data/lib/kubes/core.rb +6 -0
- data/lib/kubes/docker/strategy/image_name.rb +1 -1
- data/lib/kubes/hooks/builder.rb +20 -4
- data/lib/kubes/hooks/concern.rb +1 -1
- data/lib/kubes/kubectl/batch.rb +7 -33
- data/lib/kubes/kubectl/ordering.rb +42 -0
- data/lib/kubes/plugin.rb +14 -0
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/base/.kubes/config.rb.tt +1 -1
- data/lib/templates/base/.kubes/config/env/dev.rb +1 -1
- data/lib/templates/base/.kubes/config/env/prod.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
- data/lib/templates/new/helper/file.rb +2 -0
- data/lib/templates/new/resource/dsl/backend_config.rb +10 -0
- data/lib/templates/new/resource/dsl/config_map.rb +5 -0
- data/lib/templates/new/resource/dsl/daemon_set.rb +11 -0
- data/lib/templates/new/resource/dsl/deployment.rb +4 -0
- data/lib/templates/new/resource/dsl/ingress.rb +3 -0
- data/lib/templates/new/resource/dsl/job.rb +2 -0
- data/lib/templates/new/resource/dsl/managed_certificate.rb +2 -0
- data/lib/templates/new/resource/dsl/namespace.rb +2 -0
- data/lib/templates/new/resource/dsl/network_policy.rb +7 -0
- data/lib/templates/new/resource/dsl/pod.rb +6 -0
- data/lib/templates/new/resource/dsl/role.rb +4 -0
- data/lib/templates/new/resource/dsl/role_binding.rb +7 -0
- data/lib/templates/new/resource/dsl/secret.rb +5 -0
- data/lib/templates/new/resource/dsl/service.rb +2 -0
- data/lib/templates/new/resource/dsl/service_account.rb +1 -0
- data/lib/templates/new/resource/yaml/backend_config.yaml +10 -0
- data/lib/templates/new/resource/yaml/config_map.yaml +9 -0
- data/lib/templates/new/resource/yaml/daemon_set.yaml +11 -0
- data/lib/templates/new/resource/yaml/deployment.yaml +19 -0
- data/lib/templates/new/resource/yaml/ingress.yaml +12 -0
- data/lib/templates/new/resource/yaml/job.yaml +19 -0
- data/lib/templates/new/resource/yaml/managed_certificate.yaml +7 -0
- data/lib/templates/new/resource/yaml/namespace.yaml +6 -0
- data/lib/templates/new/resource/yaml/network_policy.yaml +20 -0
- data/lib/templates/new/resource/yaml/pod.yaml +11 -0
- data/lib/templates/new/resource/yaml/role.yaml +13 -0
- data/lib/templates/new/resource/yaml/role_binding.yaml +11 -0
- data/lib/templates/new/resource/yaml/secret.yaml +9 -0
- data/lib/templates/new/resource/yaml/service.yaml +14 -0
- data/lib/templates/new/resource/yaml/service_account.yaml +4 -0
- data/lib/templates/new/variable/file.rb +1 -0
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +2 -0
- data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
- data/spec/fixtures/multiple-files/{deployment-1.rb → .kubes/resources/web/deployment-1.rb} +0 -0
- data/spec/fixtures/multiple-files/{deployment-2.rb → .kubes/resources/web/deployment-2.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{deployment.rb → web/deployment.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{foobar.rb → web/empty.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{service.rb → web/service.rb} +1 -1
- data/spec/fixtures/syntax/{network_policy.rb → .kubes/resources/web/network_policy.rb} +0 -0
- data/spec/fixtures/syntax/{pod.rb → .kubes/resources/web/pod.rb} +0 -0
- data/spec/kubes/cli/prune_spec.rb +1 -0
- data/spec/kubes/compiler/strategy/dsl_spec.rb +2 -2
- data/spec/kubes/compiler_spec.rb +6 -2
- data/spec/kubes/dsl/network_policy_spec.rb +1 -1
- data/spec/kubes/dsl/pod_spec.rb +1 -1
- metadata +98 -25
|
@@ -11,14 +11,26 @@ class Kubes::Compiler
|
|
|
11
11
|
all = all.pluralize
|
|
12
12
|
end
|
|
13
13
|
layers = [
|
|
14
|
-
"#{all}
|
|
15
|
-
"#{all}/#{Kubes.env}
|
|
16
|
-
"#{kind}
|
|
17
|
-
"#{kind}/#{Kubes.env}
|
|
14
|
+
"#{all}",
|
|
15
|
+
"#{all}/#{Kubes.env}",
|
|
16
|
+
"#{kind}",
|
|
17
|
+
"#{kind}/#{Kubes.env}",
|
|
18
18
|
]
|
|
19
|
-
layers
|
|
19
|
+
layers = add_exts(layers)
|
|
20
|
+
layers.map! do |layer|
|
|
20
21
|
"#{Kubes.root}/.kubes/resources/base/#{layer}"
|
|
21
22
|
end
|
|
23
|
+
layers.select { |layer| File.exist?(layer) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_exts(layers)
|
|
27
|
+
layers.map do |layer|
|
|
28
|
+
[
|
|
29
|
+
"#{layer}.rb",
|
|
30
|
+
"#{layer}.yaml",
|
|
31
|
+
"#{layer}.yml",
|
|
32
|
+
]
|
|
33
|
+
end.flatten
|
|
22
34
|
end
|
|
23
35
|
|
|
24
36
|
def post_layers
|
|
@@ -31,9 +43,11 @@ class Kubes::Compiler
|
|
|
31
43
|
"base",
|
|
32
44
|
Kubes.env.to_s
|
|
33
45
|
]
|
|
34
|
-
layers
|
|
35
|
-
|
|
46
|
+
layers = add_exts(layers)
|
|
47
|
+
layers.map! do |layer|
|
|
48
|
+
"#{kind_path}/#{layer}"
|
|
36
49
|
end
|
|
50
|
+
layers.select { |layer| File.exist?(layer) }
|
|
37
51
|
end
|
|
38
52
|
end
|
|
39
53
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Kubes::Compiler::Shared
|
|
2
|
+
module CustomVariables
|
|
3
|
+
include DslEvaluator
|
|
4
|
+
|
|
5
|
+
# Load custom variables from project
|
|
6
|
+
@@custom_variables_loaded = false
|
|
7
|
+
def load_custom_variables
|
|
8
|
+
return if Kubes.kustomize?
|
|
9
|
+
|
|
10
|
+
ext = File.extname(@path)
|
|
11
|
+
role = @path.sub(%r{.*\.kubes/resources/},'').sub(ext,'').split('/').first # IE: web
|
|
12
|
+
kind = File.basename(@path).sub(ext,'') # IE: deployment
|
|
13
|
+
all = "all"
|
|
14
|
+
if @block_form
|
|
15
|
+
kind = kind.pluralize
|
|
16
|
+
all = all.pluralize
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
layers = [
|
|
20
|
+
"base.rb",
|
|
21
|
+
"#{Kubes.env}.rb",
|
|
22
|
+
"base/all.rb",
|
|
23
|
+
"base/all/#{Kubes.env}.rb",
|
|
24
|
+
"base/#{kind}.rb",
|
|
25
|
+
"base/#{kind}/base.rb",
|
|
26
|
+
"base/#{kind}/#{Kubes.env}.rb",
|
|
27
|
+
"#{role}/#{kind}.rb",
|
|
28
|
+
"#{role}/#{kind}/base.rb",
|
|
29
|
+
"#{role}/#{kind}/#{Kubes.env}.rb",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
layers.each do |layer|
|
|
33
|
+
path = "#{Kubes.root}/.kubes/variables/#{layer}"
|
|
34
|
+
evaluate_file(path)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -5,12 +5,21 @@ module Kubes::Compiler::Shared
|
|
|
5
5
|
extend Kubes::Compiler::Dsl::Core::Fields
|
|
6
6
|
fields "name"
|
|
7
7
|
|
|
8
|
-
def
|
|
8
|
+
def docker_image
|
|
9
9
|
return @options[:image] if @options[:image] # override
|
|
10
|
+
return Kubes.config.image if Kubes.config.image
|
|
11
|
+
built_image_helper
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def built_image
|
|
15
|
+
Deprecated.new.built_image
|
|
16
|
+
built_image_helper
|
|
17
|
+
end
|
|
10
18
|
|
|
19
|
+
def built_image_helper
|
|
11
20
|
path = Kubes.config.state.docker_image_path
|
|
12
21
|
unless File.exist?(path)
|
|
13
|
-
raise "Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build"
|
|
22
|
+
raise Kubes::MissingDockerImage.new("Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build")
|
|
14
23
|
end
|
|
15
24
|
IO.read(path)
|
|
16
25
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Kubes::Compiler::Shared::Helpers
|
|
2
|
+
class Deprecated
|
|
3
|
+
def built_image
|
|
4
|
+
puts "DEPRECATED: built_image is deprecated, use docker_image helper instead.".color(:yellow)
|
|
5
|
+
print_source
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def error_info
|
|
9
|
+
error_info = caller.find { |l| l.include?('.kubes/resources') }
|
|
10
|
+
path, line_number, _ = error_info.split(':')
|
|
11
|
+
{path: path, line_number: line_number}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def print_source
|
|
15
|
+
info = error_info
|
|
16
|
+
path = info[:path]
|
|
17
|
+
line_number = info[:line_number].to_i
|
|
18
|
+
|
|
19
|
+
pretty_path = path.sub("#{Kubes.root}/",'')
|
|
20
|
+
puts "Here's the line in #{pretty_path} that calls built_image:\n\n"
|
|
21
|
+
|
|
22
|
+
contents = IO.read(path)
|
|
23
|
+
content_lines = contents.split("\n")
|
|
24
|
+
context = 5 # lines of context
|
|
25
|
+
top, bottom = [line_number-context-1, 0].max, line_number+context-1
|
|
26
|
+
lpad = content_lines.size.to_s.size
|
|
27
|
+
content_lines[top..bottom].each_with_index do |line_content, index|
|
|
28
|
+
current_line = top+index+1
|
|
29
|
+
if current_line == line_number
|
|
30
|
+
printf("%#{lpad}d %s\n".color(:red), current_line, line_content)
|
|
31
|
+
else
|
|
32
|
+
printf("%#{lpad}d %s\n", current_line, line_content)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Kubes::Compiler::Shared
|
|
2
|
+
module PluginHelpers
|
|
3
|
+
# Load plugin helper methods from project
|
|
4
|
+
@@plugin_helpers_loaded = false
|
|
5
|
+
def load_plugin_helpers
|
|
6
|
+
return if @@plugin_helpers_loaded
|
|
7
|
+
Kubes::Plugin.plugins.each do |klass|
|
|
8
|
+
helpers_class = "#{klass}::Helpers".constantize # IE: KubesAws::Helpers
|
|
9
|
+
self.class.send :include, helpers_class
|
|
10
|
+
end
|
|
11
|
+
@@plugin_helpers_loaded = true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -16,12 +16,13 @@ class Kubes::Compiler
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def strategy_class
|
|
19
|
-
ext = File.extname(@path)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
ext = File.extname(@path).sub('.','').to_sym
|
|
20
|
+
map = {
|
|
21
|
+
rb: Dsl,
|
|
22
|
+
yaml: Erb,
|
|
23
|
+
yml: Erb,
|
|
24
|
+
}
|
|
25
|
+
map[ext]
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -1,13 +1,70 @@
|
|
|
1
1
|
class Kubes::Compiler::Strategy
|
|
2
2
|
class Base
|
|
3
|
-
include Kubes::
|
|
3
|
+
include Kubes::Compiler::Layering
|
|
4
|
+
include Kubes::Compiler::Util::Normalize
|
|
4
5
|
include Kubes::Compiler::Util::SaveFile
|
|
5
|
-
include Kubes::
|
|
6
|
+
include Kubes::Logging
|
|
6
7
|
|
|
7
8
|
def initialize(options={})
|
|
8
9
|
@options = options
|
|
9
10
|
@path = options[:path]
|
|
10
11
|
@save_file = save_file(@path)
|
|
12
|
+
@data = @options[:data] || {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run
|
|
16
|
+
render_files(pre_layers)
|
|
17
|
+
render(@path) # main resource definition
|
|
18
|
+
render_files(post_layers)
|
|
19
|
+
|
|
20
|
+
Result.new(@save_file, @data)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def render_files(paths)
|
|
24
|
+
paths.each do |path|
|
|
25
|
+
next unless File.exist?(path) # layers may not exist
|
|
26
|
+
render(path)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# render and merge
|
|
31
|
+
def render(path)
|
|
32
|
+
result = render_strategy(path)
|
|
33
|
+
if result.is_a?(Kubes::Compiler::Dsl::Core::Blocks)
|
|
34
|
+
result = result.results
|
|
35
|
+
end
|
|
36
|
+
@data.deeper_merge!(result)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Delegate to Dsl or Erb strategy again and pass @data down to allow rendering of a mix of yaml and rb files.
|
|
40
|
+
def render_strategy(path)
|
|
41
|
+
if path.include?('.rb')
|
|
42
|
+
dsl_class.new(@options.merge(path: path, data: @data)).run
|
|
43
|
+
else
|
|
44
|
+
Erb.new(@options.merge(data: @data)).render_result(path)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render_strategy
|
|
49
|
+
def dsl_class
|
|
50
|
+
if block_form?
|
|
51
|
+
Kubes::Compiler::Dsl::Core::Blocks
|
|
52
|
+
else
|
|
53
|
+
syntax_class
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def syntax_class
|
|
58
|
+
klass_name = normalize_kind(@save_file) # IE: @save_file: web/service.yaml
|
|
59
|
+
"Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
|
|
60
|
+
rescue NameError
|
|
61
|
+
logger.debug "Using default resource for: #{klass_name}"
|
|
62
|
+
Kubes::Compiler::Dsl::Syntax::Resource # default
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def block_form?
|
|
66
|
+
type = extract_type(@save_file)
|
|
67
|
+
type.pluralize == type
|
|
11
68
|
end
|
|
12
69
|
end
|
|
13
70
|
end
|
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
class Kubes::Compiler::Strategy
|
|
2
2
|
class Dsl < Base
|
|
3
|
-
include Kubes::Compiler::Util::Normalize
|
|
4
|
-
|
|
5
|
-
def run
|
|
6
|
-
load_custom_helpers
|
|
7
|
-
dsl = dsl_class.new(@options) # Deployment, Service, etc
|
|
8
|
-
data = dsl.run
|
|
9
|
-
Result.new(@save_file, data)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def dsl_class
|
|
13
|
-
if block_form?
|
|
14
|
-
Kubes::Compiler::Dsl::Core::Blocks
|
|
15
|
-
else
|
|
16
|
-
syntax_class
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def syntax_class
|
|
21
|
-
klass_name = normalize_kind(@save_file)
|
|
22
|
-
"Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
|
|
23
|
-
rescue NameError
|
|
24
|
-
logger.debug "Using default resource for: #{klass_name}"
|
|
25
|
-
Kubes::Compiler::Dsl::Syntax::Resource # default
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def block_form?
|
|
29
|
-
type = extract_type(@save_file)
|
|
30
|
-
type.pluralize == type
|
|
31
|
-
end
|
|
32
3
|
end
|
|
33
4
|
end
|
|
@@ -4,31 +4,19 @@ class Kubes::Compiler::Strategy
|
|
|
4
4
|
class Erb < Base
|
|
5
5
|
extend Kubes::Compiler::Dsl::Core::Fields
|
|
6
6
|
include Kubes::Compiler::Dsl::Core::Helpers
|
|
7
|
+
include Kubes::Compiler::Layering
|
|
7
8
|
include Kubes::Compiler::Shared::CustomHelpers
|
|
9
|
+
include Kubes::Compiler::Shared::CustomVariables
|
|
8
10
|
include Kubes::Compiler::Shared::Helpers
|
|
9
|
-
include Kubes::Compiler::
|
|
10
|
-
|
|
11
|
-
def
|
|
11
|
+
include Kubes::Compiler::Shared::PluginHelpers
|
|
12
|
+
|
|
13
|
+
def initialize(options={})
|
|
14
|
+
super
|
|
15
|
+
# For ERB scope is in this same Strategy::Erb class
|
|
16
|
+
# For DSL scope is within the each for the Resource classes. IE: kubes/compile/dsl/core/base.rb
|
|
17
|
+
load_plugin_helpers
|
|
18
|
+
load_custom_variables
|
|
12
19
|
load_custom_helpers
|
|
13
|
-
@data = {}
|
|
14
|
-
|
|
15
|
-
render_files(pre_layers)
|
|
16
|
-
render(@path) # main resource definition
|
|
17
|
-
render_files(post_layers)
|
|
18
|
-
|
|
19
|
-
Result.new(@save_file, @data)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def render_files(paths)
|
|
23
|
-
paths.each do |path|
|
|
24
|
-
render(path)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# render and merge
|
|
29
|
-
def render(path)
|
|
30
|
-
result = render_result(path)
|
|
31
|
-
@data.deeper_merge!(result)
|
|
32
20
|
end
|
|
33
21
|
|
|
34
22
|
def render_result(path)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
module Kubes::Compiler::Util
|
|
2
2
|
module Normalize
|
|
3
3
|
def normalize_kind(path)
|
|
4
|
-
|
|
4
|
+
info = path.sub(%r{.*/.kubes/resources/}, '')
|
|
5
|
+
extract_type(info).underscore.camelize # Deployment, Service, Ingress, ManagedCertificate, etc
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
# info: web/service.yaml
|
|
9
|
+
def extract_type(info)
|
|
10
|
+
_, kind = info.split('/')
|
|
11
|
+
kind.sub('.yaml','').sub('.yml','').sub('.rb','').sub(/-.*/,'')
|
|
9
12
|
end
|
|
10
13
|
end
|
|
11
14
|
end
|
|
@@ -4,12 +4,12 @@ require "yaml"
|
|
|
4
4
|
module Kubes::Compiler::Util
|
|
5
5
|
module YamlDump
|
|
6
6
|
def yaml_dump(data)
|
|
7
|
-
if data.
|
|
8
|
-
items = data.results.map { |k,v| standardize_yaml(v) }
|
|
9
|
-
items.map(&:to_yaml).join("")
|
|
10
|
-
else
|
|
7
|
+
if data.key?("kind") # single resource in YAML
|
|
11
8
|
data = standardize_yaml(data)
|
|
12
9
|
data.to_yaml
|
|
10
|
+
else
|
|
11
|
+
items = data.map { |k,v| standardize_yaml(v) }
|
|
12
|
+
items.map(&:to_yaml).join("")
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
data/lib/kubes/config.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Kubes
|
|
|
32
32
|
|
|
33
33
|
config.repo = nil # expected to be set by .kubes/config.rb
|
|
34
34
|
|
|
35
|
-
config.logger = Logger.new($
|
|
35
|
+
config.logger = Logger.new($stderr)
|
|
36
36
|
config.logger.level = ENV['KUBES_LOG_LEVEL'] || :info
|
|
37
37
|
|
|
38
38
|
config.skip = []
|
|
@@ -81,9 +81,22 @@ module Kubes
|
|
|
81
81
|
yield(@config)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
+
# Load configs example:
|
|
85
|
+
#
|
|
86
|
+
# .kubes/config.rb
|
|
87
|
+
# .kubes/config/env/dev.rb
|
|
88
|
+
# .kubes/config/plugins/google.rb
|
|
89
|
+
# .kubes/config/plugins/google/dev.rb
|
|
90
|
+
#
|
|
84
91
|
def load_configs
|
|
85
92
|
evaluate_file(".kubes/config.rb")
|
|
86
93
|
evaluate_file(".kubes/config/env/#{Kubes.env}.rb")
|
|
94
|
+
Kubes::Plugin.plugins.each do |klass|
|
|
95
|
+
# klass: IE: KubesAws, KubesGoogle
|
|
96
|
+
name = klass.to_s.underscore.sub('kubes_','') # kubes_google => google
|
|
97
|
+
evaluate_file(".kubes/config/plugins/#{name}.rb")
|
|
98
|
+
evaluate_file(".kubes/config/plugins/#{name}/#{Kubes.env}.rb")
|
|
99
|
+
end
|
|
87
100
|
end
|
|
88
101
|
end
|
|
89
102
|
end
|
data/lib/kubes/core.rb
CHANGED
|
@@ -28,5 +28,11 @@ module Kubes
|
|
|
28
28
|
def kustomize?
|
|
29
29
|
Kubectl::Kustomize.detect?
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
def check_project!
|
|
33
|
+
return if File.exist?("#{Kubes.root}/.kubes/config.rb")
|
|
34
|
+
logger.error "ERROR: It doesnt look like this is a kubes project. Are you sure you are in a kubes project?".color(:red)
|
|
35
|
+
ENV['TS_TEST'] ? raise : exit(1)
|
|
36
|
+
end
|
|
31
37
|
end
|
|
32
38
|
end
|
|
@@ -30,7 +30,7 @@ module Kubes::Docker::Strategy
|
|
|
30
30
|
return "tongueroo/demo-kubes:kubes-12345678" if ENV['TEST']
|
|
31
31
|
|
|
32
32
|
unless File.exist?(image_state_path)
|
|
33
|
-
|
|
33
|
+
logger.error "ERROR: Unable to find #{image_state_path} which contains the last docker image name built with kubes build. Please run `kubes docker build` first."
|
|
34
34
|
exit 1
|
|
35
35
|
end
|
|
36
36
|
IO.read(image_state_path).strip
|
data/lib/kubes/hooks/builder.rb
CHANGED
|
@@ -6,8 +6,9 @@ module Kubes::Hooks
|
|
|
6
6
|
include Kubes::Logging
|
|
7
7
|
|
|
8
8
|
attr_accessor :name
|
|
9
|
-
def initialize(
|
|
10
|
-
@
|
|
9
|
+
def initialize(file, options={})
|
|
10
|
+
@file, @options = file, options # IE: .kubes/config/hooks/kubectl.rb
|
|
11
|
+
@dsl_file = "#{Kubes.root}/.kubes/config/hooks/#{@file}"
|
|
11
12
|
@output_file = options[:file] # IE: .kubes/output/web/service.yaml
|
|
12
13
|
@name = options[:name].to_s
|
|
13
14
|
@hooks = {before: {}, after: {}}
|
|
@@ -16,10 +17,26 @@ module Kubes::Hooks
|
|
|
16
17
|
def build
|
|
17
18
|
return @hooks unless File.exist?(@dsl_file)
|
|
18
19
|
evaluate_file(@dsl_file)
|
|
20
|
+
evaluate_plugin_hooks
|
|
19
21
|
@hooks.deep_stringify_keys!
|
|
20
22
|
end
|
|
21
23
|
memoize :build
|
|
22
24
|
|
|
25
|
+
def evaluate_plugin_hooks
|
|
26
|
+
Kubes::Plugin.plugins.each do |klass|
|
|
27
|
+
hooks_class = hooks_class(klass)
|
|
28
|
+
next unless hooks_class
|
|
29
|
+
plugin_hooks = hooks_class.new
|
|
30
|
+
path = "#{plugin_hooks.path}/#{@file}"
|
|
31
|
+
evaluate_file(path)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def hooks_class(klass)
|
|
36
|
+
"#{klass}::Hooks".constantize # IE: KubesGoogle::Hooks
|
|
37
|
+
rescue NameError
|
|
38
|
+
end
|
|
39
|
+
|
|
23
40
|
def run_hooks
|
|
24
41
|
build
|
|
25
42
|
run_each_hook("before")
|
|
@@ -42,8 +59,7 @@ module Kubes::Hooks
|
|
|
42
59
|
id = "#{command} #{type} #{@name}"
|
|
43
60
|
on = " on: #{hook["on"]}" if hook["on"]
|
|
44
61
|
label = " label: #{hook["label"]}" if hook["label"]
|
|
45
|
-
logger.info "Running #{id} hook.#{on}#{label}"
|
|
46
|
-
logger.debug "Hook options: #{hook}"
|
|
62
|
+
logger.info "Hook: Running #{id} hook.#{on}#{label}"
|
|
47
63
|
Runner.new(hook).run
|
|
48
64
|
end
|
|
49
65
|
|