Class: Porkadot::Configs::Certs::Kubernetes

Inherits:
Object
  • Object
show all
Includes:
Porkadot::Configs::CertsUtils
Defined in:
lib/porkadot/configs/certs/k8s.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Porkadot::Configs::CertsUtils

#certs_root_dir, #ipaddr?

Constructor Details

#initialize(config) ⇒ Kubernetes

Returns a new instance of Kubernetes.



8
9
10
11
# File 'lib/porkadot/configs/certs/k8s.rb', line 8

def initialize config
  @config = config
  @logger = config.logger
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/porkadot/configs/certs/k8s.rb', line 5

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/porkadot/configs/certs/k8s.rb', line 6

def logger
  @logger
end

Instance Method Details

#additional_sansObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/porkadot/configs/certs/k8s.rb', line 13

def additional_sans
  dns_names = []
  ips = []
  if self.config.k8s.control_plane_endpoint
    host = self.config.k8s.control_plane_endpoint.split(':')[0]
    self.ipaddr?(host) ? ips << host : dns_names << host
  end
  self.config.nodes.each do |_, node|
    k = node.name
    v = node
    next unless v.labels && v.labels.include?(Porkadot::K8S_MASTER_LABEL)
    self.ipaddr?(k) ? ips << k : dns_names << k
    if v.hostname
      self.ipaddr?(v.hostname) ? ips << v.hostname : dns_names << v.hostname
    end
  end

  sans = dns_names.map {|v| "DNS:#{v}"} + ips.map {|v| "IP:#{v}"}
  default_sans = %W(
    DNS:kubernetes
    DNS:kubernetes.default
    DNS:kubernetes.default.svc
    DNS:kubernetes.default.svc.#{self.config.k8s.networking.dns_domain}
    DNS:porkadot-kubernetes
    DNS:porkadot-kubernetes.kube-system
    DNS:porkadot-kubernetes.kube-system.svc
    DNS:porkadot-kubernetes-latest
    DNS:porkadot-kubernetes-latest.kube-system
    DNS:porkadot-kubernetes-latest.kube-system.svc
    DNS:localhost
    IP:#{self.config.k8s.networking.kubernetes_ip}
    IP:127.0.0.1
  )
  return default_sans + sans.uniq
end

#admin_cert_pathObject Also known as: client_cert_path



82
83
84
# File 'lib/porkadot/configs/certs/k8s.rb', line 82

def admin_cert_path
  File.join(self.target_dir, 'admin.crt')
end

#admin_key_pathObject Also known as: client_key_path



77
78
79
# File 'lib/porkadot/configs/certs/k8s.rb', line 77

def admin_key_path
  File.join(self.target_dir, 'admin.key')
end

#apiserver_cert_pathObject



65
66
67
# File 'lib/porkadot/configs/certs/k8s.rb', line 65

def apiserver_cert_path
  File.join(self.target_dir, 'apiserver.crt')
end

#apiserver_key_pathObject



61
62
63
# File 'lib/porkadot/configs/certs/k8s.rb', line 61

def apiserver_key_path
  File.join(self.target_dir, 'apiserver.key')
end

#ca_cert_pathObject



57
58
59
# File 'lib/porkadot/configs/certs/k8s.rb', line 57

def ca_cert_path
  File.join(self.target_dir, 'ca.crt')
end

#ca_key_pathObject



53
54
55
# File 'lib/porkadot/configs/certs/k8s.rb', line 53

def ca_key_path
  File.join(self.target_dir, 'ca.key')
end

#kubelet_client_cert_pathObject



73
74
75
# File 'lib/porkadot/configs/certs/k8s.rb', line 73

def kubelet_client_cert_path
  File.join(self.target_dir, 'kubelet-client.crt')
end

#kubelet_client_key_pathObject



69
70
71
# File 'lib/porkadot/configs/certs/k8s.rb', line 69

def kubelet_client_key_path
  File.join(self.target_dir, 'kubelet-client.key')
end

#sa_private_key_pathObject



87
88
89
# File 'lib/porkadot/configs/certs/k8s.rb', line 87

def sa_private_key_path
  File.join(self.target_dir, 'sa.key')
end

#sa_public_key_pathObject



91
92
93
# File 'lib/porkadot/configs/certs/k8s.rb', line 91

def sa_public_key_path
  File.join(self.target_dir, 'sa.pub')
end

#target_dirObject



49
50
51
# File 'lib/porkadot/configs/certs/k8s.rb', line 49

def target_dir
  File.join(self.certs_root_dir, 'kubernetes')
end