Class: Keel::GCloud::Kubernetes::Pod
- Inherits:
-
Object
- Object
- Keel::GCloud::Kubernetes::Pod
- Defined in:
- lib/keel/gcloud/kubernetes/pod.rb
Overview
A class to represent a Kubernetes Pod. It is a simplified view of what Kubernetes returns with only the necessary information required to perform the operations needed.
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#cli ⇒ Object
Returns the value of attribute cli.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#status ⇒ Object
Returns the value of attribute status.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
-
.fetch_all(env, selector) ⇒ Hash
Fetches all the pods from Kubernetes.
-
.from_yaml(yaml) ⇒ Array<Pod>
Parses the returned YAML into objects of the Pod class.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Deletes the pod.
-
#initialize(**params) ⇒ Pod
constructor
A new instance of Pod.
-
#logs(tail = nil) ⇒ Boolean
Fetches the logs for the pod.
-
#running? ⇒ Boolean
Checks if the namespace is running by comparing the status attribute.
Constructor Details
#initialize(**params) ⇒ Pod
Returns a new instance of Pod.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 13 def initialize **params @app = params[:app] @name = params[:name] @namespace = params[:namespace] @status = params[:status] @uid = params[:uid] @cli = Cli.new @prompter = Prompter.new end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def app @app end |
#cli ⇒ Object
Returns the value of attribute cli.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def cli @cli end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def namespace @namespace end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def status @status end |
#uid ⇒ Object
Returns the value of attribute uid.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 11 def uid @uid end |
Class Method Details
.fetch_all(env, selector) ⇒ Hash
Fetches all the pods from Kubernetes.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 51 def self.fetch_all env, selector if selector.is_a? Hash selector = selector.map{|k,v| "#{k}=#{v}"}.join(',') else selector = "app=#{selector}" end command = "kubectl get po --namespace=#{env} -l #{selector} -o yaml" rcs_yaml = YAML.load Cli.new.execute(command) return false unless rcs_yaml self.from_yaml rcs_yaml end |
.from_yaml(yaml) ⇒ Array<Pod>
Parses the returned YAML into objects of the Pod class.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 30 def self.from_yaml yaml yaml['items'].map do |item| params = { app: item['metadata']['labels']['app'], name: item['metadata']['name'], namespace: item['metadata']['namespace'], status: item['status']['phase'], uid: item['metadata']['uid'], } self.new params end end |
Instance Method Details
#delete ⇒ Boolean
Deletes the pod.
79 80 81 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 79 def delete @cli.system_call "kubectl delete po #{self.name} --namespace=#{self.namespace}" end |
#logs(tail = nil) ⇒ Boolean
Fetches the logs for the pod. If the param tail is set to true, it tails the logs.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 90 def logs tail=nil f = tail ? '-f ' : '' if tail @prompter.print 'Fetching logs...' @prompter.print 'Use Ctrl-C to stop' end @cli.system_call "kubectl logs #{f}#{self.name} --namespace=#{self.namespace} -c=#{self.app}" end |
#running? ⇒ Boolean
Checks if the namespace is running by comparing the status attribute.
70 71 72 |
# File 'lib/keel/gcloud/kubernetes/pod.rb', line 70 def running? 'Running' == self.status end |