kubernetes/client-go

`exec` command timeout

HelloFillip opened this issue · 5 comments

I'm trying to run the equivalent of kubectl exec ... on a pod running on a local Rancher Desktop environment. The kubectl command works as expected, and I can list pods easily with client-go.

However, when trying to run a shell command I'm getting a timeout.

	pods, err := clientset.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))

	namespace := "default"
	podName := "vault-0"
	request := clientset.CoreV1().RESTClient().Post().Resource("pods").Name(podName).Namespace("default").SubResource("exec")


	cmd := []string{
		"sh",
		"touch",
		"/tmp/bobsfile",
	}

	option := &v1.PodExecOptions{
		Command:   cmd,
		Container: "",
		Stdin:     false,
		Stdout:    true,
		Stderr:    true,
		TTY:       false,
	}

	scheme := runtime.NewScheme()
	parameterCodec := runtime.NewParameterCodec(scheme)
	v1.AddToScheme(scheme)

	request.VersionedParams(
		option,
		parameterCodec, 
	)

	exec, err := remotecommand.NewSPDYExecutor(kubeConfig, "POST", request.URL())

	if err != nil {
		print(err.Error())
	}

	err = exec.StreamWithContext(context.Background(), remotecommand.StreamOptions{
		Stdin:  os.Stdin,
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	})

	if err != nil {
		print(err.Error())
	}

Any help is greatly appreciated.

When I removed the Stdin option from remotecommand.StreamOptions it works as expected. I'm running macOS & zsh, if that's impacting this.

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

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

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten