mirror of
https://github.com/rancher/rke.git
synced 2025-08-28 11:21:31 +00:00
Refactor configuration defaults Add comments to config Add configurable utility images Add configurable network plugin images Add configurable kubedns images
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package services
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/rancher/rke/docker"
|
|
"github.com/rancher/rke/hosts"
|
|
)
|
|
|
|
const (
|
|
NginxProxyImage = "rancher/rke-nginx-proxy:0.1.0"
|
|
NginxProxyEnvName = "CP_HOSTS"
|
|
)
|
|
|
|
func RollingUpdateNginxProxy(cpHosts []*hosts.Host, workerHosts []*hosts.Host, nginxProxyImage string) error {
|
|
nginxProxyEnv := buildProxyEnv(cpHosts)
|
|
for _, host := range workerHosts {
|
|
imageCfg, hostCfg := buildNginxProxyConfig(host, nginxProxyEnv, nginxProxyImage)
|
|
if err := docker.DoRollingUpdateContainer(host.DClient, imageCfg, hostCfg, NginxProxyContainerName, host.Address, WorkerRole); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func runNginxProxy(host *hosts.Host, cpHosts []*hosts.Host, nginxProxyImage string) error {
|
|
nginxProxyEnv := buildProxyEnv(cpHosts)
|
|
imageCfg, hostCfg := buildNginxProxyConfig(host, nginxProxyEnv, nginxProxyImage)
|
|
return docker.DoRunContainer(host.DClient, imageCfg, hostCfg, NginxProxyContainerName, host.Address, WorkerRole)
|
|
}
|
|
|
|
func removeNginxProxy(host *hosts.Host) error {
|
|
return docker.DoRemoveContainer(host.DClient, NginxProxyContainerName, host.Address)
|
|
}
|
|
|
|
func buildNginxProxyConfig(host *hosts.Host, nginxProxyEnv, nginxProxyImage string) (*container.Config, *container.HostConfig) {
|
|
imageCfg := &container.Config{
|
|
Image: nginxProxyImage,
|
|
Env: []string{fmt.Sprintf("%s=%s", NginxProxyEnvName, nginxProxyEnv)},
|
|
}
|
|
hostCfg := &container.HostConfig{
|
|
NetworkMode: "host",
|
|
RestartPolicy: container.RestartPolicy{Name: "always"},
|
|
}
|
|
|
|
return imageCfg, hostCfg
|
|
}
|
|
|
|
func buildProxyEnv(cpHosts []*hosts.Host) string {
|
|
proxyEnv := ""
|
|
for i, cpHost := range cpHosts {
|
|
proxyEnv += fmt.Sprintf("%s", cpHost.InternalAddress)
|
|
if i < (len(cpHosts) - 1) {
|
|
proxyEnv += ","
|
|
}
|
|
}
|
|
return proxyEnv
|
|
}
|