1
0
mirror of https://github.com/rancher/rke.git synced 2025-06-28 08:18:58 +00:00
rke/services/kubecontroller.go

54 lines
1.8 KiB
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package services
import (
2017-11-14 18:11:21 +00:00
"fmt"
2017-10-29 09:45:21 +00:00
"github.com/docker/docker/api/types/container"
"github.com/rancher/rke/docker"
2017-10-29 09:45:21 +00:00
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/pki"
2017-11-14 18:11:21 +00:00
"github.com/rancher/types/apis/cluster.cattle.io/v1"
2017-10-29 09:45:21 +00:00
)
2017-11-09 19:50:49 +00:00
func runKubeController(host hosts.Host, kubeControllerService v1.KubeControllerService) error {
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService)
2017-11-28 17:45:24 +00:00
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, KubeControllerContainerName, host.Address, ControlRole)
2017-10-29 09:45:21 +00:00
}
func removeKubeController(host hosts.Host) error {
2017-11-28 17:45:24 +00:00
return docker.DoRemoveContainer(host.DClient, KubeControllerContainerName, host.Address)
}
2017-11-09 19:50:49 +00:00
func buildKubeControllerConfig(kubeControllerService v1.KubeControllerService) (*container.Config, *container.HostConfig) {
2017-10-29 09:45:21 +00:00
imageCfg := &container.Config{
Image: kubeControllerService.Image,
2017-11-22 20:46:01 +00:00
Entrypoint: []string{"kube-controller-manager",
2017-10-29 09:45:21 +00:00
"--address=0.0.0.0",
"--cloud-provider=",
"--leader-elect=true",
"--kubeconfig=" + pki.KubeControllerConfigPath,
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",
"--cluster-cidr=" + kubeControllerService.ClusterCIDR,
"--service-cluster-ip-range=" + kubeControllerService.ServiceClusterIPRange,
"--service-account-private-key-file=" + pki.KubeAPIKeyPath,
"--root-ca-file=" + pki.CACertPath,
},
2017-10-29 09:45:21 +00:00
}
hostCfg := &container.HostConfig{
Binds: []string{
"/etc/kubernetes:/etc/kubernetes",
},
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)
imageCfg.Cmd = append(imageCfg.Cmd, cmd)
}
return imageCfg, hostCfg
2017-10-29 09:45:21 +00:00
}