Skip to content

Commit

Permalink
refactor: remove SEALOS_SCP_CHECKSUM 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 be94570 commit 2fffe3c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pkg/apply/applydrivers/apply_drivers_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 1 addition & 48 deletions pkg/ssh/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
10 changes: 2 additions & 8 deletions pkg/system/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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) {
Expand Down

0 comments on commit 2fffe3c

Please sign in to comment.