- 
                Notifications
    
You must be signed in to change notification settings  - Fork 418
 
Fix debug command auto-completion #2009
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
base: main
Are you sure you want to change the base?
Fix debug command auto-completion #2009
Conversation
| 
           [APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sudomakeinstall2 The full list of commands accepted by this bot can be found here. 
Needs approval from an approver in each of these files:
 
      Approvers can indicate their approval by writing   | 
    
| 
           /retest  | 
    
    
      
        1 similar comment
      
    
  
    | 
           /retest  | 
    
| // debugCompletionFunc Returns a completion function that completes: | ||
| // 1- pod names that match the toComplete prefix | ||
| // 2- resource types containing pods and nodes which match the toComplete prefix | ||
| func debugCompletionFunc(f kcmdutil.Factory) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { | 
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.
There are many built-in completion functions in kubectl and it is always better to use them. For example, upstream debug uses https://github.com/kubernetes/kubectl/blob/72b3a7e9b0e99ba874ffe7dd85f9dfd756239dd1/pkg/cmd/cmd.go#L393 and some of the oc commands use
Line 83 in beeaf09
| cmd.ValidArgsFunction = completion.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs) | 
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.
I tried this first but it doesn't really fit here. It fits more with oc ACTION resource name rather than oc ACTION resource/name.
For example
$ oc debug [tab]
nodes pods deployments ...
$ oc debug nod[tab] -> oc debug nodes [cursor is placed after space]
but you can't use $ oc debug nodes my-node, oc debug only accepts $ oc debug resource/name
kubectl defines doPodResourceCompletion for this reason.
I don't think upstream debug have auto completion.
| // Standard case, complete pod names | ||
| comps = completion.CompGetResource(f, "pod", toComplete) | ||
| 
               | 
          ||
| validResources := []string{ | 
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.
This list is not fully complete. oc debug supports resources
Line 1021 in beeaf09
| func (o *DebugOptions) approximatePodTemplateForObject(object runtime.Object) (*corev1.PodTemplateSpec, error) { | 
/hold
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.
Added imagestreamimages, imagestreamtags and cronjobs.
I didn't add deploymentConfig since it is deprecated since 4.14.
I can add it if you think it should be here.
Currently `oc debug` auto-completes to files. This commit adds auto-completion for this command. Auto-completion suggests pods and resources that are valid for the debug command. Implemenation is based on `completions.doPodResourceCompletion` examples: ``` $ oc get pods NAME READY STATUS RESTARTS AGE openshift-adp-controller-manager-68d8974985-gsn5b 1/1 Running 0 19d $ oc debug [TAB] cronjobs/ nodes/ daemonsets/ openshift-adp-controller-manager-68d8974985-gsn5b deployments/ pods/ imagestreamimages/ replicasets/ imagestreamtags/ replicationcontrollers/ jobs/ statefulsets/ $ oc debug nodes/vcl01-hv9-ctlplane-[TAB] nodes/vcl01-hv9-ctlplane-0.redhat.com nodes/vcl01-hv9-ctlplane-2.redhat.com nodes/vcl01-hv9-ctlplane-1.redhat.com ``` Signed-off-by: Saeid Askari <[email protected]>
6526b83    to
    73ca38e      
    Compare
  
    | 
           @sudomakeinstall2: The following tests failed, say  
 Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here.  | 
    
| 
           Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting  If this issue is safe to close now please do so with  /lifecycle stale  | 
    
Currently
oc debugauto-completes to files. This commit addsauto-completion for this command. Auto-completion suggests pods and
resources that are valid for the debug command.
Implemenation is based on
completions.doPodResourceCompletionexamples: