Export kubernetesClient 53/84753/2
authorKiran Kamineni <kiran.k.kamineni@intel.com>
Tue, 9 Apr 2019 21:11:06 +0000 (14:11 -0700)
committerKiran Kamineni <kiran.k.kamineni@intel.com>
Wed, 10 Apr 2019 07:07:46 +0000 (00:07 -0700)
Export kubernetesClient. There are situations where
this will need to be accessed in the plugins and we need
the definition to be exported for that.

Issue-ID: MULTICLOUD-350
Change-Id: I9eee03ea77e390effd33ed96cbbc25dc4cd09cdd
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
src/k8splugin/internal/app/client.go
src/k8splugin/internal/app/client_test.go
src/k8splugin/internal/app/instance.go

index fa5fdfd..cb6f0ec 100644 (file)
@@ -26,12 +26,12 @@ import (
        "k8s.io/helm/pkg/tiller"
 )
 
-type kubernetesClient struct {
+type KubernetesClient struct {
        clientSet *kubernetes.Clientset
 }
 
 // GetKubeClient loads the Kubernetes configuation values stored into the local configuration file
-func (k *kubernetesClient) init(configPath string) error {
+func (k *KubernetesClient) init(configPath string) error {
        if configPath == "" {
                return pkgerrors.New("config not passed and is not found in ~/.kube. ")
        }
@@ -49,7 +49,7 @@ func (k *kubernetesClient) init(configPath string) error {
        return nil
 }
 
-func (k *kubernetesClient) ensureNamespace(namespace string) error {
+func (k *KubernetesClient) ensureNamespace(namespace string) error {
        namespacePlugin, ok := utils.LoadedPlugins["namespace"]
        if !ok {
                return pkgerrors.New("No plugin for namespace resource found")
@@ -82,7 +82,7 @@ func (k *kubernetesClient) ensureNamespace(namespace string) error {
        return nil
 }
 
-func (k *kubernetesClient) createKind(kind string, files []string, namespace string) ([]string, error) {
+func (k *KubernetesClient) createKind(kind string, files []string, namespace string) ([]string, error) {
 
        log.Println("Processing items of Kind: " + kind)
 
@@ -123,7 +123,7 @@ func (k *kubernetesClient) createKind(kind string, files []string, namespace str
        return resourcesCreated, nil
 }
 
-func (k *kubernetesClient) createResources(resMap map[string][]string,
+func (k *KubernetesClient) createResources(resMap map[string][]string,
        namespace string) (map[string][]string, error) {
 
        err := k.ensureNamespace(namespace)
@@ -163,7 +163,7 @@ func (k *kubernetesClient) createResources(resMap map[string][]string,
        return createdResourceMap, nil
 }
 
-func (k *kubernetesClient) deleteKind(kind string, resources []string, namespace string) error {
+func (k *KubernetesClient) deleteKind(kind string, resources []string, namespace string) error {
        log.Println("Deleting items of Kind: " + kind)
 
        typePlugin, ok := utils.LoadedPlugins[strings.ToLower(kind)]
@@ -187,7 +187,7 @@ func (k *kubernetesClient) deleteKind(kind string, resources []string, namespace
        return nil
 }
 
-func (k *kubernetesClient) deleteResources(resMap map[string][]string, namespace string) error {
+func (k *KubernetesClient) deleteResources(resMap map[string][]string, namespace string) error {
        //TODO: Investigate if deletion should be in a particular order
        for kind, resourceNames := range resMap {
                err := k.deleteKind(kind, resourceNames, namespace)
index 5999cfa..b343643 100644 (file)
@@ -45,7 +45,7 @@ func LoadMockPlugins(krdLoadedPlugins map[string]*plugin.Plugin) error {
 func TestInit(t *testing.T) {
        t.Run("Successfully create Kube Client", func(t *testing.T) {
 
-               kubeClient := kubernetesClient{}
+               kubeClient := KubernetesClient{}
                err := kubeClient.init("../../mock_files/mock_configs/mock_config")
                if err != nil {
                        t.Fatalf("TestGetKubeClient returned an error (%s)", err)
@@ -71,7 +71,7 @@ func TestCreateResources(t *testing.T) {
                t.Fatalf("LoadMockPlugins returned an error (%s)", err)
        }
 
-       k8 := kubernetesClient{
+       k8 := KubernetesClient{
                clientSet: &kubernetes.Clientset{},
        }
 
@@ -100,7 +100,7 @@ func TestDeleteResources(t *testing.T) {
                t.Fatalf("LoadMockPlugins returned an error (%s)", err)
        }
 
-       k8 := kubernetesClient{
+       k8 := KubernetesClient{
                clientSet: &kubernetes.Clientset{},
        }
 
index a5b35fe..93305c3 100644 (file)
@@ -118,7 +118,7 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) {
                return InstanceResponse{}, pkgerrors.Wrap(err, "Error resolving helm charts")
        }
 
-       k8sClient := kubernetesClient{}
+       k8sClient := KubernetesClient{}
        err = k8sClient.init(os.Getenv("KUBE_CONFIG_DIR") + "/" + i.CloudRegion)
        if err != nil {
                return InstanceResponse{}, pkgerrors.Wrap(err, "Getting CloudRegion Information")
@@ -183,7 +183,7 @@ func (v *InstanceClient) Delete(id string) error {
                return pkgerrors.Wrap(err, "Error getting Instance")
        }
 
-       k8sClient := kubernetesClient{}
+       k8sClient := KubernetesClient{}
        err = k8sClient.init(os.Getenv("KUBE_CONFIG_DIR") + "/" + inst.CloudRegion)
        if err != nil {
                return pkgerrors.Wrap(err, "Getting CloudRegion Information")