dtk_crd_parser 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c8ceb73c7c7afa1da34bde108bf15f50935e219e
4
- data.tar.gz: 3f96f18f547b482fc57ea9367b37d949632112bb
2
+ SHA256:
3
+ metadata.gz: 7db0223829bb7c53f309e52c808582992490abed7964a65facdc70339e60cb79
4
+ data.tar.gz: a492d85e80d9fd68a1680961d6482356b5d882d5caf18e58e76066ecd78f25f5
5
5
  SHA512:
6
- metadata.gz: 42c0636f99184b6e3630f7cfd511268674cb00adec2d6ab96d2937a4332a707ee840b5eb25f58fe0bd7e96009917c18d93e81fbe871190e2285d180aa553fae6
7
- data.tar.gz: d99c3a00a40dd812abd733dd1cad49357a6b0855e0765cd4b89eb637b720b5f066f7836b73d4317284db313a7ec137551f25943137cd74240231846d86438659
6
+ metadata.gz: 30e17286423da409bbedc746db71e2ca00d34145d29596fdedc9247ee1e19d463115b0d3050634b59bda304b1c642c30f8cac6a053caf99159a701fdc5ec4e2b
7
+ data.tar.gz: 771b3eaf135045ddb093221eef64664933967464d708fce73886fe5d418fb5adcc7df4e64d38edc1813d764b660116872f4ff4c2d9b4ef21fd5ad7c027eed241
data/lib/crd_parser.rb CHANGED
@@ -4,12 +4,25 @@ module DTK
4
4
 
5
5
  require_relative('crd_parser/component')
6
6
  require_relative('crd_parser/component_def')
7
-
7
+ require_relative('crd_parser/action')
8
+ require_relative('crd_parser/error')
9
+
8
10
  def self.parse_crd_to_component(client, component_instance, component_name)
9
11
  #component instance has a name and a namespace {name: xxx, namespace: yyy}
10
12
  #client is kube client
11
13
  #component name is, for example, network-aws::vpc[vpc1]
12
14
  Component.create_from_kube(client, component_instance, component_name)
13
15
  end
16
+
17
+ def self.parse_crd_to_action(client, component_instance, action_instance)
18
+ #component instance has a name and a namespace {name: xxx, namespace: yyy}
19
+ #client is kube client
20
+ #action instance, for example, {name: xxx, namespace: xxx, id: xxx}
21
+ Action.create_from_kube(client, component_instance, action_instance)
22
+ end
23
+
24
+ def self.parse_crd_to_executable_action(client, component_instance, component_name)
25
+ Component.create_from_kube(client, component_instance, component_name)
26
+ end
14
27
  end
15
28
  end
@@ -0,0 +1,40 @@
1
+ module DTK::CrdParser
2
+ class Action < BaseClass
3
+
4
+ def initialize(name, id, component)
5
+ @name = name #action name, for example: create node group members
6
+ @component = component #this will point to the corresponding component object, example: ec2::node-group[ng]
7
+ @id = id #action subtask id
8
+ end
9
+
10
+ def self.create_from_kube(client, component_instance, action_instance)
11
+ action_obj = client.get_action(action_instance[:name], action_instance[:namespace])
12
+ @actionExists = false
13
+ action = find_action(action_instance[:id], action_obj[:spec][:action])
14
+ component_name = action[:component]
15
+ component = Component.create_from_kube(client, component_instance, component_name)
16
+ Action.new(action[:name], action[:id], component)
17
+ end
18
+
19
+ protected
20
+
21
+ @action = nil
22
+ @actionExists = false
23
+ def self.find_action(id, actionObject)
24
+ return @action if @actionExists
25
+ iterator = 0
26
+ while (!@actionExists && iterator < actionObject[:subtasks].length)
27
+ @action = actionObject[:subtasks][iterator]
28
+ if @action.id.to_s == id.to_s
29
+ @actionExists = true
30
+ return @action
31
+ elsif @action[:subtasks]
32
+ return self.find_action(id, @action)
33
+ end
34
+ iterator+=1
35
+ end
36
+ end
37
+ attr_reader :name, :component, :id
38
+
39
+ end
40
+ end
@@ -4,6 +4,11 @@ module DTK::CrdParser
4
4
  module ClassAndInstanceMixin
5
5
  # Helper functions want to have available in all classes
6
6
 
7
+ def fail_if_nil(value, property_name)
8
+ fail Error::Usage, "Property #{property_name} should not be nil") unless value
9
+ value
10
+ end
11
+
7
12
  def fail_if_not_type(object, type)
8
13
  if object.kind_of?(type)
9
14
  object
@@ -1,26 +1,22 @@
1
1
  module DTK::CrdParser
2
2
  class Component < BaseClass
3
3
  require_relative('component/attribute')
4
-
5
- attr_reader :name, :component_def, :attributes
4
+ require_relative('error')
6
5
 
7
6
  MODE_DEFAULT = :component_instance
8
7
  def initialize(name, component_def, attributes)
9
- @name = name
10
- @component_def = component_def # this wil point to the corresponding component def
11
- @attributes = attributes # array that has an Attribute object for each attribute; these are name-value pairs
8
+ @name = fail_if_nil(name, 'name')
9
+ @component_def = fail_if_nil(component_def, 'component_def') # this wil point to the corresponding component def
10
+ @attributes = attributes || [] # array that has an Attribute object for each attribute; these are name-value pairs
12
11
  end
13
12
 
14
13
  def self.create_from_kube(client, component_instance, component_name)
15
- component_name.gsub!('_', '-')
16
14
  component_instance_obj = client.get_component(component_instance[:name], component_instance[:namespace])
17
15
  component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name)
18
16
  component_attributes = getComponentAttributes(component_name, component_instance_obj[:spec][:components])
19
17
  attributes = []
20
- if component_attributes
21
- component_attributes.to_hash.each do |attribute_name, attribute_value|
22
- attributes.push Attribute.create_from_kube(attribute_name, attribute_value)
23
- end
18
+ (component_attributes || []).to_hash.each do |attribute_name, attribute_value|
19
+ attributes.push Attribute.create_from_kube(attribute_name, attribute_value)
24
20
  end
25
21
  Component.new(component_name, component_def, attributes)
26
22
  end
@@ -28,6 +24,7 @@ module DTK::CrdParser
28
24
  protected
29
25
 
30
26
  def self.getComponentAttributes(fullComponentName, components)
27
+ fullComponentName.gsub!('_', '-')
31
28
  component = components.each do |component|
32
29
  componentObj = component[fullComponentName]
33
30
  if(componentObj && componentObj.is_a?(Kubeclient::Resource))
@@ -37,6 +34,6 @@ module DTK::CrdParser
37
34
  return nil
38
35
  end
39
36
 
40
-
37
+ attr_reader :name, :component_def, :attributes
41
38
  end
42
39
  end
@@ -1,18 +1,19 @@
1
1
  module DTK::CrdParser
2
2
  class Component
3
3
  class Attribute < BaseClass
4
-
5
- attr_reader :name, :value
6
-
7
4
  def initialize(name, value)
8
- @name = name
9
- @value = value
5
+ @name = fail_if_nil(name, 'Attribute.name')
6
+ @value = fail_if_nil(value, 'Attribute.value')
10
7
  end
11
8
 
12
9
  def self.create_from_kube(attribute_name, attribute_value)
13
10
  Attribute.new(attribute_name, attribute_value)
14
11
  end
15
12
 
13
+ protected
14
+
15
+ attr_reader :name, :value
16
+
16
17
  end
17
18
  end
18
19
  end
@@ -1,21 +1,17 @@
1
1
  module DTK::CrdParser
2
2
  class ComponentDef < BaseClass
3
3
  require_relative('component_def/attribute_type_info')
4
-
5
- attr_reader :name, :namespace, :resource_version, :attribute_type_info, :bash_script, :entrypoint, :type
4
+ require_relative('error')
6
5
 
7
6
  MODE_DEFAULT = :component_instance
8
7
 
9
- def initialize(metadata, componentDefAction, componentDefAttributes)
10
- @name = metadata[:name]
11
- @namespace = metadata[:namespace]
12
- @resource_version = metadata[:resourceVersion]
13
-
14
- @bash_script = componentDefAction[:bash_script]
15
- @entrypoint = componentDefAction[:entrypoint]
16
- @type = componentDefAction[:type]
8
+ def initialize(metadata, componentDefActions, componentDefAttributes)
9
+ @name = fail_if_nil(metadata[:name], 'metadata[:name]')
10
+ @namespace = fail_if_nil(metadata[:namespace], 'metadata[:namespace]')
11
+ @resource_version = fail_if_nil(metadata[:resourceVersion], 'metadata[:resourceVersion]')
17
12
 
18
- @attribute_type_info = componentDefAttributes
13
+ @executable_actions = componentDefActions || []
14
+ @attribute_type_info = componentDefAttributes || []
19
15
  end
20
16
 
21
17
  def self.create_from_kube(client, component_instance, component_def_name)
@@ -24,15 +20,17 @@ module DTK::CrdParser
24
20
 
25
21
  componentDef = client.get_componentdef("#{destructured_component[:moduleName]}-#{destructured_component[:componentName]}", module_ref[:namespace])
26
22
 
27
- name = componentDef[:metadata][:name]
28
- namespace = componentDef[:metadata][:namespace]
29
- resourceVersion = componentDef[:metadata][:resourceVersion]
23
+ componentMetadata = self.metadata(componentDef)
24
+
25
+ name = componentMetadata[:name]
26
+ namespace = componentMetadata[:namespace]
27
+ resourceVersion = componentMetadata[:resourceVersion]
30
28
 
31
- componentDefSpec = componentDef[:spec]
32
- componentDefAction = componentDefSpec[:actions][destructured_component[:action].to_sym]
29
+ componentDefSpec = componentDef[:spec] || {}
30
+ componentDefAction = componentDefSpec[:actions][destructured_component[:action].to_sym] if componentDefSpec[:actions]
33
31
  componentDefAttributes = []
34
32
 
35
- componentDefSpec[:attributes].each do |attribute|
33
+ (componentDefSpec[:attributes] || []).each do |attribute|
36
34
  componentDefAttributes.push AttributeTypeInfo.resolveAttr(attribute)
37
35
  end
38
36
 
@@ -80,5 +78,13 @@ module DTK::CrdParser
80
78
  action: action
81
79
  }
82
80
  end
81
+
82
+ protected
83
+
84
+ attr_reader :name, :namespace, :resource_version, :attribute_type_info, :bash_script, :entrypoint, :type
85
+
86
+ def self.metadata(componentDef)
87
+ componentDef[:metadata]
88
+ end
83
89
  end
84
90
  end
@@ -1,12 +1,9 @@
1
1
  module DTK::CrdParser
2
2
  class ComponentDef
3
3
  class AttributeTypeInfo < BaseClass
4
-
5
- attr_reader :name, :type, :required, :dynamic
6
-
7
4
  def initialize(params)
8
- @name = params[:name]
9
- @type = params[:type]
5
+ @name = fail_if_nil(params[:name], 'AttributeTypeInfo.name')
6
+ @type = fail_if_nil(params[:type], 'AttributeTypeInfo.type')
10
7
  @required = params[:required] || false
11
8
  @dynamic = params[:dynamic] || false
12
9
  end
@@ -15,6 +12,9 @@ module DTK::CrdParser
15
12
  AttributeTypeInfo.new(attribute)
16
13
  end
17
14
 
15
+ protected
16
+
17
+ attr_reader :name
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,5 @@
1
+ module DTK::CrdParser
2
+ class Error < ::StandardError
3
+ require_relative('error/usage')
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module DTK::CrdParser
2
+ class Error
3
+ class Usage < self
4
+ end
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk_crd_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - DTK
@@ -17,12 +17,15 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/crd_parser.rb
20
+ - lib/crd_parser/action.rb
20
21
  - lib/crd_parser/base_class.rb
21
22
  - lib/crd_parser/base_class/helper_mixins.rb
22
23
  - lib/crd_parser/component.rb
23
24
  - lib/crd_parser/component/attribute.rb
24
25
  - lib/crd_parser/component_def.rb
25
26
  - lib/crd_parser/component_def/attribute_type_info.rb
27
+ - lib/crd_parser/error.rb
28
+ - lib/crd_parser/error/usage.rb
26
29
  homepage: https://rubygems.org/gems/dtk_crd_parser
27
30
  licenses:
28
31
  - MIT
@@ -42,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
45
  - !ruby/object:Gem::Version
43
46
  version: '0'
44
47
  requirements: []
45
- rubyforge_project:
46
- rubygems_version: 2.4.5.4
48
+ rubygems_version: 3.0.3
47
49
  signing_key:
48
50
  specification_version: 4
49
51
  summary: Parse kubernetes DTK crd to ruby in memory object!