Skip to content

Commit 318e4ed

Browse files
committed
fix: 修复容器shell检测命令
1 parent 13a8968 commit 318e4ed

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/srvconn/conn_k8s_container.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ func FindAvailableShell(opt *ContainerOptions) (shell string, err error) {
203203
for i := range shells {
204204
if err = HasShellInContainer(opt, shells[i]); err == nil {
205205
return shells[i], nil
206+
} else {
207+
logger.Debug(err)
206208
}
207209
}
208210
return "", ErrNotFoundShell
@@ -217,7 +219,8 @@ func HasShellInContainer(opt *ContainerOptions, shell string) error {
217219
if err != nil {
218220
return err
219221
}
220-
command := []string{"which", shell}
222+
testScript := fmt.Sprintf(scriptTmpl, shell)
223+
command := []string{"sh", "-c", testScript}
221224
validateChecker := func(result string) error {
222225
if !strings.HasSuffix(result, shell) {
223226
return fmt.Errorf("%w: %s %s", ErrNotFoundCommand, result, shell)
@@ -321,3 +324,6 @@ func execContainerShell(k8sClient *kubernetes.Clientset, k8sCfg *rest.Config, c
321324
err = exec.Stream(streamOption)
322325
return err
323326
}
327+
328+
var scriptTmpl = `#!/bin/sh
329+
command -v %s`

0 commit comments

Comments
 (0)