Fix the error of kubeconfig's permission in non-root user

Signed-off-by: pixiake <guofeng@yunify.com>
This commit is contained in:
pixiake 2022-03-07 18:08:00 +08:00
parent 5d35a194c6
commit 9306010a1d
3 changed files with 26 additions and 4 deletions

View File

@ -22,6 +22,8 @@ archives:
linux: linux
amd64: amd64
arm64: arm64
files:
- none*
checksum:
name_template: 'checksums.txt'
snapshot:

View File

@ -401,8 +401,18 @@ func (s *SyncKubeConfigToWorker) Execute(runtime connector.Runtime) error {
return errors.Wrap(errors.WithStack(err), "sync kube config for normal user failed")
}
chownKubeConfig := "chown -R $(id -u):$(id -g) -R $HOME/.kube"
if _, err := runtime.GetRunner().Cmd(chownKubeConfig, false); err != nil {
userId, err := runtime.GetRunner().Cmd("echo $(id -u)", false)
if err != nil {
return errors.Wrap(errors.WithStack(err), "get user id failed")
}
userGroupId, err := runtime.GetRunner().Cmd("echo $(id -g)", false)
if err != nil {
return errors.Wrap(errors.WithStack(err), "get user group id failed")
}
chownKubeConfig := fmt.Sprintf("chown -R %s:%s -R $HOME/.kube", userId, userGroupId)
if _, err := runtime.GetRunner().SudoCmd(chownKubeConfig, false); err != nil {
return errors.Wrap(errors.WithStack(err), "chown user kube config failed")
}
}

View File

@ -425,8 +425,18 @@ func (s *SyncKubeConfigToWorker) Execute(runtime connector.Runtime) error {
return errors.Wrap(errors.WithStack(err), "sync kube config for normal user failed")
}
chownKubeConfig := "chown -R $(id -u):$(id -g) -R $HOME/.kube"
if _, err := runtime.GetRunner().Cmd(chownKubeConfig, false); err != nil {
userId, err := runtime.GetRunner().Cmd("echo $(id -u)", false)
if err != nil {
return errors.Wrap(errors.WithStack(err), "get user id failed")
}
userGroupId, err := runtime.GetRunner().Cmd("echo $(id -g)", false)
if err != nil {
return errors.Wrap(errors.WithStack(err), "get user group id failed")
}
chownKubeConfig := fmt.Sprintf("chown -R %s:%s -R $HOME/.kube", userId, userGroupId)
if _, err := runtime.GetRunner().SudoCmd(chownKubeConfig, false); err != nil {
return errors.Wrap(errors.WithStack(err), "chown user kube config failed")
}
}