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

add kubectl api-resources command #42873

Merged

Conversation

xilabao
Copy link
Contributor

@xilabao xilabao commented Mar 10, 2017

What this PR does / why we need it:
As the RBAC role need to be related to resources. I think we can use the command to get the supported resources.

# ./cluster/kubectl.sh api-resources   
NAME                                  SHORTNAMES   APIGROUP                       NAMESPACED   KIND
bindings                                                                          true         Binding
componentstatuses                     cs                                          false        ComponentStatus
configmaps                            cm                                          true         ConfigMap
endpoints                             ep                                          true         Endpoints
events                                ev                                          true         Event
limitranges                           limits                                      true         LimitRange
namespaces                            ns                                          false        Namespace
nodes                                 no                                          false        Node
persistentvolumeclaims                pvc                                         true         PersistentVolumeClaim
persistentvolumes                     pv                                          false        PersistentVolume
pods                                  po                                          true         Pod
podtemplates                                                                      true         PodTemplate
replicationcontrollers                rc                                          true         ReplicationController
resourcequotas                        quota                                       true         ResourceQuota
secrets                                                                           true         Secret
serviceaccounts                       sa                                          true         ServiceAccount
services                              svc                                         true         Service
externaladmissionhookconfigurations                admissionregistration.k8s.io   false        ExternalAdmissionHookConfiguration
initializerconfigurations                          admissionregistration.k8s.io   false        InitializerConfiguration
customresourcedefinitions             crd          apiextensions.k8s.io           false        CustomResourceDefinition
apiservices                                        apiregistration.k8s.io         false        APIService
controllerrevisions                                apps                           true         ControllerRevision
daemonsets                            ds           apps                           true         DaemonSet
deployments                           deploy       apps                           true         Deployment
replicasets                           rs           apps                           true         ReplicaSet
statefulsets                          sts          apps                           true         StatefulSet
tokenreviews                                       authentication.k8s.io          false        TokenReview
localsubjectaccessreviews                          authorization.k8s.io           true         LocalSubjectAccessReview
selfsubjectaccessreviews                           authorization.k8s.io           false        SelfSubjectAccessReview
subjectaccessreviews                               authorization.k8s.io           false        SubjectAccessReview
horizontalpodautoscalers              hpa          autoscaling                    true         HorizontalPodAutoscaler
jobs                                               batch                          true         Job
certificatesigningrequests            csr          certificates.k8s.io            false        CertificateSigningRequest
daemonsets                            ds           extensions                     true         DaemonSet
deployments                           deploy       extensions                     true         Deployment
ingresses                             ing          extensions                     true         Ingress
networkpolicies                       netpol       extensions                     true         NetworkPolicy
podsecuritypolicies                   psp          extensions                     false        PodSecurityPolicy
replicasets                           rs           extensions                     true         ReplicaSet
networkpolicies                       netpol       networking.k8s.io              true         NetworkPolicy
poddisruptionbudgets                  pdb          policy                         true         PodDisruptionBudget
clusterrolebindings                                rbac.authorization.k8s.io      false        ClusterRoleBinding
clusterroles                                       rbac.authorization.k8s.io      false        ClusterRole
rolebindings                                       rbac.authorization.k8s.io      true         RoleBinding
roles                                              rbac.authorization.k8s.io      true         Role
podpresets                                         settings.k8s.io                true         PodPreset
storageclasses                        sc           storage.k8s.io                 false        StorageClass

Which issue this PR fixes: fixes #42932

Special notes for your reviewer:

Release note:

add kubectl api-resources command to discovery of resources

@k8s-ci-robot
Copy link
Contributor

Hi @xilabao. 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 @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 10, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Mar 10, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@xilabao xilabao force-pushed the add-apiresources-command branch from f523c7e to 31aebf6 Compare March 10, 2017 07:18
Example: apiresources_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunApiResources(f, out)
cmdutil.CheckErr(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can move those two lines into one


func RunApiResources(f cmdutil.Factory, output io.Writer) error {
w := tabwriter.NewWriter(output, 10, 4, 3, ' ', 0)
fmt.Fprintln(w, "NAME\tNAMESPACED\tKIND\tVERBS")
Copy link
Contributor

Choose a reason for hiding this comment

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

why not add to HumanReadablePrinter ?

}
sort.Strings(resources)
for _, r := range resources {
if _, err := fmt.Fprintf(w, "%s\t%v\t%s\t%v\n", m[r].Name, m[r].Namespaced, m[r].Kind, m[r].Verbs); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also support other format of output like json, yaml ?

@fabianofranz
Copy link
Contributor

cc @kubernetes/sig-cli-feature-requests @kubernetes/sig-cli-pr-reviews @deads2k @smarterclayton

@xilabao is there a proposal or issue related to this?

@xilabao xilabao force-pushed the add-apiresources-command branch from 31aebf6 to 9fbe191 Compare March 11, 2017 00:26
@xilabao
Copy link
Contributor Author

xilabao commented Mar 11, 2017

@xilabao is there a proposal or issue related to this?

I have just added. #42932

@liggitt
Copy link
Member

liggitt commented Mar 11, 2017

you would also need to know the API group

showing a resource that allows no verbs is debatable

@adohe-zz
Copy link

Please also take aggregated api-servers into consideration @xilabao

@liggitt
Copy link
Member

liggitt commented Mar 13, 2017

If you use discovery data, aggregated servers and TPR data will automatically work

@xilabao
Copy link
Contributor Author

xilabao commented Mar 13, 2017

@liggitt I will updated it. But I have a question. which should we add, api servers or api group?
another question @shiywang mentioned. should we also support other format of output like json, yaml ?

@liggitt
Copy link
Member

liggitt commented Mar 13, 2017

API group

@liggitt
Copy link
Member

liggitt commented Mar 13, 2017

I would not expect someone to use this as an API… if they want that, they should use the actual discovery API

@adohe-zz
Copy link

I would not expect someone to use this as an API… if they want that, they should use the actual discovery API

This is exactly what I expect, we should figure out the real use case of this command.

@xilabao xilabao force-pushed the add-apiresources-command branch from 9fbe191 to 7af26ec Compare March 13, 2017 07:23
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 13, 2017
@xilabao xilabao force-pushed the add-apiresources-command branch from 7af26ec to 5421370 Compare March 13, 2017 07:42
@xilabao
Copy link
Contributor Author

xilabao commented Mar 13, 2017

@ALL PTAL

@xilabao
Copy link
Contributor Author

xilabao commented Mar 14, 2017

@fabianofranz @liggitt @adohe @shiywang PTAL


func RunApiResources(f cmdutil.Factory, output io.Writer) error {
w := printers.GetNewTabWriter(output)
fmt.Fprintln(w, "NAME\tNAMESPACED\tAPIGROUP\tKIND\tVERBS")

Choose a reason for hiding this comment

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

I would expect we move this down before where we really need to output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@xilabao xilabao force-pushed the add-apiresources-command branch from 5421370 to bd86db0 Compare March 17, 2017 00:48
@adohe-zz
Copy link

/assign @adohe

@soltysh soltysh added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Mar 20, 2018
@tengqm
Copy link
Contributor

tengqm commented Mar 21, 2018

/test pull-kubernetes-e2e-kops-aws

@k8s-ci-robot
Copy link
Contributor

@tengqm: you can't request testing unless you are a kubernetes member.

In response to this:

/test pull-kubernetes-e2e-kops-aws

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.

@soltysh soltysh added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 21, 2018
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve no-issue

@soltysh
Copy link
Contributor

soltysh commented Mar 21, 2018

/retest

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@adohe @soltysh @xilabao

Pull Request Labels
  • sig/cli: Pull Request will be escalated to these SIGs if needed.
  • priority/important-longterm: Escalate to the pull request owners; move out of the milestone after 1 attempt.
  • kind/feature: New functionality.
Help

@smarterclayton
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adohe, smarterclayton, soltysh, xilabao

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 3, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 229d2df into kubernetes:master Apr 3, 2018
k8s-github-robot pushed a commit that referenced this pull request May 16, 2018
Automatic merge from submit-queue (batch tested with PRs 63589, 63644, 63861, 63872, 63847). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

cleanup kubectl apiresources

**What this PR does / why we need it**:
#42873 introduce this new subcommand.

This PR does
* binding flags to struct
* some code cleanups

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:
/cc soltysh juanvallejo 

**Release note**:

```release-note
None
```
@srikumar-b
Copy link

Is there a way to query for sub resource like pods/log, pods/status etc?

@liggitt
Copy link
Member

liggitt commented Nov 28, 2018

Is there a way to query for sub resource like pods/log, pods/status etc?

there is not currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

kubectl command to list available resources