1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-27 19:25:44 +00:00
rke/services/kubeapi.go

50 lines
2.0 KiB
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package services
import (
"context"
2017-11-14 18:11:21 +00:00
"github.com/rancher/rke/docker"
2017-10-29 09:45:21 +00:00
"github.com/rancher/rke/hosts"
2019-10-03 01:56:39 +00:00
"github.com/rancher/rke/log"
2018-05-01 00:25:52 +00:00
"github.com/rancher/rke/pki"
2020-07-11 16:24:19 +00:00
v3 "github.com/rancher/rke/types"
2019-10-03 01:56:39 +00:00
"github.com/sirupsen/logrus"
2017-10-29 09:45:21 +00:00
)
2018-05-01 00:25:52 +00:00
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
}
2018-05-01 00:25:52 +00:00
if err := runHealthcheck(ctx, host, KubeAPIContainerName, df, healthCheckURL, certMap); err != nil {
return err
}
return createLogLink(ctx, host, KubeAPIContainerName, ControlRole, alpineImage, prsMap)
2017-10-29 09:45:21 +00:00
}
func removeKubeAPI(ctx context.Context, host *hosts.Host) error {
return docker.DoRemoveContainer(ctx, host.DClient, KubeAPIContainerName, host.Address)
}
2018-08-20 04:37:04 +00:00
2019-01-14 17:51:20 +00:00
func RestartKubeAPI(ctx context.Context, host *hosts.Host) error {
2018-08-20 04:37:04 +00:00
return docker.DoRestartContainer(ctx, host.DClient, KubeAPIContainerName, host.Address)
}
2019-10-03 01:56:39 +00:00
func RestartKubeAPIWithHealthcheck(ctx context.Context, hostList []*hosts.Host, df hosts.DialerFactory, certMap map[string]pki.CertificatePKI) error {
2020-12-29 17:47:09 +00:00
log.Infof(ctx, "[%s] Restarting %s on %s nodes..", ControlRole, KubeAPIContainerName, ControlRole)
2019-10-03 01:56:39 +00:00
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
}
}
2020-12-29 17:47:09 +00:00
log.Infof(ctx, "[%s] Restarted %s on %s nodes successfully", ControlRole, KubeAPIContainerName, ControlRole)
2019-10-03 01:56:39 +00:00
return nil
}