1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-01 23:16:22 +00:00
Files
rke/services/workerplane.go

88 lines
2.6 KiB
Go
Raw Normal View History

package services
import (
"context"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/log"
2017-12-05 09:55:58 -07:00
"github.com/rancher/types/apis/management.cattle.io/v3"
2017-12-29 05:33:20 +02:00
"golang.org/x/sync/errgroup"
)
func RunWorkerPlane(ctx context.Context, controlHosts, workerHosts []*hosts.Host, workerServices v3.RKEConfigServices, nginxProxyImage, sidekickImage string, localConnDialerFactory hosts.DialerFactory) error {
log.Infof(ctx, "[%s] Building up Worker Plane..", WorkerRole)
2017-12-29 05:33:20 +02:00
var errgrp errgroup.Group
// Deploy worker components on control hosts
for _, host := range controlHosts {
2017-12-29 05:33:20 +02:00
controlHost := host
errgrp.Go(func() error {
return doDeployWorkerPlane(ctx, controlHost, workerServices, nginxProxyImage, sidekickImage, localConnDialerFactory, controlHosts)
2017-12-29 05:33:20 +02:00
})
}
if err := errgrp.Wait(); err != nil {
return err
}
2017-12-29 05:33:20 +02:00
// Deploy worker components on worker hosts
for _, host := range workerHosts {
2017-12-29 05:33:20 +02:00
workerHost := host
errgrp.Go(func() error {
return doDeployWorkerPlane(ctx, workerHost, workerServices, nginxProxyImage, sidekickImage, localConnDialerFactory, controlHosts)
2017-12-29 05:33:20 +02:00
})
}
if err := errgrp.Wait(); err != nil {
return err
}
log.Infof(ctx, "[%s] Successfully started Worker Plane..", WorkerRole)
return nil
}
func RemoveWorkerPlane(ctx context.Context, workerHosts []*hosts.Host, force bool) error {
log.Infof(ctx, "[%s] Tearing down Worker Plane..", WorkerRole)
for _, host := range workerHosts {
// check if the host already is a controlplane
if host.IsControl && !force {
log.Infof(ctx, "[%s] Host [%s] is already a controlplane host, nothing to do.", WorkerRole, host.Address)
return nil
}
if err := removeKubelet(ctx, host); err != nil {
return err
}
if err := removeKubeproxy(ctx, host); err != nil {
return err
}
if err := removeNginxProxy(ctx, host); err != nil {
return err
}
if err := removeSidekick(ctx, host); err != nil {
2017-12-09 01:05:55 +02:00
return err
}
log.Infof(ctx, "[%s] Successfully teared down Worker Plane..", WorkerRole)
}
return nil
}
2017-12-29 05:33:20 +02:00
func doDeployWorkerPlane(ctx context.Context, host *hosts.Host,
2017-12-29 05:33:20 +02:00
workerServices v3.RKEConfigServices,
nginxProxyImage, sidekickImage string,
localConnDialerFactory hosts.DialerFactory,
2017-12-29 05:33:20 +02:00
controlHosts []*hosts.Host) error {
// run nginx proxy
if !host.IsControl {
if err := runNginxProxy(ctx, host, controlHosts, nginxProxyImage); err != nil {
2017-12-29 05:33:20 +02:00
return err
}
}
// run sidekick
if err := runSidekick(ctx, host, sidekickImage); err != nil {
2017-12-29 05:33:20 +02:00
return err
}
// run kubelet
if err := runKubelet(ctx, host, workerServices.Kubelet, localConnDialerFactory); err != nil {
2017-12-29 05:33:20 +02:00
return err
}
return runKubeproxy(ctx, host, workerServices.Kubeproxy, localConnDialerFactory)
2017-12-29 05:33:20 +02:00
}