2017-10-31 15:55:35 +02:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rancher/rke/hosts"
|
2017-11-14 20:11:21 +02:00
|
|
|
"github.com/rancher/types/apis/cluster.cattle.io/v1"
|
2017-11-13 23:28:38 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-10-31 15:55:35 +02:00
|
|
|
)
|
|
|
|
|
2017-12-01 01:16:45 +02:00
|
|
|
func RunWorkerPlane(controlHosts []*hosts.Host, workerHosts []*hosts.Host, workerServices v1.RKEConfigServices) error {
|
2017-10-31 15:55:35 +02:00
|
|
|
logrus.Infof("[%s] Building up Worker Plane..", WorkerRole)
|
|
|
|
for _, host := range controlHosts {
|
|
|
|
// only one master for now
|
2017-11-30 03:41:17 +02:00
|
|
|
if err := runKubelet(host, workerServices.Kubelet); err != nil {
|
2017-10-31 15:55:35 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := runKubeproxy(host, workerServices.Kubeproxy); err != nil {
|
2017-10-31 15:55:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, host := range workerHosts {
|
2017-11-15 03:12:33 +02:00
|
|
|
// run nginx proxy
|
2017-12-01 01:16:45 +02:00
|
|
|
if !host.IsControl {
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := runNginxProxy(host, controlHosts); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-15 03:12:33 +02:00
|
|
|
}
|
2017-10-31 15:55:35 +02:00
|
|
|
// run kubelet
|
2017-11-30 03:41:17 +02:00
|
|
|
if err := runKubelet(host, workerServices.Kubelet); err != nil {
|
2017-10-31 15:55:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubeproxy
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := runKubeproxy(host, workerServices.Kubeproxy); err != nil {
|
2017-10-31 15:55:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logrus.Infof("[%s] Successfully started Worker Plane..", WorkerRole)
|
|
|
|
return nil
|
|
|
|
}
|
2017-11-15 04:54:26 +02:00
|
|
|
|
2017-12-01 01:16:45 +02:00
|
|
|
func RemoveWorkerPlane(workerHosts []*hosts.Host, force bool) error {
|
2017-11-20 20:08:50 +02:00
|
|
|
logrus.Infof("[%s] Tearing down Worker Plane..", WorkerRole)
|
2017-12-01 01:16:45 +02: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 20:08:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := removeKubelet(host); err != nil {
|
2017-11-20 20:08:50 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := removeKubeproxy(host); err != nil {
|
2017-11-20 20:08:50 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-11-30 01:18:12 +02:00
|
|
|
if err := removeNginxProxy(host); err != nil {
|
2017-11-20 20:08:50 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-12-01 01:16:45 +02:00
|
|
|
logrus.Infof("[%s] Successfully teared down Worker Plane..", WorkerRole)
|
2017-11-20 20:08:50 +02:00
|
|
|
}
|
2017-12-01 01:16:45 +02:00
|
|
|
|
2017-11-20 20:08:50 +02:00
|
|
|
return nil
|
|
|
|
}
|