1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-27 03:11:03 +00:00
rke/services/kubeapi.go
Sebastiaan van Steenis c8cc8194fb controlplane typo
2020-12-29 18:47:09 +01:00

50 lines
2.0 KiB
Go

package services
import (
"context"
"github.com/rancher/rke/docker"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/log"
"github.com/rancher/rke/pki"
v3 "github.com/rancher/rke/types"
"github.com/sirupsen/logrus"
)
func runKubeAPI(ctx context.Context, host *hosts.Host, df hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry, kubeAPIProcess v3.Process, alpineImage string, certMap map[string]pki.CertificatePKI) error {
imageCfg, hostCfg, healthCheckURL := GetProcessConfig(kubeAPIProcess, host)
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Address, ControlRole, prsMap); err != nil {
return err
}
if err := runHealthcheck(ctx, host, KubeAPIContainerName, df, healthCheckURL, certMap); err != nil {
return err
}
return createLogLink(ctx, host, KubeAPIContainerName, ControlRole, alpineImage, prsMap)
}
func removeKubeAPI(ctx context.Context, host *hosts.Host) error {
return docker.DoRemoveContainer(ctx, host.DClient, KubeAPIContainerName, host.Address)
}
func RestartKubeAPI(ctx context.Context, host *hosts.Host) error {
return docker.DoRestartContainer(ctx, host.DClient, KubeAPIContainerName, host.Address)
}
func RestartKubeAPIWithHealthcheck(ctx context.Context, hostList []*hosts.Host, df hosts.DialerFactory, certMap map[string]pki.CertificatePKI) error {
log.Infof(ctx, "[%s] Restarting %s on %s nodes..", ControlRole, KubeAPIContainerName, ControlRole)
for _, runHost := range hostList {
logrus.Debugf("[%s] Restarting %s on node [%s]", ControlRole, KubeAPIContainerName, runHost.Address)
if err := RestartKubeAPI(ctx, runHost); err != nil {
return err
}
logrus.Debugf("[%s] Running healthcheck for %s on node [%s]", ControlRole, KubeAPIContainerName, runHost.Address)
if err := runHealthcheck(ctx, runHost, KubeAPIContainerName,
df, GetHealthCheckURL(true, KubeAPIPort),
certMap); err != nil {
return err
}
}
log.Infof(ctx, "[%s] Restarted %s on %s nodes successfully", ControlRole, KubeAPIContainerName, ControlRole)
return nil
}