Class: Metatron::Templates::Container
- Inherits:
-
Object
- Object
- Metatron::Templates::Container
- Defined in:
- lib/metatron/templates/container.rb
Overview
Template for containers used by k8s resources (not an actual resource)
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#command ⇒ Object
Returns the value of attribute command.
-
#env ⇒ Object
(also: #environment)
Returns the value of attribute env.
-
#envfrom ⇒ Object
(also: #envFrom)
Returns the value of attribute envfrom.
-
#image ⇒ Object
Returns the value of attribute image.
-
#image_pull_policy ⇒ Object
(also: #imagePullPolicy)
Returns the value of attribute image_pull_policy.
-
#lifecycle ⇒ Object
Returns the value of attribute lifecycle.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#probes ⇒ Object
Returns the value of attribute probes.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#security_context ⇒ Object
(also: #securityContext)
Returns the value of attribute security_context.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#termination_message_path ⇒ Object
(also: #terminationMessagePath)
Returns the value of attribute termination_message_path.
-
#termination_message_policy ⇒ Object
(also: #terminationMessagePolicy)
Returns the value of attribute termination_message_policy.
-
#tty ⇒ Object
Returns the value of attribute tty.
-
#volume_mounts ⇒ Object
(also: #volumeMounts)
Returns the value of attribute volume_mounts.
Instance Method Summary collapse
- #formatted_args ⇒ Object
- #formatted_envfrom ⇒ Object
-
#formatted_environment ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #formatted_lifecycle ⇒ Object
- #formatted_ports ⇒ Object
- #formatted_resources ⇒ Object
- #formatted_security_context ⇒ Object
- #formatted_volume_mounts ⇒ Object
-
#initialize(name, image = "gcr.io/google_containers/pause") ⇒ Container
constructor
A new instance of Container.
-
#render ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(name, image = "gcr.io/google_containers/pause") ⇒ Container
Returns a new instance of Container.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/metatron/templates/container.rb', line 19 def initialize(name, image = "gcr.io/google_containers/pause") @name = name @image = image @command = nil @args = [] @env = [] @resources = {} @volume_mounts = [] @image_pull_policy = "IfNotPresent" @lifecycle = {} @probes = {} @stdin = true @tty = true = nil = nil end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def args @args end |
#command ⇒ Object
Returns the value of attribute command.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def command @command end |
#env ⇒ Object Also known as: environment
Returns the value of attribute env.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def env @env end |
#envfrom ⇒ Object Also known as: envFrom
Returns the value of attribute envfrom.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def envfrom @envfrom end |
#image ⇒ Object
Returns the value of attribute image.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def image @image end |
#image_pull_policy ⇒ Object Also known as: imagePullPolicy
Returns the value of attribute image_pull_policy.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def image_pull_policy @image_pull_policy end |
#lifecycle ⇒ Object
Returns the value of attribute lifecycle.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def lifecycle @lifecycle end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def name @name end |
#ports ⇒ Object
Returns the value of attribute ports.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def ports @ports end |
#probes ⇒ Object
Returns the value of attribute probes.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def probes @probes end |
#resources ⇒ Object
Returns the value of attribute resources.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def resources @resources end |
#security_context ⇒ Object Also known as: securityContext
Returns the value of attribute security_context.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def security_context @security_context end |
#stdin ⇒ Object
Returns the value of attribute stdin.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def stdin @stdin end |
#termination_message_path ⇒ Object Also known as: terminationMessagePath
Returns the value of attribute termination_message_path.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def end |
#termination_message_policy ⇒ Object Also known as: terminationMessagePolicy
Returns the value of attribute termination_message_policy.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def end |
#tty ⇒ Object
Returns the value of attribute tty.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def tty @tty end |
#volume_mounts ⇒ Object Also known as: volumeMounts
Returns the value of attribute volume_mounts.
7 8 9 |
# File 'lib/metatron/templates/container.rb', line 7 def volume_mounts @volume_mounts end |
Instance Method Details
#formatted_args ⇒ Object
58 59 60 61 62 |
# File 'lib/metatron/templates/container.rb', line 58 def formatted_args return {} unless args && !args.empty? { args: } end |
#formatted_envfrom ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/metatron/templates/container.rb', line 92 def formatted_envfrom if envfrom && !envfrom.empty? { envFrom: envfrom.map { |secret| { secretRef: { name: secret } } } } else {} end end |
#formatted_environment ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/metatron/templates/container.rb', line 70 def formatted_environment # rubocop:disable Metrics/PerceivedComplexity return {} unless env && !env.empty? if env.is_a?(Hash) mapped_values = env.map do |key, value| v = { name: key } if value.is_a?(Hash) v.merge!(value) else v[:value] = value end v end { env: mapped_values } elsif env.is_a?(Array) { env: } else raise "Environment must be a Hash or Array" end end |
#formatted_lifecycle ⇒ Object
64 65 66 67 68 |
# File 'lib/metatron/templates/container.rb', line 64 def formatted_lifecycle return {} unless lifecycle && !lifecycle.empty? { lifecycle: } end |
#formatted_ports ⇒ Object
102 |
# File 'lib/metatron/templates/container.rb', line 102 def formatted_ports = ports&.any? ? { ports: } : {} |
#formatted_resources ⇒ Object
100 |
# File 'lib/metatron/templates/container.rb', line 100 def formatted_resources = resources&.any? ? { resources: } : {} |
#formatted_security_context ⇒ Object
104 105 106 |
# File 'lib/metatron/templates/container.rb', line 104 def formatted_security_context security_context && !security_context.empty? ? { securityContext: } : {} end |
#formatted_volume_mounts ⇒ Object
108 |
# File 'lib/metatron/templates/container.rb', line 108 def formatted_volume_mounts = volume_mounts&.any? ? { volumeMounts: } : {} |
#render ⇒ Object
rubocop:disable Metrics/AbcSize
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/metatron/templates/container.rb', line 36 def render # rubocop:disable Metrics/AbcSize { name:, command:, image:, imagePullPolicy:, stdin:, tty:, terminationMessagePath:, terminationMessagePolicy: }.merge(probes) .merge(formatted_resources) .merge(formatted_environment) .merge(formatted_envfrom) .merge(formatted_ports) .merge(formatted_volume_mounts) .merge(formatted_security_context) .merge(formatted_args) .merge(formatted_lifecycle) .compact end |