2017-10-29 09:45:21 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2018-01-09 22:10:56 +00:00
|
|
|
"context"
|
|
|
|
|
2017-10-29 09:45:21 +00:00
|
|
|
"github.com/rancher/rke/hosts"
|
2018-01-09 22:10:56 +00:00
|
|
|
"github.com/rancher/rke/log"
|
2017-12-05 16:55:58 +00:00
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
2017-10-29 09:45:21 +00:00
|
|
|
)
|
|
|
|
|
2018-01-11 01:00:14 +00:00
|
|
|
func RunControlPlane(ctx context.Context, controlHosts, etcdHosts []*hosts.Host, controlServices v3.RKEConfigServices, sidekickImage, authorizationMode string, localConnDialerFactory hosts.DialerFactory) error {
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[%s] Building up Controller Plane..", ControlRole)
|
2017-10-31 13:55:35 +00:00
|
|
|
for _, host := range controlHosts {
|
2017-11-30 23:16:45 +00:00
|
|
|
|
|
|
|
if host.IsWorker {
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeNginxProxy(ctx, host); err != nil {
|
2017-11-30 23:16:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 23:05:55 +00:00
|
|
|
// run sidekick
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := runSidekick(ctx, host, sidekickImage); err != nil {
|
2017-12-08 23:05:55 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-10-29 09:45:21 +00:00
|
|
|
// run kubeapi
|
2018-01-11 01:00:14 +00:00
|
|
|
err := runKubeAPI(ctx, host, etcdHosts, controlServices.KubeAPI, authorizationMode, localConnDialerFactory)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubecontroller
|
2018-01-11 01:00:14 +00:00
|
|
|
err = runKubeController(ctx, host, controlServices.KubeController, authorizationMode, localConnDialerFactory)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run scheduler
|
2018-01-11 01:00:14 +00:00
|
|
|
err = runScheduler(ctx, host, controlServices.Scheduler, localConnDialerFactory)
|
2017-10-29 09:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[%s] Successfully started Controller Plane..", ControlRole)
|
2017-10-29 09:45:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-11-15 02:54:26 +00:00
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func RemoveControlPlane(ctx context.Context, controlHosts []*hosts.Host, force bool) error {
|
|
|
|
log.Infof(ctx, "[%s] Tearing down the Controller Plane..", ControlRole)
|
2017-11-20 18:08:50 +00:00
|
|
|
for _, host := range controlHosts {
|
|
|
|
// remove KubeAPI
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeKubeAPI(ctx, host); err != nil {
|
2017-11-20 18:08:50 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove KubeController
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeKubeController(ctx, host); err != nil {
|
2017-11-20 18:08:50 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove scheduler
|
2018-01-09 22:10:56 +00:00
|
|
|
err := removeScheduler(ctx, host)
|
2017-11-20 18:08:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-30 23:16:45 +00:00
|
|
|
|
|
|
|
// check if the host already is a worker
|
|
|
|
if host.IsWorker {
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[%s] Host [%s] is already a worker host, skipping delete kubelet and kubeproxy.", ControlRole, host.Address)
|
2017-11-30 23:16:45 +00:00
|
|
|
} else {
|
|
|
|
// remove KubeAPI
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeKubelet(ctx, host); err != nil {
|
2017-11-30 23:16:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// remove KubeController
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeKubeproxy(ctx, host); err != nil {
|
2017-11-30 23:16:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-12-08 23:05:55 +00:00
|
|
|
// remove Sidekick
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := removeSidekick(ctx, host); err != nil {
|
2017-12-08 23:05:55 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-11-30 23:16:45 +00:00
|
|
|
}
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[%s] Successfully teared down Controller Plane..", ControlRole)
|
2017-11-20 18:08:50 +00:00
|
|
|
return nil
|
|
|
|
}
|