class KubeDeployTools::KubernetesResource

Attributes

annotations[RW]
definition[RW]
kind[RW]
name[RW]
namespace[RW]

Public Class Methods

build(filepath: nil, definition:, kubectl:) click to toggle source
# 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
new(filepath:, definition:, kubectl:) click to toggle source
# 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

Public Instance Methods

create_definition_tempfile() click to toggle source
# 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() click to toggle source
# File lib/kube_deploy_tools/kubernetes_resource.rb, line 41
def file
  @file ||= create_definition_tempfile
end
filepath() click to toggle source
# File lib/kube_deploy_tools/kubernetes_resource.rb, line 37
def filepath
  @filepath ||= file.path
end
sync() click to toggle source
# File lib/kube_deploy_tools/kubernetes_resource.rb, line 53
def sync
  # unimplemented
end