2017-10-29 09:45:21 +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-10-29 09:45:21 +00:00
|
|
|
)
|
|
|
|
|
2017-12-05 16:55:58 +00:00
|
|
|
func RunControlPlane(controlHosts []*hosts.Host, etcdHosts []*hosts.Host, controlServices v3.RKEConfigServices) error {
|
2017-10-31 13:55:35 +00:00
|
|
|
logrus.Infof("[%s] Building up Controller Plane..", ControlRole)
|
|
|
|
for _, host := range controlHosts {
|
2017-11-30 23:16:45 +00:00
|
|
|
|
|
|
|
if host.IsWorker {
|
|
|
|
if err := removeNginxProxy(host); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-10-29 09:45:21 +00:00
|
|
|
// run kubeapi
|
2017-10-31 13:55:35 +00:00
|
|
|
err := runKubeAPI(host, etcdHosts, controlServices.KubeAPI)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubecontroller
|
2017-10-31 13:55:35 +00:00
|
|
|
err = runKubeController(host, controlServices.KubeController)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run scheduler
|
2017-10-31 13:55:35 +00:00
|
|
|
err = runScheduler(host, controlServices.Scheduler)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 13:55:35 +00:00
|
|
|
logrus.Infof("[%s] Successfully started Controller Plane..", ControlRole)
|
2017-10-29 09:45:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-11-15 02:54:26 +00:00
|
|
|
|
2017-11-30 23:16:45 +00:00
|
|
|
func RemoveControlPlane(controlHosts []*hosts.Host, force bool) error {
|
2017-11-20 18:08:50 +00:00
|
|
|
logrus.Infof("[%s] Tearing down the Controller Plane..", ControlRole)
|
|
|
|
for _, host := range controlHosts {
|
|
|
|
// remove KubeAPI
|
|
|
|
if err := removeKubeAPI(host); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove KubeController
|
|
|
|
if err := removeKubeController(host); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove scheduler
|
|
|
|
err := removeScheduler(host)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-30 23:16:45 +00:00
|
|
|
|
|
|
|
// check if the host already is a worker
|
|
|
|
if host.IsWorker {
|
|
|
|
logrus.Infof("[%s] Host [%s] is already a worker host, skipping delete kubelet and kubeproxy.", ControlRole, host.Address)
|
|
|
|
} else {
|
|
|
|
// remove KubeAPI
|
|
|
|
if err := removeKubelet(host); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// remove KubeController
|
|
|
|
if err := removeKubeproxy(host); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
|
|
|
logrus.Infof("[%s] Successfully teared down Controller Plane..", ControlRole)
|
|
|
|
return nil
|
|
|
|
}
|