Class: Hippo::ObjectDefinition
- Inherits:
-
Object
- Object
- Hippo::ObjectDefinition
- Defined in:
- lib/hippo/object_definition.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #base64_encode_data!(object = ) ⇒ Object
- #dig(*args) ⇒ Object
-
#initialize(object, stage, clean: false) ⇒ ObjectDefinition
constructor
A new instance of ObjectDefinition.
- #insert_default_labels! ⇒ Object
- #insert_deployment_id!(deployment_id) ⇒ Object
- #insert_namespace! ⇒ Object
- #kind ⇒ Object
- #metadata ⇒ Object
- #name ⇒ Object
- #yaml ⇒ Object
- #yaml_to_apply ⇒ Object
Constructor Details
#initialize(object, stage, clean: false) ⇒ ObjectDefinition
Returns a new instance of ObjectDefinition.
7 8 9 10 |
# File 'lib/hippo/object_definition.rb', line 7 def initialize(object, stage, clean: false) @object = object @stage = stage end |
Instance Method Details
#[](name) ⇒ Object
12 13 14 |
# File 'lib/hippo/object_definition.rb', line 12 def [](name) @object[name] end |
#base64_encode_data!(object = ) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/hippo/object_definition.rb', line 44 def base64_encode_data!(object = @object['data']) object.each do |key, value| object[key] = if value.is_a?(Hash) base64_encode_data!(value) else Base64.encode64(value.to_s).gsub(/\n/, '').strip end end end |
#dig(*args) ⇒ Object
16 17 18 |
# File 'lib/hippo/object_definition.rb', line 16 def dig(*args) @object.dig(*args) end |
#insert_default_labels! ⇒ Object
58 59 60 61 62 63 |
# File 'lib/hippo/object_definition.rb', line 58 def insert_default_labels! ['labels'] ||= {} ['labels']['app.kubernetes.io/name'] = @stage.manifest.name ['labels']['app.kubernetes.io/instance'] = @stage.name ['labels']['app.kubernetes.io/managed-by'] = 'hippo' end |
#insert_deployment_id!(deployment_id) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hippo/object_definition.rb', line 65 def insert_deployment_id!(deployment_id) ['labels'] ||= {} ['labels']['hippo.adam.ac/deployID'] = deployment_id # For deployments, insert the ID on the template too for deployments. if kind == 'Deployment' && = @object.dig('spec', 'template', 'metadata') ['labels'] ||= {} ['labels']['hippo.adam.ac/deployID'] = deployment_id end end |
#insert_namespace! ⇒ Object
54 55 56 |
# File 'lib/hippo/object_definition.rb', line 54 def insert_namespace! ['namespace'] = @stage.namespace end |
#kind ⇒ Object
28 29 30 |
# File 'lib/hippo/object_definition.rb', line 28 def kind @object['kind'] end |
#metadata ⇒ Object
24 25 26 |
# File 'lib/hippo/object_definition.rb', line 24 def @object['metadata'] ||= {} end |
#name ⇒ Object
20 21 22 |
# File 'lib/hippo/object_definition.rb', line 20 def name ['name'] end |
#yaml ⇒ Object
32 33 34 |
# File 'lib/hippo/object_definition.rb', line 32 def yaml @object.to_yaml(line_width: -1) end |
#yaml_to_apply ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/hippo/object_definition.rb', line 36 def yaml_to_apply object = ObjectDefinition.new(@object.dup, @stage) object.insert_namespace! object.insert_default_labels! object.base64_encode_data! if kind == 'Secret' object.yaml end |