mirror of
https://github.com/rancher/rke.git
synced 2025-08-19 07:17:30 +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{
|
CommandArgs := map[string]string{
|
||||||
"name": "etcd-" + host.HostnameOverride,
|
"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",
|
"advertise-client-urls": "https://" + host.InternalAddress + ":2379,https://" + host.InternalAddress + ":4001",
|
||||||
"listen-client-urls": "https://" + listenAddress + ":2379",
|
"listen-client-urls": "https://" + listenAddress + ":2379",
|
||||||
"initial-advertise-peer-urls": "https://" + host.InternalAddress + ":2380",
|
"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{
|
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")),
|
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(prefixPath, "/etc/kubernetes")),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
@ -40,11 +39,11 @@ type Host struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ToCleanEtcdDir = "/var/lib/etcd"
|
ToCleanEtcdDir = "/var/lib/etcd/"
|
||||||
ToCleanSSLDir = "/etc/kubernetes/"
|
ToCleanSSLDir = "/etc/kubernetes/"
|
||||||
ToCleanCNIConf = "/etc/cni/"
|
ToCleanCNIConf = "/etc/cni/"
|
||||||
ToCleanCNIBin = "/opt/cni/"
|
ToCleanCNIBin = "/opt/cni/"
|
||||||
ToCleanCNILib = "/var/lib/cni"
|
ToCleanCNILib = "/var/lib/cni/"
|
||||||
ToCleanCalicoRun = "/var/run/calico/"
|
ToCleanCalicoRun = "/var/run/calico/"
|
||||||
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
|
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
|
||||||
CleanerContainerName = "kube-cleaner"
|
CleanerContainerName = "kube-cleaner"
|
||||||
@ -243,12 +242,8 @@ func buildCleanerConfig(host *Host, toCleanDirs []string, cleanerImage string) (
|
|||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
}
|
}
|
||||||
bindMounts := []string{}
|
bindMounts := []string{}
|
||||||
bindMountsMap := make(map[string]string)
|
|
||||||
for _, vol := range toCleanDirs {
|
for _, vol := range toCleanDirs {
|
||||||
bindMountsMap[filepath.Dir(vol)] = vol
|
bindMounts = append(bindMounts, fmt.Sprintf("%s:%s:z", vol, vol))
|
||||||
}
|
|
||||||
for dir := range bindMountsMap {
|
|
||||||
bindMounts = append(bindMounts, fmt.Sprintf("%s:%s:z", dir, dir))
|
|
||||||
}
|
}
|
||||||
hostCfg := &container.HostConfig{
|
hostCfg := &container.HostConfig{
|
||||||
Binds: bindMounts,
|
Binds: bindMounts,
|
||||||
|
@ -20,6 +20,12 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
EtcdBackupPath = "/opt/rke/etcdbackup/"
|
||||||
|
EtcdRestorePath = "/opt/rke/etcdrestore/"
|
||||||
|
EtcdDataDir = "/var/lib/rancher/etcd/"
|
||||||
|
)
|
||||||
|
|
||||||
type EtcdBackup struct {
|
type EtcdBackup struct {
|
||||||
// Enable or disable backup creation
|
// Enable or disable backup creation
|
||||||
Backup bool
|
Backup bool
|
||||||
@ -235,7 +241,7 @@ func RunEtcdBackup(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]
|
|||||||
}
|
}
|
||||||
hostCfg := &container.HostConfig{
|
hostCfg := &container.HostConfig{
|
||||||
Binds: []string{
|
Binds: []string{
|
||||||
"/opt/rke/etcdbackup:/backup",
|
fmt.Sprintf("%s:/backup", EtcdBackupPath),
|
||||||
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(etcdHost.PrefixPath, "/etc/kubernetes"))},
|
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(etcdHost.PrefixPath, "/etc/kubernetes"))},
|
||||||
NetworkMode: container.NetworkMode("host"),
|
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)
|
status, err := docker.WaitForContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdBackupOnceContainerName)
|
||||||
if status != 0 || err != nil {
|
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)
|
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 {
|
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)
|
log.Infof(ctx, "[etcd] Restoring [%s] snapshot on etcd host [%s]", backupName, etcdHost.Address)
|
||||||
nodeName := pki.GetEtcdCrtName(etcdHost.InternalAddress)
|
nodeName := pki.GetEtcdCrtName(etcdHost.InternalAddress)
|
||||||
backupPath := filepath.Join("/backup/", backupName)
|
backupPath := filepath.Join(EtcdBackupPath, backupName)
|
||||||
|
|
||||||
imageCfg := &container.Config{
|
imageCfg := &container.Config{
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
|
"sh", "-c", strings.Join([]string{
|
||||||
"/usr/local/bin/etcdctl",
|
"/usr/local/bin/etcdctl",
|
||||||
"--cacert", pki.GetCertPath(pki.CACertName),
|
"--cacert", pki.GetCertPath(pki.CACertName),
|
||||||
"--cert", pki.GetCertPath(nodeName),
|
"--cert", pki.GetCertPath(nodeName),
|
||||||
"--key", pki.GetKeyPath(nodeName),
|
"--key", pki.GetKeyPath(nodeName),
|
||||||
"snapshot", "restore", backupPath,
|
"snapshot", "restore", backupPath,
|
||||||
"--data-dir=/var/lib/rancher/etcd",
|
"--data-dir=" + EtcdRestorePath,
|
||||||
"--name=etcd-" + etcdHost.HostnameOverride,
|
"--name=etcd-" + etcdHost.HostnameOverride,
|
||||||
"--initial-cluster=" + initCluster,
|
"--initial-cluster=" + initCluster,
|
||||||
"--initial-cluster-token=etcd-cluster-1",
|
"--initial-cluster-token=etcd-cluster-1",
|
||||||
"--initial-advertise-peer-urls=https://" + etcdHost.InternalAddress + ":2380",
|
"--initial-advertise-peer-urls=https://" + etcdHost.InternalAddress + ":2380",
|
||||||
|
"&& mv", EtcdRestorePath + "*", EtcdDataDir,
|
||||||
|
"&& rm -rf", EtcdRestorePath,
|
||||||
|
}, " "),
|
||||||
},
|
},
|
||||||
Env: []string{"ETCDCTL_API=3"},
|
Env: []string{"ETCDCTL_API=3"},
|
||||||
Image: etcdRestoreImage,
|
Image: etcdRestoreImage,
|
||||||
}
|
}
|
||||||
hostCfg := &container.HostConfig{
|
hostCfg := &container.HostConfig{
|
||||||
Binds: []string{
|
Binds: []string{
|
||||||
"/opt/rke/etcdbackup:/backup:z",
|
"/opt/rke/:/opt/rke/:z",
|
||||||
fmt.Sprintf("%s:/var/lib/rancher/:z", path.Join(etcdHost.PrefixPath, "/var/lib/")),
|
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"))},
|
fmt.Sprintf("%s:/etc/kubernetes:z", path.Join(etcdHost.PrefixPath, "/etc/kubernetes"))},
|
||||||
NetworkMode: container.NetworkMode("host"),
|
NetworkMode: container.NetworkMode("host"),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user