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