diff --git a/cluster/defaults.go b/cluster/defaults.go index 58a5fe6c..2123f1de 100644 --- a/cluster/defaults.go +++ b/cluster/defaults.go @@ -11,7 +11,7 @@ import ( "github.com/rancher/rke/log" "github.com/rancher/rke/services" "github.com/rancher/rke/templates" - "github.com/rancher/types/apis/management.cattle.io/v3" + v3 "github.com/rancher/types/apis/management.cattle.io/v3" ) const ( @@ -201,7 +201,7 @@ func (c *Cluster) setClusterServicesDefaults() { c.Services.Etcd.ExtraArgs[DefaultEtcdHeartbeatIntervalName] = DefaultEtcdHeartbeatIntervalValue } - if c.Services.Etcd.BackupConfig != nil { + if c.Services.Etcd.BackupConfig != nil && c.Services.Etcd.BackupConfig.Enabled != nil && *c.Services.Etcd.BackupConfig.Enabled { if c.Services.Etcd.BackupConfig.IntervalHours == 0 { c.Services.Etcd.BackupConfig.IntervalHours = DefaultEtcdBackupConfigIntervalHours } diff --git a/cluster/etcd.go b/cluster/etcd.go index aa596912..336beeb2 100644 --- a/cluster/etcd.go +++ b/cluster/etcd.go @@ -59,7 +59,7 @@ func (c *Cluster) PrepareBackup(ctx context.Context, snapshotPath string) error if !util.IsRancherBackupSupported(c.SystemImages.Alpine) { log.Warnf(ctx, "Auto local backup sync is not supported in `%s`. Using `%s` instead.", c.SystemImages.Alpine, backupImage) } - if c.Services.Etcd.BackupConfig == nil || // legacy rke local backup + if c.Services.Etcd.BackupConfig == nil || (c.Services.Etcd.BackupConfig.Enabled != nil && !*c.Services.Etcd.BackupConfig.Enabled) || // legacy rke local backup (c.Services.Etcd.BackupConfig != nil && c.Services.Etcd.BackupConfig.S3BackupConfig == nil) { // rancher local backup, no s3 // stop etcd on all etcd nodes, we need this because we start the backup server on the same port for _, host := range c.EtcdHosts { @@ -101,7 +101,9 @@ func (c *Cluster) PrepareBackup(ctx context.Context, snapshotPath string) error } // s3 backup case - if c.Services.Etcd.BackupConfig != nil && c.Services.Etcd.BackupConfig.S3BackupConfig != nil { + if c.Services.Etcd.BackupConfig != nil && + c.Services.Etcd.BackupConfig.Enabled != nil && *c.Services.Etcd.BackupConfig.Enabled && + c.Services.Etcd.BackupConfig.S3BackupConfig != nil { for _, host := range c.EtcdHosts { if err := services.DownloadEtcdSnapshotFromS3(ctx, host, c.PrivateRegistriesMap, backupImage, snapshotPath, c.Services.Etcd); err != nil { return err diff --git a/cluster/validation.go b/cluster/validation.go index 09d2da5e..6c497430 100644 --- a/cluster/validation.go +++ b/cluster/validation.go @@ -8,7 +8,7 @@ import ( "github.com/rancher/rke/log" "github.com/rancher/rke/services" "github.com/rancher/rke/util" - "github.com/rancher/types/apis/management.cattle.io/v3" + v3 "github.com/rancher/types/apis/management.cattle.io/v3" "k8s.io/apimachinery/pkg/util/validation" ) @@ -139,7 +139,8 @@ func validateServicesOptions(c *Cluster) error { } func validateEtcdBackupOptions(c *Cluster) error { - if c.Services.Etcd.BackupConfig != nil { + if c.Services.Etcd.BackupConfig != nil && + c.Services.Etcd.BackupConfig.Enabled != nil && *c.Services.Etcd.BackupConfig.Enabled { if c.Services.Etcd.BackupConfig.S3BackupConfig != nil { if len(c.Services.Etcd.BackupConfig.S3BackupConfig.Endpoint) == 0 { return fmt.Errorf("etcd s3 backup backend endpoint can't be empty") diff --git a/cmd/common.go b/cmd/common.go index 6871b415..68acc175 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -10,7 +10,7 @@ import ( "github.com/rancher/rke/cluster" "github.com/rancher/rke/hosts" "github.com/rancher/rke/log" - "github.com/rancher/types/apis/management.cattle.io/v3" + v3 "github.com/rancher/types/apis/management.cattle.io/v3" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) diff --git a/services/etcd.go b/services/etcd.go index 10d06f30..b6d9e05e 100644 --- a/services/etcd.go +++ b/services/etcd.go @@ -293,7 +293,7 @@ func RunEtcdSnapshotSave(ctx context.Context, etcdHost *hosts.Host, prsMap map[s imageCfg.Cmd = append(imageCfg.Cmd, "--creation="+es.Creation) } - if es.BackupConfig != nil { + if es.BackupConfig != nil && es.BackupConfig.Enabled != nil && *es.BackupConfig.Enabled { imageCfg = configS3BackupImgCmd(ctx, imageCfg, es.BackupConfig) } hostCfg := &container.HostConfig{