From 9d71e9114baba71266cded1f4f805cd46a378137 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Tue, 9 Apr 2019 14:11:06 -0700 Subject: Export kubernetesClient 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 --- src/k8splugin/internal/app/client.go | 14 +++++++------- src/k8splugin/internal/app/client_test.go | 6 +++--- src/k8splugin/internal/app/instance.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index fa5fdfd5..cb6f0eca 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -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) diff --git a/src/k8splugin/internal/app/client_test.go b/src/k8splugin/internal/app/client_test.go index 5999cfa0..b3436431 100644 --- a/src/k8splugin/internal/app/client_test.go +++ b/src/k8splugin/internal/app/client_test.go @@ -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{}, } diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index a5b35fef..93305c30 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -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") -- cgit 1.2.3-korg