// Execute executes a command on a pod
Execute executes a command on a pod
// Execute executes a command on a pod
func (p *podExecutor) Execute(ctx context.Context, options PodExecOptions) error {
	client, err := corev1client.NewForConfig(p.config)
	if err != nil {
		return err
	}
	request := client.RESTClient().
		Post().
		Resource("pods").
		Name(options.Name).
		Namespace(options.Namespace).
		SubResource("exec").
		Param("container", options.Container).
		Param("command", "/bin/sh").
		Param("stdin", "true").
		Param("stdout", "true").
		Param("stderr", "true").
		Param("tty", "false").
		Context(ctx)
	executor, err := remotecommand.NewSPDYExecutor(p.config, http.MethodPost, request.URL())
	if err != nil {
		return fmt.Errorf("failed to initialize the debug executor: %v", err)
	}
	return executor.Stream(remotecommand.StreamOptions{
		Stdin:  strings.NewReader(options.Command),
		Stdout: options.StdOut,
		Stderr: options.StdErr,
		Tty:    false,
	})
}
func ( p * podExecutor ) Execute ( ctx context . Context , options PodExecOptions ) error { client , err := corev1client . NewForConfig ( p . config ) if err != nil { return err } request := client . RESTClient ( ) . Post ( ) . Resource ( " " ) . Name ( options . Name ) . Namespace ( options . Namespace ) . SubResource ( " " ) . Param ( " " , options . Container ) . Param ( " " , " " ) . Param ( " " , " " ) . Param ( " " , " " ) . Param ( " " , " " ) . Param ( " " , " " ) . Context ( ctx ) executor , err := remotecommand . NewSPDYExecutor ( p . config , http . MethodPost , request . URL ( ) ) if err != nil { return fmt . Errorf ( " " , err ) } return executor . Stream ( remotecommand . StreamOptions { Stdin : strings . NewReader ( options . Command ) , Stdout : options . StdOut , Stderr : options . StdErr , Tty : false , } ) }
Execute executes a command on a pod
Execute executes a command on a pod