Class: Porkadot::Assets::Kubelet

Inherits:
Object
  • Object
show all
Includes:
Porkadot::Assets
Defined in:
lib/porkadot/assets/kubelet.rb

Constant Summary collapse

TEMPLATE_DIR =
File.join(File.dirname(__FILE__), "kubelet")

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Porkadot::Assets

#render_erb, #render_secrets_erb

Constructor Details

#initialize(config) ⇒ Kubelet

Returns a new instance of Kubelet.



85
86
87
88
89
90
# File 'lib/porkadot/assets/kubelet.rb', line 85

def initialize config
  @config = config
  @logger = config.logger
  @global_config = config.config
  @certs = Porkadot::Assets::Certs::Kubernetes.new(global_config)
end

Instance Attribute Details

#certsObject (readonly)

Returns the value of attribute certs.



83
84
85
# File 'lib/porkadot/assets/kubelet.rb', line 83

def certs
  @certs
end

#configObject (readonly)

Returns the value of attribute config.



81
82
83
# File 'lib/porkadot/assets/kubelet.rb', line 81

def config
  @config
end

#global_configObject (readonly)

Returns the value of attribute global_config.



80
81
82
# File 'lib/porkadot/assets/kubelet.rb', line 80

def global_config
  @global_config
end

#loggerObject (readonly)

Returns the value of attribute logger.



82
83
84
# File 'lib/porkadot/assets/kubelet.rb', line 82

def logger
  @logger
end

Instance Method Details

#bootstrap_cert(refresh = false) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/porkadot/assets/kubelet.rb', line 122

def bootstrap_cert(refresh=false)
  return @bootstrap_cert if defined?(@bootstrap_cert)
  if File.file?(config.bootstrap_cert_path) and !refresh
    self.logger.debug("--> Bootstrap cert already exists, skipping: #{config.bootstrap_cert_path}")
    @bootstrap_cert = OpenSSL::X509::Certificate.new(File.read(config.bootstrap_cert_path))
  else
    @bootstrap_cert = certs._client_cert(
      config.bootstrap_cert_path,
      "/O=porkadot:node-bootstrappers/CN=node-bootstrapper:#{config.name}",
      self.bootstrap_key,
      self.certs.ca_cert(false),
      self.certs.ca_key
    )
  end
  return @bootstrap_cert
end

#bootstrap_keyObject



117
118
119
120
# File 'lib/porkadot/assets/kubelet.rb', line 117

def bootstrap_key
  @bootstrap_key ||= certs.private_key(config.bootstrap_key_path)
  return @bootstrap_key
end

#renderObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/porkadot/assets/kubelet.rb', line 92

def render
  logger.info "--> Rendering #{config.name} node"
  unless File.directory?(config.target_path)
    FileUtils.mkdir_p(config.target_path)
  end
  unless File.directory?(config.target_secrets_path)
    FileUtils.mkdir_p(config.target_secrets_path)
  end
  ca_data = certs.ca_cert.to_pem
  ca_data = Base64.strict_encode64(ca_data)

  render_erb 'bootstrap-kubelet.conf', ca_data: ca_data
  render_bootstrap_certs
  render_erb 'config.yaml'
  render_erb 'kubelet.service'
  render_erb 'initiatorname.iscsi'
  render_erb 'metadata.json'
end

#render_bootstrap_certsObject



111
112
113
114
115
# File 'lib/porkadot/assets/kubelet.rb', line 111

def render_bootstrap_certs
  logger.info "----> bootstrap certs"
  self.bootstrap_key
  self.bootstrap_cert(true)
end