2017-10-29 09:45:21 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2018-01-09 22:10:56 +00:00
|
|
|
"context"
|
2017-11-14 18:11:21 +00:00
|
|
|
|
2017-10-31 13:55:35 +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 {
|
2019-08-14 10:53:32 +00:00
|
|
|
imageCfg, hostCfg, healthCheckURL := GetProcessConfig(kubeAPIProcess, host)
|
2018-01-31 17:50:55 +00:00
|
|
|
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, KubeAPIContainerName, host.Address, ControlRole, prsMap); err != nil {
|
2017-12-19 22:18:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-05-01 00:25:52 +00:00
|
|
|
if err := runHealthcheck(ctx, host, KubeAPIContainerName, df, healthCheckURL, certMap); err != nil {
|
2018-03-21 17:20:58 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return createLogLink(ctx, host, KubeAPIContainerName, ControlRole, alpineImage, prsMap)
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func removeKubeAPI(ctx context.Context, host *hosts.Host) error {
|
|
|
|
return docker.DoRemoveContainer(ctx, host.DClient, KubeAPIContainerName, host.Address)
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
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
|
|
|
|
}
|