summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2021-02-23 20:18:26 -0800
committerKonrad Bańka <k.banka@samsung.com>2021-04-12 09:52:04 +0200
commit1f60346da61383f18b7277037439711aef38a0fe (patch)
tree620201bbf61283c8db54da8f15d6340bbb813988 /src/k8splugin/plugins
parent120019529489b5cbcf82d77eec228283fb12d43a (diff)
Migrate to use Helm v3 libraries
Moving to Helm v3. Updated unit tests. Reworked Healthcheck Execution to align with v3 design. Helm v3 requires newer version for K8s libraries. Moved to use version 0.19.4. Issue-ID: MULTICLOUD-1295 Signed-off-by: Ritu Sood <ritu.sood@intel.com> Signed-off-by: Konrad Bańka <k.banka@samsung.com> Change-Id: I091b75d69841dde56ad2c294cca2d5a0291ffa8f
Diffstat (limited to 'src/k8splugin/plugins')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go19
-rw-r--r--src/k8splugin/plugins/namespace/plugin.go11
-rw-r--r--src/k8splugin/plugins/service/plugin.go11
3 files changed, 22 insertions, 19 deletions
diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go
index 8cbfcdf5..5f73ad22 100644
--- a/src/k8splugin/plugins/generic/plugin.go
+++ b/src/k8splugin/plugins/generic/plugin.go
@@ -14,6 +14,7 @@ limitations under the License.
package main
import (
+ "context"
pkgerrors "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -77,9 +78,9 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client plug
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- createdObj, err = dynClient.Resource(gvr).Namespace(namespace).Create(unstruct, metav1.CreateOptions{})
+ createdObj, err = dynClient.Resource(gvr).Namespace(namespace).Create(context.TODO(), unstruct, metav1.CreateOptions{})
case meta.RESTScopeNameRoot:
- createdObj, err = dynClient.Resource(gvr).Create(unstruct, metav1.CreateOptions{})
+ createdObj, err = dynClient.Resource(gvr).Create(context.TODO(), unstruct, metav1.CreateOptions{})
default:
return "", pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + gvk.String())
}
@@ -133,9 +134,9 @@ func (g genericPlugin) Update(yamlFilePath string, namespace string, client plug
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- updatedObj, err = dynClient.Resource(gvr).Namespace(namespace).Update(unstruct, metav1.UpdateOptions{})
+ updatedObj, err = dynClient.Resource(gvr).Namespace(namespace).Update(context.TODO(), unstruct, metav1.UpdateOptions{})
case meta.RESTScopeNameRoot:
- updatedObj, err = dynClient.Resource(gvr).Update(unstruct, metav1.UpdateOptions{})
+ updatedObj, err = dynClient.Resource(gvr).Update(context.TODO(), unstruct, metav1.UpdateOptions{})
default:
return "", pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + gvk.String())
}
@@ -170,9 +171,9 @@ func (g genericPlugin) Get(resource helm.KubernetesResource,
var unstruct *unstructured.Unstructured
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- unstruct, err = dynClient.Resource(gvr).Namespace(namespace).Get(resource.Name, opts)
+ unstruct, err = dynClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), resource.Name, opts)
case meta.RESTScopeNameRoot:
- unstruct, err = dynClient.Resource(gvr).Get(resource.Name, opts)
+ unstruct, err = dynClient.Resource(gvr).Get(context.TODO(), resource.Name, opts)
default:
return "", pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + resource.GVK.String())
}
@@ -212,15 +213,15 @@ func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string
gvr := mapping.Resource
deletePolicy := metav1.DeletePropagationForeground
- opts := &metav1.DeleteOptions{
+ opts := metav1.DeleteOptions{
PropagationPolicy: &deletePolicy,
}
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- err = dynClient.Resource(gvr).Namespace(namespace).Delete(resource.Name, opts)
+ err = dynClient.Resource(gvr).Namespace(namespace).Delete(context.TODO(), resource.Name, opts)
case meta.RESTScopeNameRoot:
- err = dynClient.Resource(gvr).Delete(resource.Name, opts)
+ err = dynClient.Resource(gvr).Delete(context.TODO(), resource.Name, opts)
default:
return pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + resource.GVK.String())
}
diff --git a/src/k8splugin/plugins/namespace/plugin.go b/src/k8splugin/plugins/namespace/plugin.go
index cfc395bb..59defa36 100644
--- a/src/k8splugin/plugins/namespace/plugin.go
+++ b/src/k8splugin/plugins/namespace/plugin.go
@@ -14,6 +14,7 @@ limitations under the License.
package main
import (
+ "context"
"log"
pkgerrors "github.com/pkg/errors"
@@ -42,7 +43,7 @@ func (p namespacePlugin) Create(yamlFilePath string, namespace string, client pl
Name: namespace,
},
}
- _, err := client.GetStandardClient().CoreV1().Namespaces().Create(namespaceObj)
+ _, err := client.GetStandardClient().CoreV1().Namespaces().Create(context.TODO(), namespaceObj, metaV1.CreateOptions{})
if err != nil {
return "", pkgerrors.Wrap(err, "Create Namespace error")
}
@@ -54,7 +55,7 @@ func (p namespacePlugin) Create(yamlFilePath string, namespace string, client pl
// Get an existing namespace hosted in a specific Kubernetes cluster
func (p namespacePlugin) Get(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) (string, error) {
opts := metaV1.GetOptions{}
- ns, err := client.GetStandardClient().CoreV1().Namespaces().Get(resource.Name, opts)
+ ns, err := client.GetStandardClient().CoreV1().Namespaces().Get(context.TODO(), resource.Name, opts)
if err != nil {
return "", pkgerrors.Wrap(err, "Get Namespace error")
}
@@ -65,12 +66,12 @@ func (p namespacePlugin) Get(resource helm.KubernetesResource, namespace string,
// Delete an existing namespace hosted in a specific Kubernetes cluster
func (p namespacePlugin) Delete(resource helm.KubernetesResource, namespace string, client plugin.KubernetesConnector) error {
deletePolicy := metaV1.DeletePropagationForeground
- opts := &metaV1.DeleteOptions{
+ opts := metaV1.DeleteOptions{
PropagationPolicy: &deletePolicy,
}
log.Println("Deleting namespace: " + resource.Name)
- if err := client.GetStandardClient().CoreV1().Namespaces().Delete(resource.Name, opts); err != nil {
+ if err := client.GetStandardClient().CoreV1().Namespaces().Delete(context.TODO(), resource.Name, opts); err != nil {
return pkgerrors.Wrap(err, "Delete namespace error")
}
@@ -84,7 +85,7 @@ func (p namespacePlugin) List(gvk schema.GroupVersionKind, namespace string, cli
Limit: utils.ResourcesListLimit,
}
- list, err := client.GetStandardClient().CoreV1().Namespaces().List(opts)
+ list, err := client.GetStandardClient().CoreV1().Namespaces().List(context.TODO(), opts)
if err != nil {
return nil, pkgerrors.Wrap(err, "Get Namespace list error")
}
diff --git a/src/k8splugin/plugins/service/plugin.go b/src/k8splugin/plugins/service/plugin.go
index 28191767..06f4b1d5 100644
--- a/src/k8splugin/plugins/service/plugin.go
+++ b/src/k8splugin/plugins/service/plugin.go
@@ -14,6 +14,7 @@ limitations under the License.
package main
import (
+ "context"
"log"
pkgerrors "github.com/pkg/errors"
@@ -61,7 +62,7 @@ func (p servicePlugin) Create(yamlFilePath string, namespace string, client plug
labels[config.GetConfiguration().KubernetesLabelName] = client.GetInstanceID()
service.SetLabels(labels)
- result, err := client.GetStandardClient().CoreV1().Services(namespace).Create(service)
+ result, err := client.GetStandardClient().CoreV1().Services(namespace).Create(context.TODO(), service, metaV1.CreateOptions{})
if err != nil {
return "", pkgerrors.Wrap(err, "Create Service error")
}
@@ -80,7 +81,7 @@ func (p servicePlugin) List(gvk schema.GroupVersionKind, namespace string, clien
Limit: utils.ResourcesListLimit,
}
- list, err := client.GetStandardClient().CoreV1().Services(namespace).List(opts)
+ list, err := client.GetStandardClient().CoreV1().Services(namespace).List(context.TODO(), opts)
if err != nil {
return nil, pkgerrors.Wrap(err, "Get Service list error")
}
@@ -111,12 +112,12 @@ func (p servicePlugin) Delete(resource helm.KubernetesResource, namespace string
}
deletePolicy := metaV1.DeletePropagationForeground
- opts := &metaV1.DeleteOptions{
+ opts := metaV1.DeleteOptions{
PropagationPolicy: &deletePolicy,
}
log.Println("Deleting service: " + resource.Name)
- if err := client.GetStandardClient().CoreV1().Services(namespace).Delete(resource.Name, opts); err != nil {
+ if err := client.GetStandardClient().CoreV1().Services(namespace).Delete(context.TODO(), resource.Name, opts); err != nil {
return pkgerrors.Wrap(err, "Delete service error")
}
@@ -130,7 +131,7 @@ func (p servicePlugin) Get(resource helm.KubernetesResource, namespace string, c
}
opts := metaV1.GetOptions{}
- service, err := client.GetStandardClient().CoreV1().Services(namespace).Get(resource.Name, opts)
+ service, err := client.GetStandardClient().CoreV1().Services(namespace).Get(context.TODO(), resource.Name, opts)
if err != nil {
return "", pkgerrors.Wrap(err, "Get Service error")
}