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
|
|
|
"fmt"
|
|
|
|
|
2017-10-29 09:45:21 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
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"
|
2017-10-31 13:55:35 +00:00
|
|
|
"github.com/rancher/rke/pki"
|
2017-12-05 16:55:58 +00:00
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
2017-10-29 09:45:21 +00:00
|
|
|
)
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func runKubeController(ctx context.Context, host *hosts.Host, kubeControllerService v3.KubeControllerService, authorizationMode string, df hosts.DialerFactory) error {
|
2017-12-14 21:56:19 +00:00
|
|
|
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService, authorizationMode)
|
2018-01-09 22:10:56 +00:00
|
|
|
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, KubeControllerContainerName, host.Address, ControlRole); err != nil {
|
2017-12-19 22:18:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-01-09 22:10:56 +00:00
|
|
|
return runHealthcheck(ctx, host, KubeControllerPort, false, KubeControllerContainerName, df)
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:10:56 +00:00
|
|
|
func removeKubeController(ctx context.Context, host *hosts.Host) error {
|
|
|
|
return docker.DoRemoveContainer(ctx, host.DClient, KubeControllerContainerName, host.Address)
|
2017-11-20 18:08:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 21:56:19 +00:00
|
|
|
func buildKubeControllerConfig(kubeControllerService v3.KubeControllerService, authorizationMode string) (*container.Config, *container.HostConfig) {
|
2017-10-29 09:45:21 +00:00
|
|
|
imageCfg := &container.Config{
|
2017-11-02 10:07:10 +00:00
|
|
|
Image: kubeControllerService.Image,
|
2017-12-08 23:05:55 +00:00
|
|
|
Entrypoint: []string{"/opt/rke/entrypoint.sh",
|
|
|
|
"kube-controller-manager",
|
2017-10-29 09:45:21 +00:00
|
|
|
"--address=0.0.0.0",
|
|
|
|
"--cloud-provider=",
|
2017-11-15 01:12:33 +00:00
|
|
|
"--leader-elect=true",
|
2018-01-16 23:10:14 +00:00
|
|
|
"--kubeconfig=" + pki.GetConfigPath(pki.KubeControllerCertName),
|
2017-10-29 09:45:21 +00:00
|
|
|
"--enable-hostpath-provisioner=false",
|
|
|
|
"--node-monitor-grace-period=40s",
|
|
|
|
"--pod-eviction-timeout=5m0s",
|
|
|
|
"--v=2",
|
|
|
|
"--allocate-node-cidrs=true",
|
2017-10-30 06:31:06 +00:00
|
|
|
"--cluster-cidr=" + kubeControllerService.ClusterCIDR,
|
2017-10-31 13:55:35 +00:00
|
|
|
"--service-cluster-ip-range=" + kubeControllerService.ServiceClusterIPRange,
|
2018-01-16 23:10:14 +00:00
|
|
|
"--service-account-private-key-file=" + pki.GetKeyPath(pki.KubeAPICertName),
|
|
|
|
"--root-ca-file=" + pki.GetCertPath(pki.CACertName),
|
2017-10-31 13:55:35 +00:00
|
|
|
},
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|
2017-12-14 21:56:19 +00:00
|
|
|
if authorizationMode == RBACAuthorizationMode {
|
|
|
|
imageCfg.Cmd = append(imageCfg.Cmd, "--use-service-account-credentials=true")
|
|
|
|
}
|
2017-10-29 09:45:21 +00:00
|
|
|
hostCfg := &container.HostConfig{
|
2017-12-08 23:05:55 +00:00
|
|
|
VolumesFrom: []string{
|
|
|
|
SidekickContainerName,
|
|
|
|
},
|
2017-10-31 13:55:35 +00:00
|
|
|
Binds: []string{
|
|
|
|
"/etc/kubernetes:/etc/kubernetes",
|
|
|
|
},
|
2017-11-15 01:12:33 +00:00
|
|
|
NetworkMode: "host",
|
2017-10-29 09:45:21 +00:00
|
|
|
RestartPolicy: container.RestartPolicy{Name: "always"},
|
|
|
|
}
|
2017-11-14 18:11:21 +00:00
|
|
|
for arg, value := range kubeControllerService.ExtraArgs {
|
|
|
|
cmd := fmt.Sprintf("--%s=%s", arg, value)
|
2017-11-30 23:16:45 +00:00
|
|
|
imageCfg.Entrypoint = append(imageCfg.Entrypoint, cmd)
|
2017-11-14 18:11:21 +00:00
|
|
|
}
|
2017-10-31 13:55:35 +00:00
|
|
|
return imageCfg, hostCfg
|
2017-10-29 09:45:21 +00:00
|
|
|
}
|