kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.91k stars 2.92k forks source link

can not exec find cmd use remotecommand #1367

Open testwill opened 1 month ago

testwill commented 1 month ago

Is it that the pod itself does not support the find operation? There is a find command in the remote pod, and the pod that executes the remote find has admin privileges? error: command terminated with exit code 1

testwill commented 1 month ago
                    req := clientset.CoreV1().RESTClient().Post().
                        Resource("pods").
                        Name(pod.Name).
                        Namespace(targetNamespace).
                        SubResource("exec")

                    // 设置 Exec 请求的参数
                    req.VersionedParams(&corev1.PodExecOptions{
                        Container: container.Name,
                        Command:   []string{"sh", "-c", "find / -name '*.jar'"},
                        Stdin:     false,
                        Stdout:    true,
                        Stderr:    true,
                    }, clientset.CoreV1().RESTClient().ParameterCodec)

                    // 执行 Exec 请求
                    executor, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
                    if err != nil {
                        log.Printf("Failed to create executor: %v", err)
                        continue
                    }