Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Create a new kubectl command to attach debug container to a running pod #46256

Closed
wants to merge 1 commit into from

Conversation

verb
Copy link
Contributor

@verb verb commented May 22, 2017

What this PR does / why we need it: This is the client command to attach a debug container in a running pod, as proposed in kubernetes/community#649

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #45922

Special notes for your reviewer: This PR depends on kubectl feature gates #46151

Release note:

NONE

Dependencies:

WIP:

  • Need decision from api-machinery on API endpoint

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 22, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: verb
We suggest the following additional approver: brendandburns

Assign the PR to them by writing /assign @brendandburns in a comment when ready.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels May 22, 2017
@verb
Copy link
Contributor Author

verb commented May 23, 2017

/cc @pwittrock

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 23, 2017
@@ -252,6 +255,12 @@ var (

// NewKubectlCommand creates the `kubectl` command and its nested children.
func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command {
if f := os.Getenv("KUBECTL_FEATURE_GATES"); f != "" {
if e := utilfeature.DefaultFeatureGate.Set(f); e != nil {
fmt.Fprintf(err, "Invalid KUBECTL_FEATURE_GATES %q. Available features:\n%s\n", f, strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do strings.Join with "\n\t" instead of just "\n"?

}
g[i].Commands = gc
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that kubectl help debug will fail to print the documentation if the feature is disabled by the environment.
I assume this is what you want, but what if it instead printed information about how to enable the command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's what I intended here, but what you describe could definitely be a better user experience. I'll try to figure out something for this in #46151

cmd := &cobra.Command{
Use: "debug POD [-c CONTAINER] -- COMMAND [args...]",
Short: i18n.T("Run a debug container in a pod"),
Long: "Run a new container inside an existing pod.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the Long help message should also include the word "debug".

return fmt.Errorf("both output and error output must be provided")
}
if p.Debugger == nil || p.PodClient == nil || p.Config == nil {
return fmt.Errorf("client, client config, and debugutor must be provided")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a debugutor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a find/replace fail...

Fixed, thanks.

return err
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do

return t.Safe(fn)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

@verb verb changed the title Create a new kubectl command to attach debug container to a running pod WIP: Create a new kubectl command to attach debug container to a running pod May 25, 2017
)

func NewCmdDebug(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
if !utilfeature.DefaultFeatureGate.Enabled(features.DebugContainers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having kubectl depend on Kubernetes repo is an anti pattern. Don't do this. It either needs to go in one of the staging repos (client-go, etc) or be copied into the kubectl packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttts mentioned wanting to use a separate feature gate in #46151 (comment), I imagine this must be why. Can kubectl depend on apiserver?

I have little preference on how to hide alpha features, so I need guidance from those who do. I mention some trade-offs here: #45922 (comment)

@@ -0,0 +1,231 @@
/*
Copyright 2014 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright

utilfeature "k8s.io/apiserver/pkg/util/feature"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/kubernetes/pkg/api"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New imports from k8s.io/kubernetes are forbidden

"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util/i18n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one too

@pwittrock
Copy link
Member

Hm. I don't want to block this functionality on kubectl deps issues which are hard to address, but don't want to create a bunch of additional work to pull them out.

If we accept the deps for this PR, will you remove the deps after code freeze?

@verb
Copy link
Contributor Author

verb commented May 26, 2017

@pwittrock yesterday there arose some disagreement in api-machinery about this API change, so I'm happy to take a little more time to get deps/alpha gate right and miss the 1.7 deadline. I'm writing up the suggested API change and would value your opinion on it.

@pwittrock
Copy link
Member

@verb great. that takes the pressure off

@xiangpengzhao xiangpengzhao mentioned this pull request May 30, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 2, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 2, 2017
@alexandercampbell
Copy link
Contributor

@verb is this ready for re-review?

@verb
Copy link
Contributor Author

verb commented Jun 14, 2017

@alexandercampbell Not quite yet, I need resolution from api-machinery about naming the api endpoint.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2017
@pwittrock
Copy link
Member

/unassign

kubectl debug runs a debug container in a currently running pod.
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 14, 2017
@k8s-ci-robot
Copy link
Contributor

@verb: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-kops-aws a0e6333 link /test pull-kubernetes-e2e-kops-aws
pull-kubernetes-kubemark-e2e-gce a0e6333 link /test pull-kubernetes-kubemark-e2e-gce
pull-kubernetes-federation-e2e-gce a0e6333 link /test pull-kubernetes-federation-e2e-gce
pull-kubernetes-e2e-gce-etcd3 a0e6333 link /test pull-kubernetes-e2e-gce-etcd3
pull-kubernetes-unit a0e6333 link /test pull-kubernetes-unit
pull-kubernetes-bazel a0e6333 link /test pull-kubernetes-bazel
pull-kubernetes-verify a0e6333 link /test pull-kubernetes-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@pwittrock
Copy link
Member

/unassign

@alexandercampbell
Copy link
Contributor

@verb close for now and re-open when the apimachinery question is resolved?

@verb
Copy link
Contributor Author

verb commented Aug 18, 2017

@alexandercampbell SGTM. Thanks for your patience.

@verb verb closed this Aug 18, 2017
@verb
Copy link
Contributor Author

verb commented Oct 2, 2017

@r2d4 FYI, this is the example kubectl debug PR. It doesn't have the alpha integration, but you can see where it would have gone here: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/alpha.go#L39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: New kubectl command kubectl debug
8 participants