aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app
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/internal/app
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/internal/app')
-rw-r--r--src/k8splugin/internal/app/client.go39
-rw-r--r--src/k8splugin/internal/app/instance.go15
2 files changed, 18 insertions, 36 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go
index 85fefe69..00fd8e97 100644
--- a/src/k8splugin/internal/app/client.go
+++ b/src/k8splugin/internal/app/client.go
@@ -16,6 +16,7 @@ limitations under the License.
package app
import (
+ "context"
"io/ioutil"
"os"
"strings"
@@ -33,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
- "k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/disk"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
@@ -67,7 +67,7 @@ func (k *KubernetesClient) getPodsByLabel(namespace string) ([]ResourceStatus, e
listOpts := metav1.ListOptions{
LabelSelector: config.GetConfiguration().KubernetesLabelName + "=" + k.instanceID,
}
- podList, err := client.List(listOpts)
+ podList, err := client.List(context.TODO(), listOpts)
if err != nil {
return nil, pkgerrors.Wrap(err, "Retrieving PodList from cluster")
}
@@ -111,9 +111,9 @@ func (k *KubernetesClient) queryResources(apiVersion, kind, labelSelector, names
var unstrList *unstructured.UnstructuredList
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- unstrList, err = dynClient.Resource(gvr).Namespace(namespace).List(opts)
+ unstrList, err = dynClient.Resource(gvr).Namespace(namespace).List(context.TODO(), opts)
case meta.RESTScopeNameRoot:
- unstrList, err = dynClient.Resource(gvr).List(opts)
+ unstrList, err = dynClient.Resource(gvr).List(context.TODO(), opts)
default:
return nil, pkgerrors.New("Got an unknown RESTScopeName for mapping: " + gvk.String())
}
@@ -128,8 +128,8 @@ func (k *KubernetesClient) queryResources(apiVersion, kind, labelSelector, names
return resp, nil
}
-// getResourcesStatus yields status of given generic resource
-func (k *KubernetesClient) getResourceStatus(res helm.KubernetesResource, namespace string) (ResourceStatus, error) {
+// GetResourcesStatus yields status of given generic resource
+func (k *KubernetesClient) GetResourceStatus(res helm.KubernetesResource, namespace string) (ResourceStatus, error) {
dynClient := k.GetDynamicClient()
mapper := k.GetMapper()
mapping, err := mapper.RESTMapping(schema.GroupKind{
@@ -146,9 +146,9 @@ func (k *KubernetesClient) getResourceStatus(res helm.KubernetesResource, namesp
var unstruct *unstructured.Unstructured
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace:
- unstruct, err = dynClient.Resource(gvr).Namespace(namespace).Get(res.Name, opts)
+ unstruct, err = dynClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), res.Name, opts)
case meta.RESTScopeNameRoot:
- unstruct, err = dynClient.Resource(gvr).Get(res.Name, opts)
+ unstruct, err = dynClient.Resource(gvr).Get(context.TODO(), res.Name, opts)
default:
return ResourceStatus{}, pkgerrors.New("Got an unknown RESTSCopeName for mapping: " + res.GVK.String())
}
@@ -276,7 +276,7 @@ func (k *KubernetesClient) ensureNamespace(namespace string) error {
return nil
}
-func (k *KubernetesClient) createKind(resTempl helm.KubernetesResourceTemplate,
+func (k *KubernetesClient) CreateKind(resTempl helm.KubernetesResourceTemplate,
namespace string) (helm.KubernetesResource, error) {
if _, err := os.Stat(resTempl.FilePath); os.IsNotExist(err) {
@@ -360,7 +360,7 @@ func (k *KubernetesClient) createResources(sortedTemplates []helm.KubernetesReso
var createdResources []helm.KubernetesResource
for _, resTempl := range sortedTemplates {
- resCreated, err := k.createKind(resTempl, namespace)
+ resCreated, err := k.CreateKind(resTempl, namespace)
if err != nil {
return nil, pkgerrors.Wrapf(err, "Error creating kind: %+v", resTempl.GVK)
}
@@ -390,7 +390,7 @@ func (k *KubernetesClient) updateResources(sortedTemplates []helm.KubernetesReso
return updatedResources, nil
}
-func (k *KubernetesClient) deleteKind(resource helm.KubernetesResource, namespace string) error {
+func (k *KubernetesClient) DeleteKind(resource helm.KubernetesResource, namespace string) error {
log.Warn("Deleting Resource", log.Fields{
"gvk": resource.GVK,
"resource": resource.Name,
@@ -412,7 +412,7 @@ func (k *KubernetesClient) deleteKind(resource helm.KubernetesResource, namespac
func (k *KubernetesClient) deleteResources(resources []helm.KubernetesResource, namespace string) error {
//TODO: Investigate if deletion should be in a particular order
for _, res := range resources {
- err := k.deleteKind(res, namespace)
+ err := k.DeleteKind(res, namespace)
if err != nil {
return pkgerrors.Wrap(err, "Deleting resources")
}
@@ -443,18 +443,3 @@ func (k *KubernetesClient) GetStandardClient() kubernetes.Interface {
func (k *KubernetesClient) GetInstanceID() string {
return k.instanceID
}
-
-//Following set of methods are implemented so that KubernetesClient
-//implements genericclioptions.RESTClientGetter interface
-func (k *KubernetesClient) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
- return k.discoverClient, nil
-}
-func (k *KubernetesClient) ToRESTMapper() (meta.RESTMapper, error) {
- return k.GetMapper(), nil
-}
-func (k *KubernetesClient) ToRawKubeConfigLoader() clientcmd.ClientConfig {
- return k.rawConfig
-}
-func (k *KubernetesClient) ToRESTConfig() (*rest.Config, error) {
- return k.restConfig, nil
-}
diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go
index c3d3d207..c1ec35b6 100644
--- a/src/k8splugin/internal/app/instance.go
+++ b/src/k8splugin/internal/app/instance.go
@@ -19,16 +19,13 @@ package app
import (
"encoding/json"
- "log"
- "strings"
-
- "k8s.io/apimachinery/pkg/runtime/schema"
- protorelease "k8s.io/helm/pkg/proto/hapi/release"
-
"github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/helm"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/namegenerator"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/rb"
+ "k8s.io/apimachinery/pkg/runtime/schema"
+ "log"
+ "strings"
pkgerrors "github.com/pkg/errors"
)
@@ -52,7 +49,7 @@ type InstanceResponse struct {
Namespace string `json:"namespace"`
ReleaseName string `json:"release-name"`
Resources []helm.KubernetesResource `json:"resources"`
- Hooks []*protorelease.Hook `json:"-"`
+ Hooks []*helm.Hook `json:"-"`
}
// InstanceMiniResponse contains the response from instantiation
@@ -264,7 +261,7 @@ func (v *InstanceClient) Query(id, apiVersion, kind, name, labels string) (Insta
Name: name,
GVK: schema.FromAPIVersionAndKind(apiVersion, kind),
}
- res, err := k8sClient.getResourceStatus(resIdentifier, resResp.Namespace)
+ res, err := k8sClient.GetResourceStatus(resIdentifier, resResp.Namespace)
if err != nil {
return InstanceStatus{}, pkgerrors.Wrap(err, "Querying Resource")
}
@@ -323,7 +320,7 @@ Main:
continue Main //Don't double check pods if someone decided to define pod explicitly in helm chart
}
}
- status, err := k8sClient.getResourceStatus(resource, resResp.Namespace)
+ status, err := k8sClient.GetResourceStatus(resource, resResp.Namespace)
if err != nil {
cumulatedErrorMsg = append(cumulatedErrorMsg, err.Error())
} else {