1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-17 14:27:01 +00:00

Use etcd service extra_env in backup containers

This commit is contained in:
moelsayed 2019-07-16 02:54:59 +02:00 committed by Alena Prokharchyk
parent b4a7b7aa70
commit 17320083e9
2 changed files with 6 additions and 3 deletions

View File

@ -130,7 +130,7 @@ func (c *Cluster) RestoreEtcdSnapshot(ctx context.Context, snapshotPath string)
// Start restore process on all etcd hosts // Start restore process on all etcd hosts
initCluster := services.GetEtcdInitialCluster(c.EtcdHosts) initCluster := services.GetEtcdInitialCluster(c.EtcdHosts)
for _, host := range c.EtcdHosts { for _, host := range c.EtcdHosts {
if err := services.RestoreEtcdSnapshot(ctx, host, c.PrivateRegistriesMap, c.SystemImages.Etcd, snapshotPath, initCluster); err != nil { if err := services.RestoreEtcdSnapshot(ctx, host, c.PrivateRegistriesMap, c.SystemImages.Etcd, snapshotPath, initCluster, c.Services.Etcd); err != nil {
return fmt.Errorf("[etcd] Failed to restore etcd snapshot: %v", err) return fmt.Errorf("[etcd] Failed to restore etcd snapshot: %v", err)
} }
} }

View File

@ -288,6 +288,7 @@ func RunEtcdSnapshotSave(ctx context.Context, etcdHost *hosts.Host, prsMap map[s
"--endpoints=" + etcdHost.InternalAddress + ":2379", "--endpoints=" + etcdHost.InternalAddress + ":2379",
}, },
Image: etcdSnapshotImage, Image: etcdSnapshotImage,
Env: es.ExtraEnv,
} }
if once { if once {
log.Infof(ctx, "[etcd] Running snapshot save once on host [%s]", etcdHost.Address) log.Infof(ctx, "[etcd] Running snapshot save once on host [%s]", etcdHost.Address)
@ -370,6 +371,7 @@ func DownloadEtcdSnapshotFromS3(ctx context.Context, etcdHost *hosts.Host, prsMa
"--s3-region=" + s3Backend.Region, "--s3-region=" + s3Backend.Region,
}, },
Image: etcdSnapshotImage, Image: etcdSnapshotImage,
Env: es.ExtraEnv,
} }
if s3Backend.CustomCA != "" { if s3Backend.CustomCA != "" {
caStr := base64.StdEncoding.EncodeToString([]byte(s3Backend.CustomCA)) caStr := base64.StdEncoding.EncodeToString([]byte(s3Backend.CustomCA))
@ -402,7 +404,7 @@ func DownloadEtcdSnapshotFromS3(ctx context.Context, etcdHost *hosts.Host, prsMa
return docker.RemoveContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdDownloadBackupContainerName) return docker.RemoveContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdDownloadBackupContainerName)
} }
func RestoreEtcdSnapshot(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, etcdRestoreImage, snapshotName, initCluster string) error { func RestoreEtcdSnapshot(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, etcdRestoreImage, snapshotName, initCluster string, es v3.ETCDService) error {
log.Infof(ctx, "[etcd] Restoring [%s] snapshot on etcd host [%s]", snapshotName, etcdHost.Address) log.Infof(ctx, "[etcd] Restoring [%s] snapshot on etcd host [%s]", snapshotName, etcdHost.Address)
nodeName := pki.GetEtcdCrtName(etcdHost.InternalAddress) nodeName := pki.GetEtcdCrtName(etcdHost.InternalAddress)
snapshotPath := fmt.Sprintf("%s%s", EtcdSnapshotPath, snapshotName) snapshotPath := fmt.Sprintf("%s%s", EtcdSnapshotPath, snapshotName)
@ -427,7 +429,7 @@ func RestoreEtcdSnapshot(ctx context.Context, etcdHost *hosts.Host, prsMap map[s
"&& rm -rf", EtcdRestorePath, "&& rm -rf", EtcdRestorePath,
}, " "), }, " "),
}, },
Env: []string{"ETCDCTL_API=3"}, Env: append([]string{"ETCDCTL_API=3"}, es.ExtraEnv...),
Image: etcdRestoreImage, Image: etcdRestoreImage,
} }
hostCfg := &container.HostConfig{ hostCfg := &container.HostConfig{
@ -478,6 +480,7 @@ func RunEtcdSnapshotRemove(ctx context.Context, etcdHost *hosts.Host, prsMap map
"sh", "-c", fmt.Sprintf("rm -f %s", fullPath), "sh", "-c", fmt.Sprintf("rm -f %s", fullPath),
}, },
Image: etcdSnapshotImage, Image: etcdSnapshotImage,
Env: es.ExtraEnv,
} }
hostCfg := &container.HostConfig{ hostCfg := &container.HostConfig{
Binds: []string{ Binds: []string{