kubes 0.5.1 → 0.6.0
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 +10 -0
- data/README.md +52 -0
- data/docs/_docs/dsl/resources/secret.md +19 -2
- data/docs/_docs/generators.md +4 -4
- 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/advanced.md +10 -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/secrets.md +78 -0
- data/docs/_docs/helpers/google/advanced.md +10 -0
- data/docs/_docs/helpers/google/secrets.md +18 -27
- data/docs/_docs/helpers.md +16 -2
- data/docs/_docs/intro.md +2 -11
- data/docs/_docs/layering/mix.md +99 -0
- data/docs/_docs/layering.md +2 -0
- data/docs/_docs/patterns/multiple-envs.md +55 -0
- data/docs/_docs/variables/advanced.md +62 -0
- data/docs/_docs/variables/basic.md +137 -0
- data/docs/_docs/variables.md +23 -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/vs.md +10 -0
- data/docs/_includes/intro/features.md +10 -0
- data/docs/_includes/layering/layers.md +2 -4
- data/docs/_includes/sidebar.html +39 -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-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 +6 -38
- data/kubes.gemspec +2 -2
- 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/auth.rb +4 -1
- data/lib/kubes/cli/help/new/helper.md +4 -0
- data/lib/kubes/cli/help/{new.md → new/resource.md} +3 -3
- 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/new.rb +12 -94
- data/lib/kubes/command.rb +1 -1
- data/lib/kubes/compiler/decorator/base.rb +1 -1
- data/lib/kubes/compiler/dsl/core/base.rb +6 -9
- data/lib/kubes/compiler/layering.rb +21 -7
- data/lib/kubes/compiler/shared/custom_variables.rb +38 -0
- data/lib/kubes/compiler/shared/plugin_helpers.rb +14 -0
- 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/strategy.rb +7 -6
- data/lib/kubes/compiler/util/normalize.rb +6 -3
- data/lib/kubes/compiler/util/yaml_dump.rb +4 -4
- data/lib/kubes/plugin.rb +14 -0
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/kubes.rb +4 -3
- data/lib/templates/new/helper/file.rb +2 -0
- data/lib/templates/new/{dsl → resource/dsl}/backend_config.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/config_map.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/daemon_set.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/deployment.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/ingress.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/job.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/managed_certificate.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/namespace.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/network_policy.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/pod.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/role.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/role_binding.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/secret.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/service.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/service_account.rb +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/backend_config.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/config_map.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/daemon_set.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/deployment.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/ingress.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/job.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/managed_certificate.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/namespace.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/network_policy.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/pod.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/role.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/role_binding.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/secret.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/service.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/service_account.yaml +0 -0
- data/lib/templates/new/variable/file.rb +1 -0
- 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/compiler/strategy/dsl_spec.rb +2 -2
- data/spec/kubes/compiler_spec.rb +1 -1
- data/spec/kubes/dsl/network_policy_spec.rb +1 -1
- data/spec/kubes/dsl/pod_spec.rb +1 -1
- metadata +81 -48
|
@@ -11,48 +11,16 @@ reference: true
|
|
|
11
11
|
|
|
12
12
|
Generates new resource.
|
|
13
13
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
$ kubes new ingress
|
|
17
|
-
create .kubes/resources/web/ingress.yaml
|
|
18
|
-
$ kubes new service_account
|
|
19
|
-
create .kubes/resources/shared/service_account.yaml
|
|
20
|
-
$
|
|
21
|
-
|
|
22
|
-
## Supported Resources
|
|
23
|
-
|
|
24
|
-
Here's a list of some of the supported resources.
|
|
25
|
-
|
|
26
|
-
backend_config
|
|
27
|
-
config_map
|
|
28
|
-
daemon_set
|
|
29
|
-
deployment
|
|
30
|
-
ingress
|
|
31
|
-
job
|
|
32
|
-
managed_certificate
|
|
33
|
-
namespace
|
|
34
|
-
network_policy
|
|
35
|
-
pod
|
|
36
|
-
role_binding
|
|
37
|
-
role
|
|
38
|
-
secret
|
|
39
|
-
service_account
|
|
40
|
-
service
|
|
41
|
-
|
|
42
|
-
Refer to the source code to all the resources that the generator supports:
|
|
43
|
-
https://github.com/boltops-tools/kubes/blob/master/lib/templates/new/yaml
|
|
14
|
+
## Subcommands
|
|
44
15
|
|
|
16
|
+
* [kubes new helper]({% link _reference/kubes-new-helper.md %}) - Generates kubes helper file.
|
|
17
|
+
* [kubes new resource]({% link _reference/kubes-new-resource.md %}) - Generates Kubes Kubernetes resource definition.
|
|
18
|
+
* [kubes new variable]({% link _reference/kubes-new-variable.md %}) - Generates kubes variable file.
|
|
45
19
|
|
|
46
20
|
## Options
|
|
47
21
|
|
|
48
22
|
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
y, [--force] # Bypass overwrite are you sure prompt for existing files
|
|
52
|
-
r, [--role=ROLE] # Role. IE: web, clock, worker, migrate, etc. Defaults to convention: web or shared when not set
|
|
53
|
-
t, [--type=TYPE] # Type: dsl or yaml
|
|
54
|
-
# Default: yaml
|
|
55
|
-
[--verbose], [--no-verbose]
|
|
56
|
-
[--noop], [--no-noop]
|
|
23
|
+
[--verbose], [--no-verbose]
|
|
24
|
+
[--noop], [--no-noop]
|
|
57
25
|
```
|
|
58
26
|
|
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"
|
|
33
|
-
spec.add_dependency "kubes_google"
|
|
32
|
+
spec.add_dependency "kubes_aws" # , "~> 0.2.0"
|
|
33
|
+
spec.add_dependency "kubes_google" # , "~> 0.2.0"
|
|
34
34
|
|
|
35
35
|
spec.add_development_dependency "bundler"
|
|
36
36
|
spec.add_development_dependency "byebug"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
class Kubes::Auth
|
|
4
|
+
class Base
|
|
5
|
+
include Kubes::Logging
|
|
6
|
+
|
|
7
|
+
def initialize(image)
|
|
8
|
+
@image = image
|
|
9
|
+
@repo_domain = "#{image.split('/').first}"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ensure_dotdocker_exists
|
|
13
|
+
dirname = File.dirname(docker_config)
|
|
14
|
+
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def docker_config
|
|
18
|
+
"#{ENV['HOME']}/.docker/config.json"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/kubes/auth/ecr.rb
CHANGED
|
@@ -14,14 +14,9 @@
|
|
|
14
14
|
# If that format changes, the update will need to be updated.
|
|
15
15
|
#
|
|
16
16
|
class Kubes::Auth
|
|
17
|
-
class Ecr
|
|
17
|
+
class Ecr < Base
|
|
18
18
|
include Kubes::AwsServices
|
|
19
19
|
|
|
20
|
-
def initialize(image)
|
|
21
|
-
@image = image
|
|
22
|
-
@repo_domain = "#{image.split('/').first}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
20
|
def run
|
|
26
21
|
auth_token = fetch_auth_token
|
|
27
22
|
if File.exist?(docker_config)
|
|
@@ -42,14 +37,5 @@ class Kubes::Auth
|
|
|
42
37
|
def fetch_auth_token
|
|
43
38
|
ecr.get_authorization_token.authorization_data.first.authorization_token
|
|
44
39
|
end
|
|
45
|
-
|
|
46
|
-
def docker_config
|
|
47
|
-
"#{ENV['HOME']}/.docker/config.json"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def ensure_dotdocker_exists
|
|
51
|
-
dirname = File.dirname(docker_config)
|
|
52
|
-
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
|
|
53
|
-
end
|
|
54
40
|
end
|
|
55
41
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class Kubes::Auth
|
|
2
|
+
class Gcr < Base
|
|
3
|
+
def run
|
|
4
|
+
authorize! unless authorized?
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def authorize!
|
|
8
|
+
command = "gcloud auth configure-docker"
|
|
9
|
+
logger.debug "Authorizing GCR with: #{command}"
|
|
10
|
+
success = system(command)
|
|
11
|
+
unless success
|
|
12
|
+
logger.error "ERROR: running #{command}".color(:red)
|
|
13
|
+
exit $?.exitstatus if exit_on_fail
|
|
14
|
+
end
|
|
15
|
+
success
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def authorized?
|
|
19
|
+
return false unless File.exist?(docker_config)
|
|
20
|
+
data = JSON.load(IO.read(docker_config))
|
|
21
|
+
!!data.dig('credHelpers', 'gcr.io')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/kubes/auth.rb
CHANGED
|
@@ -10,11 +10,14 @@ module Kubes
|
|
|
10
10
|
klass.new(@image).run
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
# Currently only support ECR
|
|
13
|
+
# Currently only support ECR and GCR
|
|
14
|
+
# TODO: consider moving this to plugin gems
|
|
14
15
|
def strategy_class
|
|
15
16
|
case @image
|
|
16
17
|
when /\.amazonaws\.com/ # IE: 112233445566.dkr.ecr.us-west-2.amazonaws.com/demo/sinatra
|
|
17
18
|
Ecr
|
|
19
|
+
when /gcr\.io/
|
|
20
|
+
Gcr
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
## Examples
|
|
2
2
|
|
|
3
|
-
$ kubes new ingress
|
|
3
|
+
$ kubes new resource ingress
|
|
4
4
|
create .kubes/resources/web/ingress.yaml
|
|
5
|
-
$ kubes new service_account
|
|
5
|
+
$ kubes new resource service_account
|
|
6
6
|
create .kubes/resources/shared/service_account.yaml
|
|
7
7
|
$
|
|
8
8
|
|
|
@@ -27,4 +27,4 @@ Here's a list of some of the supported resources.
|
|
|
27
27
|
service
|
|
28
28
|
|
|
29
29
|
Refer to the source code to all the resources that the generator supports:
|
|
30
|
-
https://github.com/boltops-tools/kubes/blob/master/lib/templates/new/yaml
|
|
30
|
+
https://github.com/boltops-tools/kubes/blob/master/lib/templates/new/resource/yaml
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class Kubes::CLI::New
|
|
2
|
+
class Helper < Kubes::CLI::Sequence
|
|
3
|
+
argument :name, default: "custom"
|
|
4
|
+
|
|
5
|
+
def self.options
|
|
6
|
+
[
|
|
7
|
+
[:force, aliases: ["y"], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
|
8
|
+
]
|
|
9
|
+
end
|
|
10
|
+
options.each { |args| class_option(*args) }
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
def underscored_name
|
|
14
|
+
name.include?("_helper") ? name : "#{name}_helper"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
public
|
|
18
|
+
def create_helper
|
|
19
|
+
set_source("new/helper")
|
|
20
|
+
file = "#{underscored_name}.rb"
|
|
21
|
+
template "file.rb", ".kubes/helpers/#{file}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
class Kubes::CLI::New
|
|
2
|
+
class Resource < Kubes::CLI::Sequence
|
|
3
|
+
argument :kind
|
|
4
|
+
|
|
5
|
+
def self.options
|
|
6
|
+
[
|
|
7
|
+
[:app, aliases: ["a"], default: "demo", desc: "App name"],
|
|
8
|
+
[:force, aliases: ["y"], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
|
9
|
+
[:role, aliases: ["r"], desc: "Role. IE: web, clock, worker, migrate, etc. Defaults to convention: web or shared when not set"],
|
|
10
|
+
[:type, aliases: ["t"], default: "yaml", desc: "Type: dsl or yaml"],
|
|
11
|
+
]
|
|
12
|
+
end
|
|
13
|
+
options.each { |args| class_option(*args) }
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
def app
|
|
17
|
+
options[:app]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def role
|
|
21
|
+
role = options[:role]
|
|
22
|
+
return role if role
|
|
23
|
+
shared = %w[
|
|
24
|
+
config_map
|
|
25
|
+
namespace
|
|
26
|
+
network_policy
|
|
27
|
+
persistent_volume
|
|
28
|
+
persistent_volume_claim
|
|
29
|
+
secret
|
|
30
|
+
service_account
|
|
31
|
+
]
|
|
32
|
+
if shared.include?(full_kind)
|
|
33
|
+
"shared"
|
|
34
|
+
elsif full_kind == "job"
|
|
35
|
+
"migrate"
|
|
36
|
+
else
|
|
37
|
+
"web"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def full_kind
|
|
42
|
+
# shorthands
|
|
43
|
+
map = {
|
|
44
|
+
cj: "cron_job",
|
|
45
|
+
cm: "config_map",
|
|
46
|
+
crd: "custom_resource_definition",
|
|
47
|
+
crds: "custom_resource_definition",
|
|
48
|
+
cs: "component_statuses",
|
|
49
|
+
csr: "certificate_signing_request",
|
|
50
|
+
deploy: "deployment",
|
|
51
|
+
ds: "daemonset",
|
|
52
|
+
ep: "endpoints",
|
|
53
|
+
ev: "event",
|
|
54
|
+
hpa: "horizontal_pod_autoscaler",
|
|
55
|
+
ing: "ingress",
|
|
56
|
+
limits: "limit_range",
|
|
57
|
+
netpol: "network_policy",
|
|
58
|
+
no: "node",
|
|
59
|
+
ns: "namespace",
|
|
60
|
+
pc: "priority_class",
|
|
61
|
+
pdb: "pod_disruption_budget",
|
|
62
|
+
po: "pod",
|
|
63
|
+
psp: "pods_ecurity_policy",
|
|
64
|
+
pv: "persistent_volume",
|
|
65
|
+
pvc: "persistent_volume_claim",
|
|
66
|
+
quota: "resource_quota",
|
|
67
|
+
rc: "replication_controller",
|
|
68
|
+
rs: "replica_set",
|
|
69
|
+
sa: "service_account",
|
|
70
|
+
sc: "storage_classes",
|
|
71
|
+
sgp: "security_group_policy",
|
|
72
|
+
sts: "stateful_set",
|
|
73
|
+
svc: "service",
|
|
74
|
+
}.stringify_keys!
|
|
75
|
+
map[kind] || kind
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def file
|
|
79
|
+
ext = options[:type] == "yaml" ? "yaml" : "rb"
|
|
80
|
+
"#{full_kind}.#{ext}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
public
|
|
84
|
+
def set_template_source
|
|
85
|
+
path = File.expand_path("../../../templates/new/resource/#{options[:type]}/#{file}", __dir__)
|
|
86
|
+
unless File.exist?(path)
|
|
87
|
+
logger.info "ERROR: Generator for #{file} not supported".color(:red)
|
|
88
|
+
exit 1
|
|
89
|
+
end
|
|
90
|
+
set_source("new/resource/#{options[:type]}")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def create_resource
|
|
94
|
+
template file, ".kubes/resources/#{role}/#{file}"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Kubes::CLI::New
|
|
2
|
+
class Variable < Kubes::CLI::Sequence
|
|
3
|
+
def self.options
|
|
4
|
+
[
|
|
5
|
+
[:force, aliases: ["y"], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
|
6
|
+
]
|
|
7
|
+
end
|
|
8
|
+
options.each { |args| class_option(*args) }
|
|
9
|
+
|
|
10
|
+
def create_helper
|
|
11
|
+
set_source("new/variable")
|
|
12
|
+
file = "#{Kubes.env}.rb"
|
|
13
|
+
template "file.rb", ".kubes/variables/#{file}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/kubes/cli/new.rb
CHANGED
|
@@ -1,97 +1,15 @@
|
|
|
1
1
|
class Kubes::CLI
|
|
2
|
-
class New <
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
def app
|
|
17
|
-
options[:app]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def role
|
|
21
|
-
role = options[:role]
|
|
22
|
-
return role if role
|
|
23
|
-
shared = %w[
|
|
24
|
-
config_map
|
|
25
|
-
namespace
|
|
26
|
-
network_policy
|
|
27
|
-
persistent_volume
|
|
28
|
-
persistent_volume_claim
|
|
29
|
-
secret
|
|
30
|
-
service_account
|
|
31
|
-
]
|
|
32
|
-
if shared.include?(full_kind)
|
|
33
|
-
"shared"
|
|
34
|
-
elsif full_kind == "job"
|
|
35
|
-
"migrate"
|
|
36
|
-
else
|
|
37
|
-
"web"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def full_kind
|
|
42
|
-
# shorthands
|
|
43
|
-
map = {
|
|
44
|
-
cj: "cron_job",
|
|
45
|
-
cm: "config_map",
|
|
46
|
-
crd: "custom_resource_definition",
|
|
47
|
-
crds: "custom_resource_definition",
|
|
48
|
-
cs: "component_statuses",
|
|
49
|
-
csr: "certificate_signing_request",
|
|
50
|
-
deploy: "deployment",
|
|
51
|
-
ds: "daemonset",
|
|
52
|
-
ep: "endpoints",
|
|
53
|
-
ev: "event",
|
|
54
|
-
hpa: "horizontal_pod_autoscaler",
|
|
55
|
-
ing: "ingress",
|
|
56
|
-
limits: "limit_range",
|
|
57
|
-
netpol: "network_policy",
|
|
58
|
-
no: "node",
|
|
59
|
-
ns: "namespace",
|
|
60
|
-
pc: "priority_class",
|
|
61
|
-
pdb: "pod_disruption_budget",
|
|
62
|
-
po: "pod",
|
|
63
|
-
psp: "pods_ecurity_policy",
|
|
64
|
-
pv: "persistent_volume",
|
|
65
|
-
pvc: "persistent_volume_claim",
|
|
66
|
-
quota: "resource_quota",
|
|
67
|
-
rc: "replication_controller",
|
|
68
|
-
rs: "replica_set",
|
|
69
|
-
sa: "service_account",
|
|
70
|
-
sc: "storage_classes",
|
|
71
|
-
sgp: "security_group_policy",
|
|
72
|
-
sts: "stateful_set",
|
|
73
|
-
svc: "service",
|
|
74
|
-
}.stringify_keys!
|
|
75
|
-
map[kind] || kind
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def file
|
|
79
|
-
ext = options[:type] == "yaml" ? "yaml" : "rb"
|
|
80
|
-
"#{full_kind}.#{ext}"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
public
|
|
84
|
-
def set_template_source
|
|
85
|
-
path = File.expand_path("../../templates/new/#{options[:type]}/#{file}", __dir__)
|
|
86
|
-
unless File.exist?(path)
|
|
87
|
-
logger.info "ERROR: Generator for #{file} not supported".color(:red)
|
|
88
|
-
exit 1
|
|
89
|
-
end
|
|
90
|
-
set_source("new/#{options[:type]}")
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def create_resource
|
|
94
|
-
template file, ".kubes/resources/#{role}/#{file}"
|
|
95
|
-
end
|
|
2
|
+
class New < Kubes::Command
|
|
3
|
+
long_desc Help.text("new/resource")
|
|
4
|
+
Resource.options.each { |args| option(*args) }
|
|
5
|
+
register(Resource, "resource", "resource", "Generates Kubes Kubernetes resource definition.")
|
|
6
|
+
|
|
7
|
+
long_desc Help.text("new/helper")
|
|
8
|
+
Helper.options.each { |args| option(*args) }
|
|
9
|
+
register(Helper, "helper", "helper", "Generates kubes helper file.")
|
|
10
|
+
|
|
11
|
+
long_desc Help.text("new/variable")
|
|
12
|
+
Variable.options.each { |args| option(*args) }
|
|
13
|
+
register(Variable, "variable", "variable", "Generates kubes variable file.")
|
|
96
14
|
end
|
|
97
15
|
end
|
data/lib/kubes/command.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Kubes::Compiler::Decorator
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def result
|
|
14
|
-
if @data.
|
|
14
|
+
if @data.key?(Kubes::Compiler::Dsl::Core::Blocks)
|
|
15
15
|
@data.results.each { |k,v| process(v) } # returns nil
|
|
16
16
|
else
|
|
17
17
|
process # processes and returns @data
|
|
@@ -3,25 +3,22 @@ module Kubes::Compiler::Dsl::Core
|
|
|
3
3
|
extend Fields
|
|
4
4
|
include DslEvaluator
|
|
5
5
|
include Helpers
|
|
6
|
-
include Kubes::Compiler::
|
|
6
|
+
include Kubes::Compiler::Shared::CustomHelpers
|
|
7
|
+
include Kubes::Compiler::Shared::CustomVariables
|
|
8
|
+
include Kubes::Compiler::Shared::PluginHelpers
|
|
7
9
|
|
|
8
10
|
def initialize(options={})
|
|
9
11
|
@options = options
|
|
10
12
|
@name = options[:name]
|
|
11
13
|
@path = options[:path]
|
|
14
|
+
load_plugin_helpers
|
|
15
|
+
load_custom_variables
|
|
16
|
+
load_custom_helpers
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
def run
|
|
15
|
-
evaluate_files(pre_layers)
|
|
16
20
|
evaluate_file(@path) # main resource definition
|
|
17
|
-
evaluate_files(post_layers)
|
|
18
21
|
result if respond_to?(:result) # block form doesnt have result
|
|
19
22
|
end
|
|
20
|
-
|
|
21
|
-
def evaluate_files(paths)
|
|
22
|
-
paths.each do |path|
|
|
23
|
-
evaluate_file(path)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
23
|
end
|
|
27
24
|
end
|
|
@@ -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
|
|
@@ -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
|
|
9
|
+
self.class.send :include, helpers_class
|
|
10
|
+
end
|
|
11
|
+
@@plugin_helpers_loaded = true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
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
|