Skip to content

Commit 7bcd88a

Browse files
authored
Fix(connector): gracefully handle LANG environment setup failures-Update ssh.go (#2552)
* Update ssh.go setenv 会导致在kk 3.1.8/3.1.9 在centos/rockey linux 9.x下ssh fail ,无法部署; 经过验证,不设置语言对在centos/rockey linux 9.x部署没有影响,建议setenv改为尽力而为方式更合适,,设置失败产生Warn即可。 Signed-off-by: zmoon460 <[email protected]> * Update ssh.go 修改Setenv告警日志显示 Localization warning 为Warning ,更符合一般习惯 Signed-off-by: zmoon460 <[email protected]> * Fix: no sudo env export fail Check chown operator Signed-off-by: zmoon460 <[email protected]> * Update ssh.go 部署测试模拟发现,如果设置失败会大量产生这种Warning,可能因为部署过程kk有大量ssh连接操作的缘故,故降到Debug级别 Co-Authored-By: zmoon460 <[email protected]> Signed-off-by: zmoon460 <[email protected]> --------- Signed-off-by: zmoon460 <[email protected]>
1 parent f7f7489 commit 7bcd88a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cmd/kk/pkg/core/connector/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ func (c *connection) session() (*ssh.Session, error) {
259259
}
260260

261261
if err := sess.Setenv("LANG", "en_US.UTF-8"); err != nil { // try make sure work with english language environments
262-
return nil, err
262+
logger.Log.Debugf("Failed to enforce LANG=en_US.UTF-8. (Error: %v)", err)
263263
}
264-
264+
265265
return sess, nil
266266
}
267267

cmd/kk/pkg/filesystem/task.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ package filesystem
1919
import (
2020
"fmt"
2121
"os/exec"
22-
22+
"os"
2323
"github.com/pkg/errors"
2424

2525
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/action"
2626
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/connector"
2727
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/util"
28+
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/logger"
2829
)
2930

3031
type ChownFileAndDir struct {
@@ -64,6 +65,12 @@ type LocalTaskChown struct {
6465

6566
func (l *LocalTaskChown) Execute(runtime connector.Runtime) error {
6667
if exist := util.IsExist(l.Path); exist {
68+
// Check environment variables first
69+
if os.Getenv("SUDO_UID") == "" || os.Getenv("SUDO_GID") == "" {
70+
logger.Log.Infof("Skip chown for %s: SUDO_UID/GID missing (not using sudo)", l.Path)
71+
return nil
72+
}
73+
6774
if err := exec.Command("/bin/sh", "-c", fmt.Sprintf("chown -R ${SUDO_UID}:${SUDO_GID} %s", l.Path)).Run(); err != nil {
6875
return errors.Wrapf(errors.WithStack(err), "chown %s failed", l.Path)
6976
}

0 commit comments

Comments
 (0)