Class: DTK::State::CrdAssembly

Inherits:
Object
  • Object
show all
Defined in:
lib/state/crd_assembly.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, name, crd_content) ⇒ CrdAssembly

Returns a new instance of CrdAssembly.



5
6
7
8
9
10
11
# File 'lib/state/crd_assembly.rb', line 5

def initialize(namespace, name, crd_content)
  @name        = name
  @namespace   = namespace
  @crd_content = crd_content
  @references  = crd_content.references
  @components  = crd_content[:spec][:components]
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



3
4
5
# File 'lib/state/crd_assembly.rb', line 3

def components
  @components
end

#crd_contentObject (readonly)

Returns the value of attribute crd_content.



3
4
5
# File 'lib/state/crd_assembly.rb', line 3

def crd_content
  @crd_content
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/state/crd_assembly.rb', line 3

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/state/crd_assembly.rb', line 3

def namespace
  @namespace
end

#referencesObject (readonly)

Returns the value of attribute references.



3
4
5
# File 'lib/state/crd_assembly.rb', line 3

def references
  @references
end

Class Method Details

.get(namespace, name, opts = {}) ⇒ Object



13
14
15
16
17
# File 'lib/state/crd_assembly.rb', line 13

def self.get(namespace, name, opts = {})
  # crd_component = ::DTK::CrdClient.instance.kubeclient.get_component(name, namespace)
  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)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/state/crd_assembly.rb', line 26

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