summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-17 14:51:56 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-17 14:52:00 -0700
commitbb712bce5402d65a3f522b62a6f95bf5e0166e66 (patch)
treeb57b5c0d146ba936dd953619811a7022a9b52fc7 /src
parentbf49d552b003072c6bc64ae838a4699c1f4028bd (diff)
Support non-namespaced objects in generic plugin
Generic plugin is not generic enough right now. It was assuming that objects are namespaced. This patch supports both types based on the Scope field in the mapping. Issue-ID: MULTICLOUD-557 Change-Id: I3ac512243d183b26cbf0aea2962dcd2a6492c887 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go
index 9073535c..f3b2798a 100644
--- a/src/k8splugin/plugins/generic/plugin.go
+++ b/src/k8splugin/plugins/generic/plugin.go
@@ -17,6 +17,7 @@ import (
"log"
pkgerrors "github.com/pkg/errors"
+ "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -59,8 +60,17 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client *app
}
gvr := mapping.Resource
+ var createdObj *unstructured.Unstructured
+
+ switch mapping.Scope.Name() {
+ case meta.RESTScopeNameNamespace:
+ createdObj, err = dynClient.Resource(gvr).Namespace(namespace).Create(unstruct, metav1.CreateOptions{})
+ case meta.RESTScopeNameRoot:
+ createdObj, err = dynClient.Resource(gvr).Create(unstruct, metav1.CreateOptions{})
+ default:
+ return "", pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + gvk.String())
+ }
- createdObj, err := dynClient.Resource(gvr).Namespace(namespace).Create(unstruct, metav1.CreateOptions{})
if err != nil {
return "", pkgerrors.Wrap(err, "Create object error")
}
@@ -93,11 +103,18 @@ func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string
gvr := mapping.Resource
log.Printf("Using gvr: %s, %s, %s", gvr.Group, gvr.Version, gvr.Resource)
- err = dynClient.Resource(gvr).Namespace(namespace).Delete(resource.Name, opts)
+ switch mapping.Scope.Name() {
+ case meta.RESTScopeNameNamespace:
+ err = dynClient.Resource(gvr).Namespace(namespace).Delete(resource.Name, opts)
+ case meta.RESTScopeNameRoot:
+ err = dynClient.Resource(gvr).Delete(resource.Name, opts)
+ default:
+ return pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + resource.GVK.String())
+ }
+
if err != nil {
return pkgerrors.Wrap(err, "Delete object error")
}
-
return nil
}