-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Fix missing pod name for kubectl attach #77606
Conversation
Hi @tnqn. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/assign @dims |
/ok-to-test |
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/assign @soltysh |
/assign @liggitt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one comment on placing unknown content into a format string.
also, the same issue exists for exec, can we fix both commands in this PR?
pkg/kubectl/cmd/attach/attach.go
Outdated
@@ -189,7 +189,7 @@ func (o *AttachOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s | |||
fullCmdName = cmdParent.CommandPath() | |||
} | |||
if len(fullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") { | |||
o.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s -n %s' to see all of the containers in this pod.", fullCmdName, o.PodName, o.Namespace) | |||
o.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%%s -n %s' to see all of the containers in this pod.", fullCmdName, o.Namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using SuggestedCmdUsage as a format string means that if fullCmdName or o.Namespace contain %
characters, the output will be malformed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out. I checked Namespace is only allowed to be [a-z0-9]([-a-z0-9]*[a-z0-9])?
, but can't be sure that fullCmdName won't contain %
, it should be kubectl for most cases though.
To avoid potential problem, I move the suggested usage formatting to where it could be done completely. The issue in exec is also addressed.
PTAL. Thanks!
The pod name is missing in suggested cmd usage when executing kubectl attach and exec: "Defaulting container name to master. Use 'kubectl describe pod/ -n default' to see all of the containers in this pod." The PodName is empty in func Complete as the attached Pod isn't populated yet, causing suggested cmd usage imcomplete. This patch renders PodName after it is populated.
/retest |
thanks /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, tnqn, yue9944882 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
The pod name is missing in suggested cmd usage when executing
kubectl attach
:The PodName is empty in func Complete as the attached Pod isn't populated yet, causing suggested cmd usage imcomplete.
This patch renders PodName after it is populated.
Which issue(s) this PR fixes:
Fixes #77604
Special notes for your reviewer:
Does this PR introduce a user-facing change?: