Skip to content

Commit

Permalink
feat: add SYNC_WORKDIR env key
Browse files Browse the repository at this point in the history
Signed-off-by: fengxsong <[email protected]>
  • Loading branch information
fengxsong committed Oct 11, 2023
1 parent f8764c8 commit be94570
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/apply/applydrivers/apply_drivers_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"os"
"strconv"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/system/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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) {
Expand Down

0 comments on commit be94570

Please sign in to comment.