Class: K8y::Kubeconfig::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/k8y/kubeconfig/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, cluster:, namespace:, user:) ⇒ Context

Returns a new instance of Context.



20
21
22
23
24
25
# File 'lib/k8y/kubeconfig/context.rb', line 20

def initialize(name:, cluster:, namespace:, user:)
  @name = name
  @cluster = cluster
  @namespace = namespace
  @user = user
end

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster.



6
7
8
# File 'lib/k8y/kubeconfig/context.rb', line 6

def cluster
  @cluster
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/k8y/kubeconfig/context.rb', line 6

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



6
7
8
# File 'lib/k8y/kubeconfig/context.rb', line 6

def namespace
  @namespace
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/k8y/kubeconfig/context.rb', line 6

def user
  @user
end

Class Method Details

.from_hash(hash) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/k8y/kubeconfig/context.rb', line 8

def self.from_hash(hash)
  context = hash.fetch("context")
  new(
    name: hash.fetch("name"),
    cluster: context.fetch("cluster"),
    namespace: context.fetch("namespace", nil),
    user: context.fetch("user")
  )
rescue Psych::Exception, KeyError => e
  raise Error, e
end