From 2fffe3c0fcaef4449666a3b76d3240d1c5c559a8 Mon Sep 17 00:00:00 2001 From: fengxsong Date: Wed, 11 Oct 2023 03:11:52 +0000 Subject: [PATCH] refactor: remove SEALOS_SCP_CHECKSUM env key Signed-off-by: fengxsong --- .../applydrivers/apply_drivers_default.go | 2 +- pkg/ssh/scp.go | 49 +------------------ pkg/system/env.go | 10 +--- 3 files changed, 4 insertions(+), 57 deletions(-) diff --git a/pkg/apply/applydrivers/apply_drivers_default.go b/pkg/apply/applydrivers/apply_drivers_default.go index 9aa9d8667f1..e620a419975 100644 --- a/pkg/apply/applydrivers/apply_drivers_default.go +++ b/pkg/apply/applydrivers/apply_drivers_default.go @@ -275,7 +275,7 @@ func (c *Applier) deleteCluster() error { } func (c *Applier) syncWorkdir() { - if v, _ := system.Get(system.SYNC_WORKDIR_ENV_KEY); v != "" { + if v, _ := system.Get(system.SyncWorkDirEnvKey); v != "" { vb, _ := strconv.ParseBool(v) if !vb { return diff --git a/pkg/ssh/scp.go b/pkg/ssh/scp.go index bbbf90e5ea2..4c6af22e4c5 100644 --- a/pkg/ssh/scp.go +++ b/pkg/ssh/scp.go @@ -20,18 +20,14 @@ import ( "os" "path" "path/filepath" - "strconv" "strings" "time" - "github.com/labring/sealos/pkg/system" - "github.com/pkg/sftp" "github.com/schollz/progressbar/v3" "golang.org/x/crypto/ssh" "github.com/labring/sealos/pkg/utils/file" - "github.com/labring/sealos/pkg/utils/hash" "github.com/labring/sealos/pkg/utils/logger" "github.com/labring/sealos/pkg/utils/progress" ) @@ -198,20 +194,6 @@ func (c *Client) doCopy(client *sftp.Client, host, src, dest string, epu *progre } } } else { - fn := func(host string, name string) bool { - exists, err := checkIfRemoteFileExists(client, name) - if err != nil { - logger.Error("failed to detect remote file exists: %v", err) - } - return exists - } - if isCheckFileMD5() && fn(host, dest) { - rfp, _ := client.Stat(dest) - if lfp.Size() == rfp.Size() && hash.FileDigest(src) == c.RemoteSha256Sum(host, dest) { - logger.Debug("remote dst %s already exists and is the latest version, skip copying process", dest) - return nil - } - } lf, err := os.Open(filepath.Clean(src)) if err != nil { return fmt.Errorf("failed to open: %v", err) @@ -240,37 +222,8 @@ func (c *Client) doCopy(client *sftp.Client, host, src, dest string, epu *progre if err = client.PosixRename(destTmp, dest); err != nil { return fmt.Errorf("failed to rename %s to %s: %v", destTmp, dest, err) } - if isCheckFileMD5() { - dh := c.RemoteSha256Sum(host, dest) - if dh == "" { - // when ssh connection failed, remote sha256 is default to "", so ignore it. - return nil - } - sh := hash.FileDigest(src) - if sh != dh { - return fmt.Errorf("sha256 sum not match %s(%s) != %s(%s), maybe network corruption?", src, sh, dest, dh) - } - } + _ = epu.Add(1) } return nil } - -func checkIfRemoteFileExists(client *sftp.Client, fp string) (bool, error) { - _, err := client.Stat(fp) - if err != nil { - if os.IsNotExist(err) { - return false, nil - } - return false, err - } - return true, nil -} - -func isCheckFileMD5() bool { - if v, err := system.Get(system.ScpChecksumConfigKey); err == nil { - boolVal, _ := strconv.ParseBool(v) - return boolVal - } - return true -} diff --git a/pkg/system/env.go b/pkg/system/env.go index bfd8520ecb5..975c3bee150 100644 --- a/pkg/system/env.go +++ b/pkg/system/env.go @@ -82,18 +82,13 @@ var configOptions = []ConfigOption{ Description: `the log level to be used in buildah modules, either "trace", "debug", "info", "warn", "error", "fatal", or "panic".`, OSEnv: BuildahLogLevelConfigKey, }, - { - Key: ScpChecksumConfigKey, - Description: "whether to check the md5sum value is consistent during the copy process.", - DefaultValue: "false", - }, { Key: ContainerStorageConfEnvKey, Description: "path of container storage config file, setting this env will override the default location", OSEnv: ContainerStorageConfEnvKey, }, { - Key: SYNC_WORKDIR_ENV_KEY, + Key: SyncWorkDirEnvKey, Description: "whether to sync runtime root dir to all master nodes for backup purpose", DefaultValue: "true", }, @@ -106,8 +101,7 @@ const ( BuildahFormatConfigKey = "BUILDAH_FORMAT" BuildahLogLevelConfigKey = "BUILDAH_LOG_LEVEL" ContainerStorageConfEnvKey = "CONTAINERS_STORAGE_CONF" - ScpChecksumConfigKey = "SCP_CHECKSUM" - SYNC_WORKDIR_ENV_KEY = "SYNC_WORKDIR" + SyncWorkDirEnvKey = "SYNC_WORKDIR" ) func (*envSystemConfig) getValueOrDefault(key string) (*ConfigOption, error) {