Class: Keel::GCloud::Kubernetes::PodManager
- Inherits:
-
Object
- Object
- Keel::GCloud::Kubernetes::PodManager
- 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
Instance Attribute Summary collapse
-
#containers ⇒ Object
Returns the value of attribute containers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#original ⇒ Object
Returns the value of attribute original.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
-
.from_yaml(yaml) ⇒ Array<ReplicationController>
Parses the returned YAML into objects of the ReplicationController class.
-
.replace(file) ⇒ Boolean
Replaces the controller’s specifications with a new one.
Instance Method Summary collapse
-
#initialize(**params) ⇒ PodManager
constructor
A new instance of PodManager.
-
#to_file(filename) ⇒ Boolean
Writes the current specifications to a file.
-
#to_yaml ⇒ String
Get the YAML representation of the controller.
-
#update ⇒ Object
Updates the specifications of a controller on Kubernetes with the latest specs.
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
#containers ⇒ Object
Returns the value of attribute containers.
10 11 12 |
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10 def containers @containers end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10 def namespace @namespace end |
#original ⇒ Object
Returns the value of attribute original.
10 11 12 |
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 10 def original @original end |
#uid ⇒ Object
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.
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.
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.
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_yaml ⇒ String
Get the YAML representation of the controller.
59 60 61 |
# File 'lib/keel/gcloud/kubernetes/pod_manager.rb', line 59 def to_yaml self.original.to_yaml end |
#update ⇒ Object
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 |