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
merged 1 commit into from Apr 3, 2018

Conversation

@xilabao
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Mar 10, 2017

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-reviewable

This comment has been minimized.

Copy link

k8s-reviewable commented Mar 10, 2017

This change is Reviewable

@xilabao xilabao force-pushed the xilabao:add-apiresources-command branch from f523c7e to 31aebf6 Mar 10, 2017

Example: apiresources_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunApiResources(f, out)
cmdutil.CheckErr(err)

This comment has been minimized.

@shiywang

shiywang Mar 10, 2017

Member

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")

This comment has been minimized.

@shiywang

shiywang Mar 10, 2017

Member

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 {

This comment has been minimized.

@shiywang

shiywang Mar 10, 2017

Member

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

@fabianofranz

This comment has been minimized.

Copy link
Contributor

fabianofranz commented Mar 10, 2017

@xilabao xilabao force-pushed the xilabao:add-apiresources-command branch from 31aebf6 to 9fbe191 Mar 11, 2017

@xilabao

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

adohe commented Mar 12, 2017

Please also take aggregated api-servers into consideration @xilabao

@liggitt

This comment has been minimized.

Copy link
Member

liggitt commented Mar 13, 2017

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

@xilabao

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

liggitt commented Mar 13, 2017

API group

@liggitt

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

adohe 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

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

@xilabao xilabao force-pushed the xilabao:add-apiresources-command branch from 9fbe191 to 7af26ec Mar 13, 2017

@k8s-github-robot k8s-github-robot added size/L and removed size/M labels Mar 13, 2017

@xilabao xilabao force-pushed the xilabao:add-apiresources-command branch from 7af26ec to 5421370 Mar 13, 2017

@xilabao

This comment has been minimized.

Copy link
Contributor Author

xilabao commented Mar 13, 2017

@ALL PTAL

@xilabao

This comment has been minimized.

Copy link
Contributor Author

xilabao commented Mar 14, 2017


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

This comment has been minimized.

@adohe

adohe Mar 16, 2017

Member

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

This comment has been minimized.

@xilabao

xilabao Mar 17, 2017

Author Contributor

Done.

@xilabao xilabao force-pushed the xilabao:add-apiresources-command branch from 5421370 to bd86db0 Mar 17, 2017

@adohe

This comment has been minimized.

Copy link
Member

adohe commented Mar 18, 2017

/assign @adohe

@tengqm

This comment has been minimized.

Copy link
Contributor

tengqm commented Mar 21, 2018

/test pull-kubernetes-e2e-kops-aws

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Mar 21, 2018

@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
Copy link
Contributor

soltysh left a comment

/lgtm
/approve no-issue

@soltysh

This comment has been minimized.

Copy link
Contributor

soltysh commented Mar 21, 2018

/retest

@k8s-github-robot

This comment has been minimized.

Copy link
Contributor

k8s-github-robot commented Mar 23, 2018

[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

This comment has been minimized.

Copy link
Contributor

smarterclayton commented Apr 3, 2018

/approve

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Apr 3, 2018

[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-github-robot

This comment has been minimized.

Copy link
Contributor

k8s-github-robot commented Apr 3, 2018

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

@k8s-github-robot

This comment has been minimized.

Copy link
Contributor

k8s-github-robot commented Apr 3, 2018

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

13 of 14 checks passed

Submit Queue Required Github CI test is not green: pull-kubernetes-e2e-gce
Details
cla/linuxfoundation xilabao authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce Job succeeded.
Details
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details

@tengqm tengqm referenced this pull request Apr 4, 2018

Closed

Document the `kubectl api-resources` command #7958

1 of 2 tasks complete

k8s-github-robot pushed a commit that referenced this pull request May 16, 2018

Kubernetes Submit Queue
Merge pull request #63644 from dixudx/cleanup_apiresources
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

This comment has been minimized.

Copy link

srikumar-b commented Nov 27, 2018

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

@liggitt

This comment has been minimized.

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
You can’t perform that action at this time.