we have built an operator via kubebuilder 2.0 successfully.
In this operator, we need to run a cmd in a pod
before we use k8s.io/client-go/kubernetes.Clientset which it grabs restconfig and run like
execReq := o.clientset.CoreV1().RESTClient().Post().
Resource("pods").
Name(Podname).
Namespace("default").
SubResource("exec")
execReq.VersionedParams(&corev1.PodExecOptions{
Command: SqlCommand,
Stdin: true,
Stdout: true,
Stderr: true,
}, scheme.ParameterCodec)
exec, err := remotecommand.NewSPDYExecutor(o.restConfig, "POST", execReq.URL())
if err != nil {
return fmt.Errorf("error while creating Executor: %v", err)
}
err = exec.Stream(remotecommand.StreamOptions{
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Tty: false,
})
if err != nil {
return fmt.Errorf("error in Stream: %v", err)
} else {
return nil
}
In the controller-runtime world, I can't find any RESTClient from client of controller-runtime.
https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client
I wonder how we can execute a cmd in a pod from an operator ?
It would be great if we have restclient in controller-runtime.
It could be PR
thank you
/kind feature
https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client/apiutil#RESTClientForGVK is the function that you're looking for.
we have built an operator via kubebuilder 2.0 successfully.
In this operator, we need to run a cmd in a pod
before we use k8s.io/client-go/kubernetes.Clientset which it grabs restconfig and run likeexecReq := o.clientset.CoreV1().RESTClient().Post(). Resource("pods"). Name(Podname). Namespace("default"). SubResource("exec") execReq.VersionedParams(&corev1.PodExecOptions{ Command: SqlCommand, Stdin: true, Stdout: true, Stderr: true, }, scheme.ParameterCodec) exec, err := remotecommand.NewSPDYExecutor(o.restConfig, "POST", execReq.URL()) if err != nil { return fmt.Errorf("error while creating Executor: %v", err) } err = exec.Stream(remotecommand.StreamOptions{ Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, Tty: false, }) if err != nil { return fmt.Errorf("error in Stream: %v", err) } else { return nil }In the controller-runtime world, I can't find any RESTClient from client of controller-runtime.
https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client
I wonder how we can execute a cmd in a pod from an operator ?
It would be great if we have restclient in controller-runtime.
It could be PRthank you
/kind feature
How did you use the RESTClientforGVK. How do you build the arguments to pass to it.
Can you share any example to exec into the pod using this function.
Most helpful comment
How did you use the RESTClientforGVK. How do you build the arguments to pass to it.
Can you share any example to exec into the pod using this function.