Skip to content

Commit

Permalink
fix: 修复容器shell检测命令
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Feb 10, 2022
1 parent 13a8968 commit 318e4ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/srvconn/conn_k8s_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func FindAvailableShell(opt *ContainerOptions) (shell string, err error) {
for i := range shells {
if err = HasShellInContainer(opt, shells[i]); err == nil {
return shells[i], nil
} else {
logger.Debug(err)
}
}
return "", ErrNotFoundShell
Expand All @@ -217,7 +219,8 @@ func HasShellInContainer(opt *ContainerOptions, shell string) error {
if err != nil {
return err
}
command := []string{"which", shell}
testScript := fmt.Sprintf(scriptTmpl, shell)
command := []string{"sh", "-c", testScript}
validateChecker := func(result string) error {
if !strings.HasSuffix(result, shell) {
return fmt.Errorf("%w: %s %s", ErrNotFoundCommand, result, shell)
Expand Down Expand Up @@ -321,3 +324,6 @@ func execContainerShell(k8sClient *kubernetes.Clientset, k8sCfg *rest.Config, c
err = exec.Stream(streamOption)
return err
}

var scriptTmpl = `#!/bin/sh
command -v %s`

0 comments on commit 318e4ed

Please sign in to comment.