mirror of
https://github.com/rancher/rke.git
synced 2025-05-10 17:35:03 +00:00
fix rhel and centos regression
This commit is contained in:
parent
21ee619645
commit
db3bda1191
@ -578,7 +578,7 @@ func (c *Cluster) BuildEtcdProcess(host *hosts.Host, etcdHosts []*hosts.Host, pr
|
||||
|
||||
CommandArgs := map[string]string{
|
||||
"name": "etcd-" + host.HostnameOverride,
|
||||
"data-dir": "/var/lib/rancher/etcd",
|
||||
"data-dir": services.EtcdDataDir,
|
||||
"advertise-client-urls": "https://" + host.InternalAddress + ":2379,https://" + host.InternalAddress + ":4001",
|
||||
"listen-client-urls": "https://" + listenAddress + ":2379",
|
||||
"initial-advertise-peer-urls": "https://" + host.InternalAddress + ":2380",
|
||||
@ -595,7 +595,7 @@ func (c *Cluster) BuildEtcdProcess(host *hosts.Host, etcdHosts []*hosts.Host, pr
|
||||
}
|
||||
|
||||
Binds := []string{
|
||||
fmt.Sprintf("%s:/var/lib/rancher/:z", path.Join(prefixPath, "/var/lib/")),
|
||||
fmt.Sprintf("%s:%s:z", path.Join(prefixPath, "/var/lib/etcd"), services.EtcdDataDir),
|
||||
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(prefixPath, "/etc/kubernetes")),
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@ -40,11 +39,11 @@ type Host struct {
|
||||
}
|
||||
|
||||
const (
|
||||
ToCleanEtcdDir = "/var/lib/etcd"
|
||||
ToCleanEtcdDir = "/var/lib/etcd/"
|
||||
ToCleanSSLDir = "/etc/kubernetes/"
|
||||
ToCleanCNIConf = "/etc/cni/"
|
||||
ToCleanCNIBin = "/opt/cni/"
|
||||
ToCleanCNILib = "/var/lib/cni"
|
||||
ToCleanCNILib = "/var/lib/cni/"
|
||||
ToCleanCalicoRun = "/var/run/calico/"
|
||||
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
|
||||
CleanerContainerName = "kube-cleaner"
|
||||
@ -243,12 +242,8 @@ func buildCleanerConfig(host *Host, toCleanDirs []string, cleanerImage string) (
|
||||
Cmd: cmd,
|
||||
}
|
||||
bindMounts := []string{}
|
||||
bindMountsMap := make(map[string]string)
|
||||
for _, vol := range toCleanDirs {
|
||||
bindMountsMap[filepath.Dir(vol)] = vol
|
||||
}
|
||||
for dir := range bindMountsMap {
|
||||
bindMounts = append(bindMounts, fmt.Sprintf("%s:%s:z", dir, dir))
|
||||
bindMounts = append(bindMounts, fmt.Sprintf("%s:%s:z", vol, vol))
|
||||
}
|
||||
hostCfg := &container.HostConfig{
|
||||
Binds: bindMounts,
|
||||
|
@ -20,6 +20,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
EtcdBackupPath = "/opt/rke/etcdbackup/"
|
||||
EtcdRestorePath = "/opt/rke/etcdrestore/"
|
||||
EtcdDataDir = "/var/lib/rancher/etcd/"
|
||||
)
|
||||
|
||||
type EtcdBackup struct {
|
||||
// Enable or disable backup creation
|
||||
Backup bool
|
||||
@ -235,7 +241,7 @@ func RunEtcdBackup(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]
|
||||
}
|
||||
hostCfg := &container.HostConfig{
|
||||
Binds: []string{
|
||||
"/opt/rke/etcdbackup:/backup",
|
||||
fmt.Sprintf("%s:/backup", EtcdBackupPath),
|
||||
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(etcdHost.PrefixPath, "/etc/kubernetes"))},
|
||||
NetworkMode: container.NetworkMode("host"),
|
||||
}
|
||||
@ -246,7 +252,7 @@ func RunEtcdBackup(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]
|
||||
}
|
||||
status, err := docker.WaitForContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdBackupOnceContainerName)
|
||||
if status != 0 || err != nil {
|
||||
return fmt.Errorf("Failed to take etcd backup exit code [%s]: %v", status, err)
|
||||
return fmt.Errorf("Failed to take etcd backup exit code [%d]: %v", status, err)
|
||||
}
|
||||
return docker.RemoveContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdBackupOnceContainerName)
|
||||
}
|
||||
@ -256,28 +262,32 @@ func RunEtcdBackup(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]
|
||||
func RestoreEtcdBackup(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, etcdRestoreImage, backupName, initCluster string) error {
|
||||
log.Infof(ctx, "[etcd] Restoring [%s] snapshot on etcd host [%s]", backupName, etcdHost.Address)
|
||||
nodeName := pki.GetEtcdCrtName(etcdHost.InternalAddress)
|
||||
backupPath := filepath.Join("/backup/", backupName)
|
||||
backupPath := filepath.Join(EtcdBackupPath, backupName)
|
||||
|
||||
imageCfg := &container.Config{
|
||||
Cmd: []string{
|
||||
"/usr/local/bin/etcdctl",
|
||||
"--cacert", pki.GetCertPath(pki.CACertName),
|
||||
"--cert", pki.GetCertPath(nodeName),
|
||||
"--key", pki.GetKeyPath(nodeName),
|
||||
"snapshot", "restore", backupPath,
|
||||
"--data-dir=/var/lib/rancher/etcd",
|
||||
"--name=etcd-" + etcdHost.HostnameOverride,
|
||||
"--initial-cluster=" + initCluster,
|
||||
"--initial-cluster-token=etcd-cluster-1",
|
||||
"--initial-advertise-peer-urls=https://" + etcdHost.InternalAddress + ":2380",
|
||||
"sh", "-c", strings.Join([]string{
|
||||
"/usr/local/bin/etcdctl",
|
||||
"--cacert", pki.GetCertPath(pki.CACertName),
|
||||
"--cert", pki.GetCertPath(nodeName),
|
||||
"--key", pki.GetKeyPath(nodeName),
|
||||
"snapshot", "restore", backupPath,
|
||||
"--data-dir=" + EtcdRestorePath,
|
||||
"--name=etcd-" + etcdHost.HostnameOverride,
|
||||
"--initial-cluster=" + initCluster,
|
||||
"--initial-cluster-token=etcd-cluster-1",
|
||||
"--initial-advertise-peer-urls=https://" + etcdHost.InternalAddress + ":2380",
|
||||
"&& mv", EtcdRestorePath + "*", EtcdDataDir,
|
||||
"&& rm -rf", EtcdRestorePath,
|
||||
}, " "),
|
||||
},
|
||||
Env: []string{"ETCDCTL_API=3"},
|
||||
Image: etcdRestoreImage,
|
||||
}
|
||||
hostCfg := &container.HostConfig{
|
||||
Binds: []string{
|
||||
"/opt/rke/etcdbackup:/backup:z",
|
||||
fmt.Sprintf("%s:/var/lib/rancher/:z", path.Join(etcdHost.PrefixPath, "/var/lib/")),
|
||||
"/opt/rke/:/opt/rke/:z",
|
||||
fmt.Sprintf("%s:/var/lib/rancher/etcd:z", path.Join(etcdHost.PrefixPath, "/var/lib/etcd")),
|
||||
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(etcdHost.PrefixPath, "/etc/kubernetes"))},
|
||||
NetworkMode: container.NetworkMode("host"),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user