@@ -34,6 +34,9 @@ type ClusterResourcesOutput struct {
3434 ImagePullSecretsErrors []byte `json:"cluster-resources/image-pull-secrets-errors.json,omitempty"`
3535 Nodes []byte `json:"cluster-resources/nodes.json,omitempty"`
3636 NodesErrors []byte `json:"cluster-resources/nodes-errors.json,omitempty"`
37+ Groups []byte `json:"cluster-resources/groups.json,omitempty"`
38+ Resources []byte `json:"cluster-resources/resources.json,omitempty"`
39+ GroupsResourcesErrors []byte `json:"cluster-resources/groups-resources-errors.json,omitempty"`
3740
3841 // TODO these should be considered for relocation to an rbac or auth package. cluster resources might not be the right place
3942 AuthCanI map [string ][]byte `json:"cluster-resources/auth-cani-list,omitempty"`
@@ -137,6 +140,14 @@ func ClusterResources(ctx *Context) ([]byte, error) {
137140 return nil , err
138141 }
139142
143+ groups , resources , groupsResourcesErrors := apiResources (client )
144+ clusterResourcesOutput .Groups = groups
145+ clusterResourcesOutput .Resources = resources
146+ clusterResourcesOutput .GroupsResourcesErrors , err = marshalNonNil (groupsResourcesErrors )
147+ if err != nil {
148+ return nil , err
149+ }
150+
140151 // auth cani
141152 authCanI , authCanIErrors := authCanI (client , namespaceNames )
142153 clusterResourcesOutput .AuthCanI = authCanI
@@ -374,6 +385,27 @@ func nodes(client *kubernetes.Clientset) ([]byte, []string) {
374385 return b , nil
375386}
376387
388+ // get the list of API resources, similar to 'kubectl api-resources'
389+ func apiResources (client * kubernetes.Clientset ) ([]byte , []byte , []string ) {
390+ var errorArray []string
391+ groups , resources , err := client .Discovery ().ServerGroupsAndResources ()
392+ if err != nil {
393+ errorArray = append (errorArray , err .Error ())
394+ }
395+
396+ groupBytes , err := json .MarshalIndent (groups , "" , " " )
397+ if err != nil {
398+ errorArray = append (errorArray , err .Error ())
399+ }
400+
401+ resourcesBytes , err := json .MarshalIndent (resources , "" , " " )
402+ if err != nil {
403+ errorArray = append (errorArray , err .Error ())
404+ }
405+
406+ return groupBytes , resourcesBytes , errorArray
407+ }
408+
377409func authCanI (client * kubernetes.Clientset , namespaces []string ) (map [string ][]byte , map [string ]string ) {
378410 // https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/auth/cani.go
379411
@@ -464,6 +496,14 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
464496 if err != nil {
465497 return nil , err
466498 }
499+ groups , err := redact .Redact (c .Groups )
500+ if err != nil {
501+ return nil , err
502+ }
503+ resources , err := redact .Redact (c .Resources )
504+ if err != nil {
505+ return nil , err
506+ }
467507
468508 return & ClusterResourcesOutput {
469509 Namespaces : namespaces ,
@@ -486,5 +526,8 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
486526 ImagePullSecretsErrors : c .ImagePullSecretsErrors ,
487527 AuthCanI : c .AuthCanI ,
488528 AuthCanIErrors : c .AuthCanIErrors ,
529+ Groups : groups ,
530+ Resources : resources ,
531+ GroupsResourcesErrors : c .GroupsResourcesErrors ,
489532 }, nil
490533}
0 commit comments