From fc8153724eeeaaafcbcaf881a27e12e8e6cd1045 Mon Sep 17 00:00:00 2001 From: shravan Date: Fri, 17 Jan 2020 09:51:13 +0530 Subject: [PATCH] added map of kind to list api from swagger document --- pkg/kyverno/apply/command.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/kyverno/apply/command.go b/pkg/kyverno/apply/command.go index bedc2e2ee9..b964ece167 100644 --- a/pkg/kyverno/apply/command.go +++ b/pkg/kyverno/apply/command.go @@ -28,6 +28,25 @@ import ( "k8s.io/client-go/kubernetes/scheme" ) +var kindToListApi = map[string]string{ + "resourcequota": "/api/v1/resourcequotas", + "serviceaccount": "/api/v1/serviceaccounts", + "limitrange": "/api/v1/limitranges", + "replicationcontroller": "/api/v1/replicationcontrollers", + "persistentvolume": "/api/v1/persistentvolumes", + "event": "/api/v1/events", + "persistentvolumeclaim": "/api/v1/persistentvolumeclaims", + "podtemplate": "/api/v1/podtemplates", + "componentstatus": "/api/v1/componentstatuses", + "secret": "/api/v1/secrets", + "service": "/api/v1/services", + "namespace": "/api/v1/namespaces", + "node": "/api/v1/nodes", + "endpoint": "/api/v1/endpoints", + "pod": "/api/v1/pods", + "configmap": "/api/v1/configmaps", +} + func Command() *cobra.Command { var resourcePath, kubeConfig string @@ -127,13 +146,8 @@ func getResourcesOfTypeFromCluster(resourceTypes []string, kubeConfig string) ([ return nil, err } - //var kindToListApi = map[string]string{ - // "pod": "/api/v1/pods", - // "services": "/api/v1/services", - //} - for _, kind := range resourceTypes { - listObjectRaw, err := dClient.RESTClient().Get().RequestURI("/api/v1/" + strings.ToLower(kind) + "s").Do().Raw() + listObjectRaw, err := dClient.RESTClient().Get().RequestURI(kindToListApi[strings.ToLower(kind)]).Do().Raw() if err != nil { log.Println(2, err) }