class Kbt::Deployment

Attributes

containers[R]
labels[R]
name[R]
replicas[R]
template[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/kbt/deployment.rb, line 4
def initialize(args = {})
  @template = args.fetch(:template)
  @name = args.fetch(:name)
  @labels = args.fetch(:labels)
  @containers = args.fetch(:containers)
  @replicas = args[:replicas] || 1
end

Public Instance Methods

to_h() click to toggle source
# File lib/kbt/deployment.rb, line 12
def to_h
  Fusu::Hash.deep_merge(
    template.value,
    overrides
  )
end

Private Instance Methods

overrides() click to toggle source
# File lib/kbt/deployment.rb, line 21
def overrides
  case version
  when 'apps/v1', 'apps/v1beta2'
    v1
  when 'extensions/v1beta1', 'apps/v1beta1'
    v1beta1
  else
    raise 'version not recognised'
  end
end
v1() click to toggle source
# File lib/kbt/deployment.rb, line 36
def v1
  {
    "metadata" => {
      "name" => name,
      "labels" => labels
    },
    "spec" => {
      'replicas' => replicas,
      'selector' => {
        'matchLabels' => labels
      },
      'template' => template
    }
  }
end
v1beta1() click to toggle source
# File lib/kbt/deployment.rb, line 61
def v1beta1
  {
    "metadata" => {
      "name" => name,
      "labels" => labels
    },
    "spec" => {
      'replicas' => replicas,
      'template' => template
    }
  }
end
version() click to toggle source
# File lib/kbt/deployment.rb, line 32
def version
  template.value['apiVersion']
end