summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins/generic
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-16 18:09:13 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-16 18:09:27 -0700
commitbf49d552b003072c6bc64ae838a4699c1f4028bd (patch)
tree57c2b6130781f8215b0544e6b6f126ec8e2f8152 /src/k8splugin/plugins/generic
parent244578803033f17781b10be283aef43fa6f0aa60 (diff)
Replace Kind with GroupVersionKind
Kind is not unique to track resources in Kubernetes GroupVersionKind is unique. We are just using that to track our data. It is abstracted behind a couple of new types for templates and resources. This change makes a lot of the old kind based operations redundant and simplified. Issue-ID: MULTICLOUD-573 Change-Id: I8f4ded2ba6a0821a8fbd679dc99ce3a44d805524 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/plugins/generic')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go
index b0cf609c..9073535c 100644
--- a/src/k8splugin/plugins/generic/plugin.go
+++ b/src/k8splugin/plugins/generic/plugin.go
@@ -24,22 +24,12 @@ import (
utils "k8splugin/internal"
"k8splugin/internal/app"
+ "k8splugin/internal/helm"
)
type genericPlugin struct {
}
-var kindToGVRMap = map[string]schema.GroupVersionResource{
- "ConfigMap": schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"},
- "StatefulSet": schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"},
- "Job": schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "jobs"},
- "Pod": schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
- "DaemonSet": schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"},
- "CustomResourceDefinition": schema.GroupVersionResource{
- Group: "apiextensions.k8s.io", Version: "v1beta1", Resource: "customresourcedefinitions",
- },
-}
-
// Create deployment object in a specific Kubernetes cluster
func (g genericPlugin) Create(yamlFilePath string, namespace string, client *app.KubernetesClient) (string, error) {
if namespace == "" {
@@ -79,7 +69,7 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client *app
}
// Delete an existing deployment hosted in a specific Kubernetes cluster
-func (g genericPlugin) Delete(kind string, name string, namespace string, client *app.KubernetesClient) error {
+func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) error {
if namespace == "" {
namespace = "default"
}
@@ -90,14 +80,20 @@ func (g genericPlugin) Delete(kind string, name string, namespace string, client
}
dynClient := client.GetDynamicClient()
- gvr, ok := kindToGVRMap[kind]
- if !ok {
- return pkgerrors.New("GVR not found for: " + kind)
+ mapper := client.GetMapper()
+
+ mapping, err := mapper.RESTMapping(schema.GroupKind{
+ Group: resource.GVK.Group,
+ Kind: resource.GVK.Kind,
+ }, resource.GVK.Version)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Mapping kind to resource error")
}
+ gvr := mapping.Resource
log.Printf("Using gvr: %s, %s, %s", gvr.Group, gvr.Version, gvr.Resource)
- err := dynClient.Resource(gvr).Namespace(namespace).Delete(name, opts)
+ err = dynClient.Resource(gvr).Namespace(namespace).Delete(resource.Name, opts)
if err != nil {
return pkgerrors.Wrap(err, "Delete object error")
}