diff --git a/pkg/apply/applydrivers/apply_drivers_default.go b/pkg/apply/applydrivers/apply_drivers_default.go index c2158075ea6..9aa9d8667f1 100644 --- a/pkg/apply/applydrivers/apply_drivers_default.go +++ b/pkg/apply/applydrivers/apply_drivers_default.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "os" + "strconv" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/version" @@ -31,6 +32,7 @@ import ( "github.com/labring/sealos/pkg/constants" "github.com/labring/sealos/pkg/exec" "github.com/labring/sealos/pkg/ssh" + "github.com/labring/sealos/pkg/system" v2 "github.com/labring/sealos/pkg/types/v1beta1" "github.com/labring/sealos/pkg/utils/confirm" "github.com/labring/sealos/pkg/utils/iputils" @@ -273,6 +275,12 @@ func (c *Applier) deleteCluster() error { } func (c *Applier) syncWorkdir() { + if v, _ := system.Get(system.SYNC_WORKDIR_ENV_KEY); v != "" { + vb, _ := strconv.ParseBool(v) + if !vb { + return + } + } workDir := constants.ClusterDir(c.ClusterDesired.Name) logger.Debug("sync workdir: %s", workDir) ipList := c.ClusterDesired.GetMasterIPAndPortList() @@ -295,8 +303,14 @@ func (c *Applier) syncWorkdir() { // save cluster to file after apply func (c *Applier) saveClusterFile() { clusterPath := constants.Clusterfile(c.ClusterDesired.Name) - logger.Debug("save objects into local: %s, objects: %v", clusterPath, c.getWriteBackObjects()) - saveErr := yaml.MarshalFile(clusterPath, c.getWriteBackObjects()...) + objects := c.getWriteBackObjects() + if logger.IsDebugMode() { + out, err := yaml.MarshalConfigs(objects...) + if err == nil { + logger.Debug("save objects into local: %s, objects: %s", clusterPath, string(out)) + } + } + saveErr := yaml.MarshalFile(clusterPath, objects...) if saveErr != nil { logger.Error("failed to serialize into file: %s error, %s", clusterPath, saveErr) } diff --git a/pkg/system/env.go b/pkg/system/env.go index f3825ce1cec..bfd8520ecb5 100644 --- a/pkg/system/env.go +++ b/pkg/system/env.go @@ -92,6 +92,11 @@ var configOptions = []ConfigOption{ Description: "path of container storage config file, setting this env will override the default location", OSEnv: ContainerStorageConfEnvKey, }, + { + Key: SYNC_WORKDIR_ENV_KEY, + Description: "whether to sync runtime root dir to all master nodes for backup purpose", + DefaultValue: "true", + }, } const ( @@ -102,6 +107,7 @@ const ( BuildahLogLevelConfigKey = "BUILDAH_LOG_LEVEL" ContainerStorageConfEnvKey = "CONTAINERS_STORAGE_CONF" ScpChecksumConfigKey = "SCP_CHECKSUM" + SYNC_WORKDIR_ENV_KEY = "SYNC_WORKDIR" ) func (*envSystemConfig) getValueOrDefault(key string) (*ConfigOption, error) {