Class: Keel::GCloud::Kubernetes::Namespace

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Namespace

Returns a new instance of Namespace.



13
14
15
16
17
18
19
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 13

def initialize **params
  @name   = params[:name]
  @status = params[:status]
  @uid    = params[:uid]

  @cli    = Cli.new
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



11
12
13
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11

def cli
  @cli
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11

def name
  @name
end

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 11

def status
  @status
end

#uidObject

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_allHash

Fetches all the namespaces from Kubernetes.

Returns:

  • (Hash)

    the parsed result of the API call



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.

Parameters:

  • yaml (Hash)

    the parsed result of the API call

Returns:

  • (Array<Namespace>)

    an array of Namespace objects



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.

Returns:

  • (Boolean)


57
58
59
# File 'lib/keel/gcloud/kubernetes/namespace.rb', line 57

def active?
  'Active' == self.status
end