Class: Keel::GCloud::Kubernetes::PodManager

Inherits:
Object
  • Object
show all
Defined in:
lib/keel/gcloud/kubernetes/pod_manager.rb

Overview

A class to represent the shared characteristics of a Kubernetes pod manager (eg. Deployment or Replication Controller)

Direct Known Subclasses

Deployment, ReplicationController

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ PodManager

Returns a new instance of PodManager.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 12

def initialize **params
  @containers = params[:containers]
  @name       = params[:name]
  @namespace  = params[:namespace]
  @uid        = params[:uid]

  @original   = params[:original]
  
  # don't send status back when updating the manager
  @original['metadata'].delete 'creationTimestamp'
  @original.delete 'status'
end

Instance Attribute Details

#containersObject

Returns the value of attribute containers.



10
11
12
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10

def containers
  @containers
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



10
11
12
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10

def namespace
  @namespace
end

#originalObject

Returns the value of attribute original.



10
11
12
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10

def original
  @original
end

#uidObject

Returns the value of attribute uid.



10
11
12
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10

def uid
  @uid
end

Class Method Details

.from_yaml(yaml) ⇒ Array<ReplicationController>

Parses the returned YAML into objects of the ReplicationController class.

Parameters:

  • yaml (Hash)

    the parsed result of the API call

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 31

def self.from_yaml yaml
  yaml['items'].map do |item|
    params = {
      containers: item['spec']['template']['spec']['containers'],
      name:       item['metadata']['name'],
      namespace:  item['metadata']['namespace'],
      original:   item,
      uid:        item['metadata']['uid'],
    }
    self.new params
  end
end

.replace(file) ⇒ Boolean

Replaces the controller’s specifications with a new one.

Parameters:

  • file (File)

    the new specifications file

Returns:

  • (Boolean)

    whether the call succeeded or not



50
51
52
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 50

def self.replace file
  Cli.new.system_call "kubectl replace -f #{file}"
end

Instance Method Details

#to_file(filename) ⇒ Boolean

Writes the current specifications to a file.

Parameters:

  • filename (String)

    the name of the file to write to

Returns:

  • (Boolean)

    result of the operation



69
70
71
72
73
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 69

def to_file filename
  File.open(filename, 'w') do |io|
    io.write self.to_yaml
  end
end

#to_yamlString

Get the YAML representation of the controller.

Returns:

  • (String)

    the YAML format



59
60
61
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 59

def to_yaml
  self.original.to_yaml
end

#updateObject

Updates the specifications of a controller on Kubernetes with the latest specs.

(see #to_file) (see #replace)



82
83
84
85
86
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 82

def update
  tmp_file = Rails.root.join('tmp', 'deployment-rc.yml')
  self.to_file tmp_file
  self.class.replace tmp_file
end