Class: KubeDeployTools::KubernetesResource
- Defined in:
- lib/kube_deploy_tools/kubernetes_resource.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Class Method Summary collapse
Instance Method Summary collapse
- #create_definition_tempfile ⇒ Object
- #file ⇒ Object
- #filepath ⇒ Object
-
#initialize(filepath:, definition:, kubectl:) ⇒ KubernetesResource
constructor
A new instance of KubernetesResource.
- #sync ⇒ Object
Constructor Details
#initialize(filepath:, definition:, kubectl:) ⇒ KubernetesResource
Returns a new instance of KubernetesResource.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 26 def initialize(filepath:, definition:, kubectl:) @filepath = filepath @definition = definition @kubectl = kubectl @namespace = definition.dig('metadata', 'namespace') @name = definition.dig('metadata', 'name') @kind = definition['kind'] @annotations = definition.dig('metadata', 'annotations') end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
5 6 7 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 5 def annotations @annotations end |
#definition ⇒ Object
Returns the value of attribute definition.
5 6 7 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 5 def definition @definition end |
#kind ⇒ Object
Returns the value of attribute kind.
5 6 7 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 5 def kind @kind end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 5 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 5 def namespace @namespace end |
Class Method Details
.build(filepath: nil, definition:, kubectl:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 11 def self.build(filepath: nil, definition:, kubectl:) opts = { filepath: filepath, definition: definition, kubectl: kubectl } # Find the corresponding class for the Kubernetes resource, if available if ["Deployment"].include?(definition["kind"]) klass = KubeDeployTools.const_get(definition["kind"]) klass.new(**opts) else # Otherwise initialize here if no class exists for this Kubernetes # resource kind inst = new(**opts) inst.kind = definition["kind"] inst end end |
Instance Method Details
#create_definition_tempfile ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 45 def create_definition_tempfile file = Tempfile.new(["#{@namespace}-#{@kind}-#{@name}", ".yaml"]) file.write(YAML.dump(@definition)) file ensure file&.close end |
#file ⇒ Object
41 42 43 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 41 def file @file ||= create_definition_tempfile end |
#filepath ⇒ Object
37 38 39 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 37 def filepath @filepath ||= file.path end |
#sync ⇒ Object
53 54 55 |
# File 'lib/kube_deploy_tools/kubernetes_resource.rb', line 53 def sync # unimplemented end |