Class: Kuby::GKE::Kubeconfig

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/gke/kubeconfig.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, cluster_name:, zone:, endpoint:, ca_cert:) ⇒ Kubeconfig

Returns a new instance of Kubeconfig.



18
19
20
21
22
23
24
# File 'lib/kuby/gke/kubeconfig.rb', line 18

def initialize(project_id:, cluster_name:, zone:, endpoint:, ca_cert:)
  @project_id = project_id
  @cluster_name = cluster_name
  @zone = zone
  @endpoint = endpoint
  @ca_cert = ca_cert
end

Instance Attribute Details

#ca_certObject (readonly)

Returns the value of attribute ca_cert.



6
7
8
# File 'lib/kuby/gke/kubeconfig.rb', line 6

def ca_cert
  @ca_cert
end

#cluster_nameObject (readonly)

Returns the value of attribute cluster_name.



6
7
8
# File 'lib/kuby/gke/kubeconfig.rb', line 6

def cluster_name
  @cluster_name
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/kuby/gke/kubeconfig.rb', line 6

def endpoint
  @endpoint
end

#project_idObject (readonly)

Returns the value of attribute project_id.



6
7
8
# File 'lib/kuby/gke/kubeconfig.rb', line 6

def project_id
  @project_id
end

#zoneObject (readonly)

Returns the value of attribute zone.



6
7
8
# File 'lib/kuby/gke/kubeconfig.rb', line 6

def zone
  @zone
end

Class Method Details

.from(config:, cluster_def:) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/kuby/gke/kubeconfig.rb', line 8

def self.from(config:, cluster_def:)
  new(
    project_id: config.project_id,
    cluster_name: config.cluster_name,
    zone: config.zone,
    endpoint: cluster_def['endpoint'],
    ca_cert: cluster_def['master_auth']['cluster_ca_certificate']
  )
end

Instance Method Details

#generateObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kuby/gke/kubeconfig.rb', line 26

def generate
  {
    "apiVersion" => "v1",
    "kind" => "Config",
    "clusters" => clusters,
    "contexts" => contexts,
    "current-context" => id_triple,
    "preferences" => {},
    "users" => users
  }
end