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"
|
2018-02-01 15:16:02 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2017-10-29 09:45:21 +00:00
|
|
|
)
|
|
|
|
|
2018-01-31 17:50:55 +00:00
|
|
|
func RunControlPlane(ctx context.Context, controlHosts, etcdHosts []*hosts.Host, controlServices v3.RKEConfigServices, sidekickImage, authorizationMode string, localConnDialerFactory hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry) error {
|
2018-01-09 22:10:56 +00:00
|
|
|
log.Infof(ctx, "[%s] Building up Controller Plane..", ControlRole)
|
2018-02-01 15:16:02 +00:00
|
|
|
var errgrp errgroup.Group
|
2017-10-31 13:55:35 +00:00
|
|
|
for _, host := range controlHosts {
|
2018-02-01 15:16:02 +00:00
|
|
|
runHost := host
|
|
|
|
errgrp.Go(func() error {
|
|
|
|
return doDeployControlHost(ctx, runHost, etcdHosts, controlServices, sidekickImage, authorizationMode, localConnDialerFactory, prsMap)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if err := errgrp.Wait(); err != nil {
|
|
|
|
return err
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
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-23 23:02:22 +00:00
|
|
|
log.Infof(ctx, "[%s] Successfully tore down Controller Plane..", ControlRole)
|
2017-11-20 18:08:50 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-02-01 15:16:02 +00:00
|
|
|
|
|
|
|
func doDeployControlHost(ctx context.Context, host *hosts.Host, etcdHosts []*hosts.Host, controlServices v3.RKEConfigServices, sidekickImage, authorizationMode string, localConnDialerFactory hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry) error {
|
|
|
|
if host.IsWorker {
|
|
|
|
if err := removeNginxProxy(ctx, host); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// run sidekick
|
|
|
|
if err := runSidekick(ctx, host, sidekickImage, prsMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubeapi
|
|
|
|
if err := runKubeAPI(ctx, host, etcdHosts, controlServices.KubeAPI, authorizationMode, localConnDialerFactory, prsMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run kubecontroller
|
|
|
|
if err := runKubeController(ctx, host, controlServices.KubeController, authorizationMode, localConnDialerFactory, prsMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// run scheduler
|
|
|
|
return runScheduler(ctx, host, controlServices.Scheduler, localConnDialerFactory, prsMap)
|
|
|
|
}
|