2017-10-31 13:55:35 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rancher/rke/hosts"
|
2017-12-05 16:55:58 +00:00
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
2017-11-13 21:28:38 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-12-29 03:33:20 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2017-10-31 13:55:35 +00:00
|
|
|
)
|
|
|
|
|
2017-12-19 22:18:27 +00:00
|
|
|
func RunWorkerPlane(controlHosts, workerHosts []*hosts.Host, workerServices v3.RKEConfigServices, nginxProxyImage, sidekickImage string, healthcheckDialerFactory hosts.DialerFactory) error {
|
2017-10-31 13:55:35 +00:00
|
|
|
logrus.Infof("[%s] Building up Worker Plane..", WorkerRole)
|
2017-12-29 03:33:20 +00:00
|
|
|
var errgrp errgroup.Group
|
|
|
|
|
|
|
|
// Deploy worker components on control hosts
|
2017-10-31 13:55:35 +00:00
|
|
|
for _, host := range controlHosts {
|
2017-12-29 03:33:20 +00:00
|
|
|
controlHost := host
|
|
|
|
errgrp.Go(func() error {
|
|
|
|
return doDeployWorkerPlane(controlHost, workerServices, nginxProxyImage, sidekickImage, healthcheckDialerFactory, controlHosts)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if err := errgrp.Wait(); err != nil {
|
|
|
|
return err
|
2017-10-31 13:55:35 +00:00
|
|
|
}
|
2017-12-29 03:33:20 +00:00
|
|
|
// Deploy worker components on worker hosts
|
2017-10-31 13:55:35 +00:00
|
|
|
for _, host := range workerHosts {
|
2017-12-29 03:33:20 +00:00
|
|
|
workerHost := host
|
|
|
|
errgrp.Go(func() error {
|
|
|
|
return doDeployWorkerPlane(workerHost, workerServices, nginxProxyImage, sidekickImage, healthcheckDialerFactory, controlHosts)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if err := errgrp.Wait(); err != nil {
|
|
|
|
return err
|
2017-10-31 13:55:35 +00:00
|
|
|
}
|
|
|
|
logrus.Infof("[%s] Successfully started Worker Plane..", WorkerRole)
|
|
|
|
return nil
|
|
|
|
}
|
2017-11-15 02:54:26 +00:00
|
|
|
|
2017-11-30 23:16:45 +00:00
|
|
|
func RemoveWorkerPlane(workerHosts []*hosts.Host, force bool) error {
|
2017-11-20 18:08:50 +00:00
|
|
|
logrus.Infof("[%s] Tearing down Worker Plane..", WorkerRole)
|
2017-11-30 23:16:45 +00:00
|
|
|
for _, host := range workerHosts {
|
|
|
|
// check if the host already is a controlplane
|
|
|
|
if host.IsControl && !force {
|
|
|
|
logrus.Infof("[%s] Host [%s] is already a controlplane host, nothing to do.", WorkerRole, host.Address)
|
|
|
|
return nil
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 23:18:12 +00:00
|
|
|
if err := removeKubelet(host); err != nil {
|
2017-11-20 18:08:50 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-11-29 23:18:12 +00:00
|
|
|
if err := removeKubeproxy(host); err != nil {
|
2017-11-20 18:08:50 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-11-29 23:18:12 +00:00
|
|
|
if err := removeNginxProxy(host); err != nil {
|
2017-11-20 18:08:50 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-12-08 23:05:55 +00:00
|
|
|
if err := removeSidekick(host); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-30 23:16:45 +00:00
|
|
|
logrus.Infof("[%s] Successfully teared down Worker Plane..", WorkerRole)
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
2017-11-30 23:16:45 +00:00
|
|
|
|
2017-11-20 18:08:50 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-12-29 03:33:20 +00:00
|
|
|
|
|
|
|
func doDeployWorkerPlane(host *hosts.Host,
|
|
|
|
workerServices v3.RKEConfigServices,
|
|
|
|
nginxProxyImage, sidekickImage string,
|
|
|
|
healthcheckDialerFactory hosts.DialerFactory,
|
|
|
|
controlHosts []*hosts.Host) error {
|
|
|
|
// run nginx proxy
|
|
|
|
if !host.IsControl {
|
|
|
|
if err := runNginxProxy(host, controlHosts, nginxProxyImage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// run sidekick
|
|
|
|
if err := runSidekick(host, sidekickImage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubelet
|
|
|
|
if err := runKubelet(host, workerServices.Kubelet, healthcheckDialerFactory); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return runKubeproxy(host, workerServices.Kubeproxy, healthcheckDialerFactory)
|
|
|
|
}
|