Class: Keel::GCloud::Kubernetes::Namespace
- Inherits:
-
Object
- Object
- Keel::GCloud::Kubernetes::Namespace
- Defined in:
- lib/keel/gcloud/kubernetes/namespace.rb
Overview
A class to represent a Kubernetes Namespace. It is a simplified view of what Kubernetes returns with only the necessary information required to perform the operations needed.
Instance Attribute Summary collapse
-
#cli ⇒ Object
Returns the value of attribute cli.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
-
.fetch_all ⇒ Hash
Fetches all the namespaces from Kubernetes.
-
.from_yaml(yaml) ⇒ Array<Namespace>
Parses the returned YAML into objects of the Namespace class.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the namespace is active by comparing the status attribute.
-
#initialize(**params) ⇒ Namespace
constructor
A new instance of Namespace.
Constructor Details
Instance Attribute Details
#cli ⇒ Object
Returns the value of attribute cli.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11 def cli @cli end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11 def status @status end |
#uid ⇒ Object
Returns the value of attribute uid.
11 12 13 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11 def uid @uid end |
Class Method Details
.fetch_all ⇒ Hash
Fetches all the namespaces from Kubernetes.
44 45 46 47 48 49 50 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 44 def self.fetch_all command = 'kubectl get namespaces -o yaml' namespaces_yaml = YAML.load Cli.new.execute(command) return false unless namespaces_yaml self.from_yaml namespaces_yaml end |
.from_yaml(yaml) ⇒ Array<Namespace>
Parses the returned YAML into objects of the Namespace class.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 27 def self.from_yaml yaml yaml['items'].map do |item| params = { name: item['metadata']['name'], status: item['status']['phase'], uid: item['metadata']['uid'], } self.new params end end |
Instance Method Details
#active? ⇒ Boolean
Checks if the namespace is active by comparing the status attribute.
57 58 59 |
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 57 def active? 'Active' == self.status end |