kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
9.13k stars 2.95k forks source link

can not exec find cmd use remotecommand #1367

Open testwill opened 4 months ago

testwill commented 4 months 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 4 months 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
                    }
k8s-triage-robot commented 1 month ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 2 weeks ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten