Class: Porkadot::Install::Bootstrap

Inherits:
Object
  • Object
show all
Includes:
SSHKit::DSL
Defined in:
lib/porkadot/install/bootstrap.rb

Constant Summary collapse

KUBE_TEMP =
File.join(Porkadot::Install::KUBE_TEMP, 'bootstrap')
KUBE_SECRETS_TEMP =
File.join(Porkadot::Install::KUBE_TEMP, '.bootstrap')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_config) ⇒ Bootstrap

Returns a new instance of Bootstrap.



11
12
13
14
15
16
# File 'lib/porkadot/install/bootstrap.rb', line 11

def initialize global_config
  @global_config = global_config
  @config = global_config.bootstrap
  @logger = global_config.logger
  @host = Porkadot::Install::Kubelet.new(self.config.kubelet_config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/porkadot/install/bootstrap.rb', line 7

def config
  @config
end

#global_configObject (readonly)

Returns the value of attribute global_config.



6
7
8
# File 'lib/porkadot/install/bootstrap.rb', line 6

def global_config
  @global_config
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/porkadot/install/bootstrap.rb', line 9

def host
  @host
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/porkadot/install/bootstrap.rb', line 8

def logger
  @logger
end

Instance Method Details

#cleanupObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/porkadot/install/bootstrap.rb', line 44

def cleanup
  global_config = self.global_config
  config = self.config
  on(host) do |host|
    execute(:mkdir, '-p', Porkadot::Install::KUBE_TEMP)
    if test("[ -d #{KUBE_TEMP} ]")
      execute(:rm, '-rf', KUBE_TEMP)
      execute(:rm, '-rf', KUBE_SECRETS_TEMP)
    end
    upload! config.target_path, KUBE_TEMP, recursive: true
    upload! config.target_secrets_path, KUBE_SECRETS_TEMP, recursive: true
    execute(:cp, '-r', KUBE_SECRETS_TEMP + '/*', KUBE_TEMP)

    global_config.nodes.each do |k, node|
      if node.apiserver?
        endpoint = "https://#{node.hostname}:#{global_config.k8s.apiserver.bind_port}/healthz"
        info "Start to wait api node #{node.hostname}"
        while !test('curl', '-skf', endpoint)
          info "Still waiting for API node: #{node.hostname}"
          sleep 5
        end
      end
    end

    endpoint = "https://#{global_config.k8s.control_plane_endpoint}/healthz"
    info "Start to wait api endpoint"
    while !test('curl', '-skf', endpoint)
      info "Still waiting for API: #{endpoint}"
      sleep 5
    end

    as user: 'root' do
      execute(:bash, File.join(KUBE_TEMP, 'cleanup.sh'))
    end
  end
end

#installObject



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
# File 'lib/porkadot/install/bootstrap.rb', line 18

def install
  global_config = self.global_config
  config = self.config
  on(host) do |host|
    execute(:mkdir, '-p', Porkadot::Install::KUBE_TEMP)
    if test("[ -d #{KUBE_TEMP} ]")
      execute(:rm, '-rf', KUBE_TEMP)
      execute(:rm, '-rf', KUBE_SECRETS_TEMP)
    end
    upload! config.target_path, KUBE_TEMP, recursive: true
    upload! config.target_secrets_path, KUBE_SECRETS_TEMP, recursive: true
    execute(:cp, '-r', KUBE_SECRETS_TEMP + '/*', KUBE_TEMP)

    as user: 'root' do
      execute(:bash, File.join(KUBE_TEMP, 'install.sh'))
    end

   endpoint = "https://127.0.0.1:#{global_config.k8s.apiserver.bind_port}/readyz"
   info "Start to wait for Bootstrapping Kubernetes API: #{endpoint}"
    while !test('curl', '-skf', endpoint)
      info "Still wating for Bootstrapping Kubernetes API..."
      sleep 5
    end
  end
end