Class: DTK::State::CrdAssembly
- Inherits:
-
Object
- Object
- DTK::State::CrdAssembly
- Includes:
- Utils::CrdHelper
- Defined in:
- lib/state/crd_assembly.rb
Constant Summary collapse
- ASSEMBLY_CRD_VERSION =
ENV["ASSEMBLY_CRD_VERSION"]
Instance Attribute Summary collapse
-
#component_objs ⇒ Object
readonly
Returns the value of attribute component_objs.
-
#components ⇒ Object
Returns the value of attribute components.
-
#crd_content ⇒ Object
readonly
Returns the value of attribute crd_content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Class Method Summary collapse
- .get(namespace, name, opts = {}) ⇒ Object
-
.get_attributes_for(namespace, crd_component_name, components, opts = {}) ⇒ Object
components can be: ‘all’ - print attributes for all components [‘cmp1’, ‘cmp2’, …] - print attributes for set of components ‘<cmp_name>’ - print attributes for single component opts can have keys: task_id format - format to print in (default is yaml).
-
.get_with_influx_data(namespace, assembly_name, opts = {}) ⇒ Object
TODO: this is a temporal solution to avoid breaking backward compatibility; will change this soon.
Instance Method Summary collapse
-
#initialize(namespace, name, crd_content) ⇒ CrdAssembly
constructor
A new instance of CrdAssembly.
- #to_hash ⇒ Object
Methods included from Utils::CrdHelper
Constructor Details
#initialize(namespace, name, crd_content) ⇒ CrdAssembly
Returns a new instance of CrdAssembly.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/state/crd_assembly.rb', line 10 def initialize(namespace, name, crd_content) @name = name @namespace = namespace @api_version = crd_content.apiVersion @kind = crd_content.kind @metadata = crd_content. # @crd_content = crd_content @references = crd_content.references @components = crd_content[:spec][:components] || [] # @component_objs = Component.create_from_kube_array(@components, self) end |
Instance Attribute Details
#component_objs ⇒ Object (readonly)
Returns the value of attribute component_objs.
7 8 9 |
# File 'lib/state/crd_assembly.rb', line 7 def component_objs @component_objs end |
#components ⇒ Object
Returns the value of attribute components.
8 9 10 |
# File 'lib/state/crd_assembly.rb', line 8 def components @components end |
#crd_content ⇒ Object (readonly)
Returns the value of attribute crd_content.
7 8 9 |
# File 'lib/state/crd_assembly.rb', line 7 def crd_content @crd_content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/state/crd_assembly.rb', line 7 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/state/crd_assembly.rb', line 7 def namespace @namespace end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
7 8 9 |
# File 'lib/state/crd_assembly.rb', line 7 def references @references end |
Class Method Details
.get(namespace, name, opts = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/state/crd_assembly.rb', line 22 def self.get(namespace, name, opts = {}) opts[:apiVersion] = ASSEMBLY_CRD_VERSION crd_assembly = ::DTK::CrdClient.get_kubeclient(opts).get_assembly(name, namespace) CrdAssembly.new(namespace, name, crd_assembly) end |
.get_attributes_for(namespace, crd_component_name, components, opts = {}) ⇒ Object
components can be:
'all' - print attributes for all components
['cmp1', 'cmp2', ...] - print attributes for set of components
'<cmp_name>' - print attributes for single component
opts can have keys:
task_id
format - format to print in (default is yaml)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/state/crd_assembly.rb', line 35 def self.get_attributes_for(namespace, crd_component_name, components, opts = {}) output = {} crd_component = get(namespace, crd_component_name, opts) crd_components = crd_component.components if components == 'all' crd_components.each do |kube_component| component_hash = kube_component.to_hash component_name = component_hash.keys.first component = Component.new(component_name, component_hash[component_name], crd_component, opts) output.merge!(component_name => component.attributes(opts)) end else components = [components] unless components.is_a?(Array) check_for_missing_components(crd_components, components) components.each do |component_name| matching_component = crd_components.find{ |cmp| cmp.to_hash.keys.first == component_name } component = Component.new(component_name, matching_component[component_name], crd_component, opts) output.merge!(component_name => component.attributes(opts)) end end output end |
.get_with_influx_data(namespace, assembly_name, opts = {}) ⇒ Object
TODO: this is a temporal solution to avoid breaking backward compatibility; will change this soon
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/state/crd_assembly.rb', line 63 def self.get_with_influx_data(namespace, assembly_name, opts = {}) assembly = get(namespace, assembly_name, opts) components_hash = {} assembly.components.each do |assembly_component| cmp_name = assembly_component.to_hash.keys.first components_hash[cmp_name] = assembly_component[cmp_name].to_hash end component_objs = Component.create_from_kube_array(assembly.components, assembly) component_objs.each do |component_obj| component_name = component_obj.name attr_type_info = component_obj.component_def.attribute_type_info attr_type_info.each do |attr_info| if attr_info.temporal attribute_name = attr_info.name influxdb = ::DTK::State::Component::Attribute::Influxdb.new(:attributes) influxdb_attribute = influxdb.get(namespace, component_name, assembly_name, attribute_name, opts) if valid_attribute = influxdb_attribute.first value = valid_attribute['_value'] if components_hash[component_name][:attributes][attribute_name].is_a?(String) components_hash[component_name][:attributes][attribute_name] = value else components_hash[component_name][:attributes][attribute_name][:value] = value end end end end end assembly.components = components_hash assembly end |
Instance Method Details
#to_hash ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/state/crd_assembly.rb', line 97 def to_hash { apiVersion: @api_version, kind: @kind, metadata: (@metadata), references: @references.to_hash, spec: { components: @components.to_hash } } end |