aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins/generic/plugin.go
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-06-19 22:46:37 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-19 22:46:37 +0000
commit36bd529eefdf43e552f420ab0a1d52fd560b837f (patch)
tree9cc2974f1c6dc91c0e54300a96963aa11bce1780 /src/k8splugin/plugins/generic/plugin.go
parentc1963d4331fce447d93131d731e1f261c175de87 (diff)
parentd780f1b30c98a27d269e3e05423e9e54e0e022f6 (diff)
Merge "Plugin code refactoring"
Diffstat (limited to 'src/k8splugin/plugins/generic/plugin.go')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go68
1 files changed, 58 insertions, 10 deletions
diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go
index 9ecaf68c..31c65d05 100644
--- a/src/k8splugin/plugins/generic/plugin.go
+++ b/src/k8splugin/plugins/generic/plugin.go
@@ -23,15 +23,18 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
utils "k8splugin/internal"
- "k8splugin/internal/app"
+ "k8splugin/internal/plugin"
"k8splugin/internal/helm"
)
+// ExportedVariable is what we will look for when calling the generic plugin
+var ExportedVariable genericPlugin
+
type genericPlugin struct {
}
// Create deployment object in a specific Kubernetes cluster
-func (g genericPlugin) Create(yamlFilePath string, namespace string, client *app.KubernetesClient) (string, error) {
+func (g genericPlugin) Create(yamlFilePath string, namespace string, client plugin.KubernetesConnector) (string, error) {
if namespace == "" {
namespace = "default"
}
@@ -72,15 +75,58 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client *app
return createdObj.GetName(), nil
}
-// Delete an existing deployment hosted in a specific Kubernetes cluster
-func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string, client *app.KubernetesClient) error {
+// Get an existing resource hosted in a specific Kubernetes cluster
+func (g genericPlugin) Get(resource helm.KubernetesResource,
+ namespace string, client plugin.KubernetesConnector) (string, error) {
if namespace == "" {
namespace = "default"
}
- deletePolicy := metav1.DeletePropagationForeground
- opts := &metav1.DeleteOptions{
- PropagationPolicy: &deletePolicy,
+ dynClient := client.GetDynamicClient()
+ 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)
+
+ opts := metav1.GetOptions{}
+ var unstruct *unstructured.Unstructured
+ switch mapping.Scope.Name() {
+ case meta.RESTScopeNameNamespace:
+ unstruct, err = dynClient.Resource(gvr).Namespace(namespace).Get(resource.Name, opts)
+ case meta.RESTScopeNameRoot:
+ unstruct, err = dynClient.Resource(gvr).Get(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 unstruct.GetName(), nil
+}
+
+// List all existing resources of the GroupVersionKind
+// TODO: Implement in seperate patch
+func (g genericPlugin) List(gvk schema.GroupVersionKind, namespace string,
+ client plugin.KubernetesConnector) ([]helm.KubernetesResource, error) {
+
+ var returnData []helm.KubernetesResource
+ return returnData, nil
+}
+
+// Delete an existing resource hosted in a specific Kubernetes cluster
+func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) error {
+ if namespace == "" {
+ namespace = "default"
}
dynClient := client.GetDynamicClient()
@@ -97,6 +143,11 @@ 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)
+ deletePolicy := metav1.DeletePropagationForeground
+ opts := &metav1.DeleteOptions{
+ PropagationPolicy: &deletePolicy,
+ }
+
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
err = dynClient.Resource(gvr).Namespace(namespace).Delete(resource.Name, opts)
@@ -111,6 +162,3 @@ func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string
}
return nil
}
-
-// ExportedVariable is what we will look for when calling the generic plugin
-var ExportedVariable genericPlugin