kubes 0.4.7 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -0
  3. data/README.md +54 -8
  4. data/docs/_docs/config/hooks/kubes.md +1 -0
  5. data/docs/_docs/config/reference.md +1 -0
  6. data/docs/_docs/config/skip.md +1 -1
  7. data/docs/_docs/dsl/multiple-resources.md +6 -4
  8. data/docs/_docs/dsl/resources/job.md +62 -0
  9. data/docs/_docs/dsl/resources/secret.md +19 -2
  10. data/docs/_docs/extra-env/dsl.md +2 -2
  11. data/docs/_docs/extra-env/yaml.md +1 -1
  12. data/docs/_docs/generators.md +41 -0
  13. data/docs/_docs/helpers.md +17 -3
  14. data/docs/_docs/helpers/aws/advanced.md +10 -0
  15. data/docs/_docs/helpers/aws/advanced/secrets.md +131 -0
  16. data/docs/_docs/helpers/aws/advanced/ssm.md +78 -0
  17. data/docs/_docs/helpers/aws/secrets.md +18 -88
  18. data/docs/_docs/helpers/aws/ssm.md +20 -38
  19. data/docs/_docs/helpers/google/advanced.md +10 -0
  20. data/docs/_docs/helpers/google/advanced/secrets.md +78 -0
  21. data/docs/_docs/helpers/google/gke.md +33 -0
  22. data/docs/_docs/helpers/google/secrets.md +18 -27
  23. data/docs/_docs/helpers/google/service-account.md +8 -0
  24. data/docs/_docs/intro.md +2 -9
  25. data/docs/_docs/intro/docker-image.md +66 -0
  26. data/docs/_docs/intro/how-kubes-works.md +7 -11
  27. data/docs/_docs/layering.md +2 -0
  28. data/docs/_docs/layering/merge.md +1 -1
  29. data/docs/_docs/layering/mix.md +99 -0
  30. data/docs/_docs/learn/dsl/delete.md +10 -2
  31. data/docs/_docs/learn/dsl/review-project.md +2 -2
  32. data/docs/_docs/learn/yaml/delete.md +10 -2
  33. data/docs/_docs/learn/yaml/review-project.md +2 -2
  34. data/docs/_docs/patterns/clock-web-worker.md +3 -3
  35. data/docs/_docs/patterns/migrations.md +1 -1
  36. data/docs/_docs/patterns/multiple-envs.md +55 -0
  37. data/docs/_docs/variables.md +23 -0
  38. data/docs/_docs/variables/advanced.md +62 -0
  39. data/docs/_docs/variables/basic.md +137 -0
  40. data/docs/_docs/vs.md +10 -0
  41. data/docs/_docs/vs/custom.md +109 -0
  42. data/docs/_docs/vs/helm.md +243 -0
  43. data/docs/_docs/vs/kustomize.md +167 -0
  44. data/docs/_docs/yaml.md +2 -2
  45. data/docs/_includes/commands.html +2 -2
  46. data/docs/_includes/intro/features.md +11 -0
  47. data/docs/_includes/layering/layers.md +2 -4
  48. data/docs/_includes/sidebar.html +41 -0
  49. data/docs/_includes/vs/article.md +1 -0
  50. data/docs/_includes/vs/kubes/layering.md +10 -0
  51. data/docs/_includes/vs/kubes/structure.md +24 -0
  52. data/docs/_reference/kubes-delete.md +1 -1
  53. data/docs/_reference/kubes-exec.md +17 -1
  54. data/docs/_reference/kubes-init.md +2 -2
  55. data/docs/_reference/kubes-logs.md +2 -1
  56. data/docs/_reference/kubes-new-help.md +15 -0
  57. data/docs/_reference/kubes-new-helper.md +25 -0
  58. data/docs/_reference/kubes-new-resource.md +56 -0
  59. data/docs/_reference/kubes-new-variable.md +20 -0
  60. data/docs/_reference/kubes-new.md +26 -0
  61. data/docs/_reference/kubes-prune.md +22 -0
  62. data/docs/reference.md +2 -0
  63. data/kubes.gemspec +2 -2
  64. data/lib/kubes.rb +5 -3
  65. data/lib/kubes/auth.rb +4 -1
  66. data/lib/kubes/auth/base.rb +21 -0
  67. data/lib/kubes/auth/ecr.rb +1 -15
  68. data/lib/kubes/auth/gcr.rb +24 -0
  69. data/lib/kubes/cli.rb +9 -1
  70. data/lib/kubes/cli/apply.rb +0 -1
  71. data/lib/kubes/cli/build.rb +6 -0
  72. data/lib/kubes/cli/compile.rb +7 -0
  73. data/lib/kubes/cli/deploy.rb +1 -6
  74. data/lib/kubes/cli/exec.rb +5 -1
  75. data/lib/kubes/cli/help/exec.md +15 -0
  76. data/lib/kubes/cli/help/new/helper.md +4 -0
  77. data/lib/kubes/cli/help/new/resource.md +30 -0
  78. data/lib/kubes/cli/init.rb +1 -1
  79. data/lib/kubes/cli/new.rb +15 -0
  80. data/lib/kubes/cli/new/helper.rb +24 -0
  81. data/lib/kubes/cli/new/resource.rb +97 -0
  82. data/lib/kubes/cli/new/variable.rb +16 -0
  83. data/lib/kubes/cli/prune.rb +4 -2
  84. data/lib/kubes/cli/sequence.rb +1 -0
  85. data/lib/kubes/command.rb +7 -0
  86. data/lib/kubes/compiler.rb +19 -21
  87. data/lib/kubes/compiler/decorator/base.rb +1 -1
  88. data/lib/kubes/compiler/dsl/core/base.rb +6 -9
  89. data/lib/kubes/compiler/dsl/syntax/job.rb +217 -0
  90. data/lib/kubes/compiler/layering.rb +21 -7
  91. data/lib/kubes/compiler/shared/custom_variables.rb +38 -0
  92. data/lib/kubes/compiler/shared/helpers.rb +11 -2
  93. data/lib/kubes/compiler/shared/helpers/deprecated.rb +37 -0
  94. data/lib/kubes/compiler/shared/plugin_helpers.rb +14 -0
  95. data/lib/kubes/compiler/strategy.rb +7 -6
  96. data/lib/kubes/compiler/strategy/base.rb +59 -2
  97. data/lib/kubes/compiler/strategy/dsl.rb +0 -29
  98. data/lib/kubes/compiler/strategy/erb.rb +10 -22
  99. data/lib/kubes/compiler/util/normalize.rb +6 -3
  100. data/lib/kubes/compiler/util/yaml_dump.rb +4 -4
  101. data/lib/kubes/config.rb +14 -1
  102. data/lib/kubes/core.rb +6 -0
  103. data/lib/kubes/docker/strategy/image_name.rb +1 -1
  104. data/lib/kubes/hooks/builder.rb +20 -4
  105. data/lib/kubes/hooks/concern.rb +1 -1
  106. data/lib/kubes/kubectl/batch.rb +7 -33
  107. data/lib/kubes/kubectl/ordering.rb +42 -0
  108. data/lib/kubes/plugin.rb +14 -0
  109. data/lib/kubes/util/sh.rb +1 -1
  110. data/lib/kubes/version.rb +1 -1
  111. data/lib/templates/base/.kubes/config.rb.tt +1 -1
  112. data/lib/templates/base/.kubes/config/env/dev.rb +1 -1
  113. data/lib/templates/base/.kubes/config/env/prod.rb +1 -1
  114. data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
  115. data/lib/templates/new/helper/file.rb +2 -0
  116. data/lib/templates/new/resource/dsl/backend_config.rb +10 -0
  117. data/lib/templates/new/resource/dsl/config_map.rb +5 -0
  118. data/lib/templates/new/resource/dsl/daemon_set.rb +11 -0
  119. data/lib/templates/new/resource/dsl/deployment.rb +4 -0
  120. data/lib/templates/new/resource/dsl/ingress.rb +3 -0
  121. data/lib/templates/new/resource/dsl/job.rb +2 -0
  122. data/lib/templates/new/resource/dsl/managed_certificate.rb +2 -0
  123. data/lib/templates/new/resource/dsl/namespace.rb +2 -0
  124. data/lib/templates/new/resource/dsl/network_policy.rb +7 -0
  125. data/lib/templates/new/resource/dsl/pod.rb +6 -0
  126. data/lib/templates/new/resource/dsl/role.rb +4 -0
  127. data/lib/templates/new/resource/dsl/role_binding.rb +7 -0
  128. data/lib/templates/new/resource/dsl/secret.rb +5 -0
  129. data/lib/templates/new/resource/dsl/service.rb +2 -0
  130. data/lib/templates/new/resource/dsl/service_account.rb +1 -0
  131. data/lib/templates/new/resource/yaml/backend_config.yaml +10 -0
  132. data/lib/templates/new/resource/yaml/config_map.yaml +9 -0
  133. data/lib/templates/new/resource/yaml/daemon_set.yaml +11 -0
  134. data/lib/templates/new/resource/yaml/deployment.yaml +19 -0
  135. data/lib/templates/new/resource/yaml/ingress.yaml +12 -0
  136. data/lib/templates/new/resource/yaml/job.yaml +19 -0
  137. data/lib/templates/new/resource/yaml/managed_certificate.yaml +7 -0
  138. data/lib/templates/new/resource/yaml/namespace.yaml +6 -0
  139. data/lib/templates/new/resource/yaml/network_policy.yaml +20 -0
  140. data/lib/templates/new/resource/yaml/pod.yaml +11 -0
  141. data/lib/templates/new/resource/yaml/role.yaml +13 -0
  142. data/lib/templates/new/resource/yaml/role_binding.yaml +11 -0
  143. data/lib/templates/new/resource/yaml/secret.yaml +9 -0
  144. data/lib/templates/new/resource/yaml/service.yaml +14 -0
  145. data/lib/templates/new/resource/yaml/service_account.yaml +4 -0
  146. data/lib/templates/new/variable/file.rb +1 -0
  147. data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +2 -0
  148. data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
  149. data/spec/fixtures/multiple-files/{deployment-1.rb → .kubes/resources/web/deployment-1.rb} +0 -0
  150. data/spec/fixtures/multiple-files/{deployment-2.rb → .kubes/resources/web/deployment-2.rb} +0 -0
  151. data/spec/fixtures/project/.kubes/resources/{deployment.rb → web/deployment.rb} +0 -0
  152. data/spec/fixtures/project/.kubes/resources/{foobar.rb → web/empty.rb} +0 -0
  153. data/spec/fixtures/project/.kubes/resources/{service.rb → web/service.rb} +1 -1
  154. data/spec/fixtures/syntax/{network_policy.rb → .kubes/resources/web/network_policy.rb} +0 -0
  155. data/spec/fixtures/syntax/{pod.rb → .kubes/resources/web/pod.rb} +0 -0
  156. data/spec/kubes/cli/prune_spec.rb +1 -0
  157. data/spec/kubes/compiler/strategy/dsl_spec.rb +2 -2
  158. data/spec/kubes/compiler_spec.rb +6 -2
  159. data/spec/kubes/dsl/network_policy_spec.rb +1 -1
  160. data/spec/kubes/dsl/pod_spec.rb +1 -1
  161. metadata +98 -25
@@ -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
@@ -2,15 +2,17 @@ class Kubes::CLI
2
2
  class Prune < Base
3
3
  KINDS = %w[ConfigMap Secret]
4
4
  extend Memoist
5
+ include Kubes::Hooks::Concern
5
6
  include Kubes::Util::Sure
6
7
 
7
8
  def run
8
9
  return unless anything_to_prune?
9
10
  logger.info "Pruning old resources: #{KINDS.join(', ')}"
10
-
11
11
  perform(preview: true) unless @options[:yes]
12
12
  sure?("This will prune/delete resources. Are you sure?")
13
- perform(preview: false)
13
+ run_hooks("kubes.rb", name: "prune") do
14
+ perform(preview: false)
15
+ end
14
16
  end
15
17
 
16
18
  def fetcher
@@ -3,6 +3,7 @@ require 'thor'
3
3
  class Kubes::CLI
4
4
  class Sequence < Thor::Group
5
5
  include Thor::Actions
6
+ include Kubes::Logging
6
7
 
7
8
  private
8
9
  def logger
@@ -28,6 +28,8 @@ module Kubes
28
28
  class Command < Thor
29
29
  class << self
30
30
  def dispatch(m, args, options, config)
31
+ check_project!(args.first)
32
+
31
33
  # Allow calling for help via:
32
34
  # kubes command help
33
35
  # kubes command -h
@@ -54,6 +56,11 @@ module Kubes
54
56
  super
55
57
  end
56
58
 
59
+ def check_project!(command_name)
60
+ return if %w[-h help init new].include?(command_name)
61
+ Kubes.check_project!
62
+ end
63
+
57
64
  # Override command_help to include the description at the top of the
58
65
  # long_description.
59
66
  def command_help(shell, command_name)
@@ -3,6 +3,7 @@ module Kubes
3
3
  include Kubes::Hooks::Concern
4
4
  include Kubes::Logging
5
5
  include Kubes::Util::Consider
6
+ include Kubes::Kubectl::Ordering
6
7
 
7
8
  def initialize(options={})
8
9
  @options = options
@@ -21,7 +22,9 @@ module Kubes
21
22
  end
22
23
  end
23
24
 
24
- puts "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
25
+ write_full
26
+
27
+ logger.info "Compiled .kubes/resources files to .kubes/output" if show_compiled_message?
25
28
  end
26
29
 
27
30
  def resources
@@ -34,24 +37,6 @@ module Kubes
34
37
  paths
35
38
  end
36
39
 
37
- # Only considering files 2 layers deep. So:
38
- #
39
- # Yes = web/deployment.yaml
40
- # No = web/deployment/dev.yaml
41
- #
42
- def process?(path)
43
- if Kubes.kustomize?
44
- File.file?(path)
45
- else
46
- consider?(path) && two_levels_deep?(path)
47
- end
48
- end
49
-
50
- def two_levels_deep?(path)
51
- rel_path = path.sub(%r{.*\.kubes/resources/},'')
52
- rel_path.split('/').size == 2
53
- end
54
-
55
40
  def write(result)
56
41
  result.decorate!(:post)
57
42
  filename, content = result.filename, result.content
@@ -64,12 +49,25 @@ module Kubes
64
49
  IO.write(dest, content)
65
50
  end
66
51
 
67
- pretty_dest = dest.sub("#{Kubes.root}/",'')
68
- logger.debug "Compiled #{pretty_dest}"
52
+ logger.debug "Compiled #{pretty(dest)}"
53
+ end
54
+
55
+ def write_full
56
+ full = sorted_files.inject([]) do |acc, file|
57
+ acc << IO.read(file)
58
+ end
59
+ content = full.join("\n")
60
+ path = "#{Kubes.root}/.kubes/output/full.yaml"
61
+ IO.write(path, content)
62
+ logger.debug "Compiled #{pretty(path)}"
69
63
  end
70
64
 
71
65
  def show_compiled_message?
72
66
  !%w[g ge get].include?(ARGV.first)
73
67
  end
68
+
69
+ def pretty(path)
70
+ path.sub("#{Kubes.root}/",'')
71
+ end
74
72
  end
75
73
  end
@@ -11,7 +11,7 @@ module Kubes::Compiler::Decorator
11
11
  end
12
12
 
13
13
  def result
14
- if @data.is_a?(Kubes::Compiler::Dsl::Core::Blocks)
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::Layering
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
@@ -0,0 +1,217 @@
1
+ module Kubes::Compiler::Dsl::Syntax
2
+ class Job < Resource
3
+ fields :container, # <Object>
4
+ "matchLabels:hash", # <map[string]string>
5
+ :sidecar, # <Object>
6
+ :sidecar_name, # <string>
7
+ :sidecar_image, # <string>
8
+ :templateMetadata, # <Object>
9
+ :templateSpec # <Object>
10
+
11
+ # kubectl explain job.spec
12
+ fields :activeDeadlineSeconds, # <integer>
13
+ :backoffLimit, # <integer>
14
+ :completions, # <integer>
15
+ :manualSelector, # <boolean>
16
+ :parallelism, # <integer>
17
+ :selector, # <Object>
18
+ :template, # <Object> -required-
19
+ :ttlSecondsAfterFinished # <integer>
20
+
21
+
22
+ # kubectl explain job.spec.template.spec
23
+ fields :activeDeadlineSeconds, # <integer>
24
+ :affinity, # <Object>
25
+ :automountServiceAccountToken, # <boolean>
26
+ :containers, # <[]Object> -required-
27
+ :dnsConfig, # <Object>
28
+ :dnsPolicy, # <string>
29
+ :enableServiceLinks, # <boolean>
30
+ :ephemeralContainers, # <[]Object>
31
+ :hostAliases, # <[]Object>
32
+ :hostIPC, # <boolean>
33
+ :hostNetwork, # <boolean>
34
+ :hostPID, # <boolean>
35
+ :hostname, # <string>
36
+ :imagePullSecrets, # <[]Object>
37
+ :initContainers, # <[]Object>
38
+ :nodeName, # <string>
39
+ :nodeSelector, # <map[string]string>
40
+ :overhead, # <map[string]string>
41
+ :preemptionPolicy, # <string>
42
+ :priority, # <integer>
43
+ :priorityClassName, # <string>
44
+ :readinessGates, # <[]Object>
45
+ :restartPolicy, # <string>
46
+ :runtimeClassName, # <string>
47
+ :schedulerName, # <string>
48
+ :securityContext, # <Object>
49
+ :serviceAccount, # <string>
50
+ :serviceAccountName, # <string>
51
+ :shareProcessNamespace, # <boolean>
52
+ :subdomain, # <string>
53
+ :terminationGracePeriodSeconds,# <integer>
54
+ :tolerations, # <[]Object>
55
+ :topologySpreadConstraints, # <[]Object>
56
+ :volumes # <[]Object>
57
+
58
+ # kubectl explain deployment.spec.template.spec.containers
59
+ fields :args, # <[]string>
60
+ :command, # <[]string>
61
+ :env, # <[]Object>
62
+ :envFrom, # <[]Object>
63
+ :image, # <string>
64
+ :imagePullPolicy, # <string>
65
+ :lifecycle, # <Object>
66
+ :livenessProbe, # <Object>
67
+ :containerName, # <string> -required- (originally called name)
68
+ :ports, # <[]Object>
69
+ :readinessProbe, # <Object>
70
+ :resources, # <Object>
71
+ :securityContext, # <Object>
72
+ :startupProbe, # <Object>
73
+ :stdin, # <boolean>
74
+ :stdinOnce, # <boolean>
75
+ :terminationMessagePath, # <string>
76
+ :terminationMessagePolicy, # <string>
77
+ :tty, # <boolean>
78
+ :volumeDevices, # <[]Object>
79
+ :volumeMounts, # <[]Object>
80
+ :workingDir # <string>
81
+
82
+ # kubectl explain deployment.spec.template.spec.containers.ports
83
+ fields :containerPort, # <integer> -required-
84
+ :hostIP, # <string>
85
+ :hostPort, # <integer>
86
+ :portName, # <string> (originally called name)
87
+ :protocol # <string>
88
+
89
+ def default_apiVersion
90
+ "batch/v1"
91
+ end
92
+
93
+ def default_spec
94
+ {
95
+ activeDeadlineSeconds: activeDeadlineSeconds,
96
+ backoffLimit: backoffLimit,
97
+ completions: completions,
98
+ manualSelector: manualSelector,
99
+ parallelism: parallelism,
100
+ selector: selector,
101
+ template: template,
102
+ ttlSecondsAfterFinished: ttlSecondsAfterFinished,
103
+ }
104
+ end
105
+
106
+ def default_matchLabels
107
+ labels
108
+ end
109
+
110
+ def default_template
111
+ {
112
+ metadata: templateMetadata,
113
+ spec: templateSpec,
114
+ }
115
+ end
116
+
117
+ def default_templateSpec
118
+ {
119
+ activeDeadlineSeconds: activeDeadlineSeconds,
120
+ affinity: affinity,
121
+ automountServiceAccountToken: automountServiceAccountToken,
122
+ containers: containers,
123
+ dnsConfig: dnsConfig,
124
+ dnsPolicy: dnsPolicy,
125
+ enableServiceLinks: enableServiceLinks,
126
+ ephemeralContainers: ephemeralContainers,
127
+ hostAliases: hostAliases,
128
+ hostIPC: hostIPC,
129
+ hostNetwork: hostNetwork,
130
+ hostPID: hostPID,
131
+ hostname: hostname,
132
+ imagePullSecrets: imagePullSecrets,
133
+ initContainers: initContainers,
134
+ nodeName: nodeName,
135
+ nodeSelector: nodeSelector,
136
+ overhead: overhead,
137
+ preemptionPolicy: preemptionPolicy,
138
+ priority: priority,
139
+ priorityClassName: priorityClassName,
140
+ readinessGates: readinessGates,
141
+ restartPolicy: restartPolicy,
142
+ runtimeClassName: runtimeClassName,
143
+ schedulerName: schedulerName,
144
+ securityContext: securityContext,
145
+ serviceAccount: serviceAccount,
146
+ serviceAccountName: serviceAccountName,
147
+ shareProcessNamespace: shareProcessNamespace,
148
+ subdomain: subdomain,
149
+ terminationGracePeriodSeconds: terminationGracePeriodSeconds,
150
+ tolerations: tolerations,
151
+ topologySpreadConstraints: topologySpreadConstraints,
152
+ volumes: volumes,
153
+ }
154
+ end
155
+
156
+ def default_templateMetadata
157
+ { labels: labels }
158
+ end
159
+
160
+ def default_containers
161
+ [container, sidecar].compact
162
+ end
163
+
164
+ def default_sidecar
165
+ {
166
+ name: sidecar_name,
167
+ image: sidecar_image,
168
+ }
169
+ end
170
+
171
+ def default_sidecar_name
172
+ "sidecar" if sidecar_image # othewise will create invalid sidecar field w/o image
173
+ end
174
+
175
+ def default_container
176
+ {
177
+ args: args,
178
+ command: command,
179
+ env: env,
180
+ envFrom: envFrom,
181
+ image: image,
182
+ imagePullPolicy: imagePullPolicy,
183
+ lifecycle: lifecycle,
184
+ livenessProbe: livenessProbe,
185
+ name: containerName || name,
186
+ ports: ports,
187
+ readinessProbe: readinessProbe,
188
+ resources: resources,
189
+ securityContext: securityContext,
190
+ startupProbe: startupProbe,
191
+ stdin: stdin,
192
+ stdinOnce: stdinOnce,
193
+ terminationMessagePath: terminationMessagePath,
194
+ terminationMessagePolicy: terminationMessagePolicy,
195
+ tty: tty,
196
+ volumeDevices: volumeDevices,
197
+ volumeMounts: volumeMounts,
198
+ workingDir: workingDir,
199
+ }
200
+ end
201
+
202
+ def default_ports
203
+ [
204
+ containerPort: containerPort,
205
+ hostIP: hostIP,
206
+ hostPort: hostPort,
207
+ name: portName,
208
+ protocol: protocol,
209
+ ]
210
+ end
211
+
212
+ # Override command instead of default_command since we want to change a String to an Array
213
+ def command_reader
214
+ @command.is_a?(String) ? @command.split(' ') : @command # else assume Array
215
+ end
216
+ end
217
+ end