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