diff options
Diffstat (limited to 'src/k8splugin/internal/app')
-rw-r--r-- | src/k8splugin/internal/app/client.go | 16 | ||||
-rw-r--r-- | src/k8splugin/internal/app/client_test.go | 2 | ||||
-rw-r--r-- | src/k8splugin/internal/app/config_backend.go | 4 | ||||
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 8 |
4 files changed, 22 insertions, 8 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index d44f3505..914a8eec 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -39,6 +39,7 @@ type KubernetesClient struct { dynamicClient dynamic.Interface discoverClient discovery.CachedDiscoveryInterface restMapper meta.RESTMapper + instanceID string } // getKubeConfig uses the connectivity client to get the kubeconfig based on the name @@ -55,11 +56,17 @@ func (k *KubernetesClient) getKubeConfig(cloudregion string) (string, error) { } // init loads the Kubernetes configuation values stored into the local configuration file -func (k *KubernetesClient) init(cloudregion string) error { +func (k *KubernetesClient) init(cloudregion string, iid string) error { if cloudregion == "" { return pkgerrors.New("Cloudregion is empty") } + if iid == "" { + return pkgerrors.New("Instance ID is empty") + } + + k.instanceID = iid + configPath, err := k.getKubeConfig(cloudregion) if err != nil { return pkgerrors.Wrap(err, "Get kubeconfig file") @@ -89,6 +96,7 @@ func (k *KubernetesClient) init(cloudregion string) error { } k.restMapper = restmapper.NewDeferredDiscoveryRESTMapper(k.discoverClient) + return nil } @@ -211,3 +219,9 @@ func (k *KubernetesClient) GetDynamicClient() dynamic.Interface { func (k *KubernetesClient) GetStandardClient() kubernetes.Interface { return k.clientSet } + +//GetInstanceID returns the instanceID that is injected into all the +//resources created by the plugin +func (k *KubernetesClient) GetInstanceID() string { + return k.instanceID +} diff --git a/src/k8splugin/internal/app/client_test.go b/src/k8splugin/internal/app/client_test.go index fd293ab0..7001d9e2 100644 --- a/src/k8splugin/internal/app/client_test.go +++ b/src/k8splugin/internal/app/client_test.go @@ -72,7 +72,7 @@ func TestInit(t *testing.T) { kubeClient := KubernetesClient{} // Refer to the connection via its name - err = kubeClient.init("mock_connection") + err = kubeClient.init("mock_connection", "abcdefg") if err != nil { t.Fatalf("TestGetKubeClient returned an error (%s)", err) } diff --git a/src/k8splugin/internal/app/config_backend.go b/src/k8splugin/internal/app/config_backend.go index b31cbac7..6bc145ee 100644 --- a/src/k8splugin/internal/app/config_backend.go +++ b/src/k8splugin/internal/app/config_backend.go @@ -354,7 +354,7 @@ func scheduleResources(c chan configResourceList) { log.Printf("[scheduleResources]: POST %v %v", data.profile, data.resourceTemplates) for _, inst := range resp { k8sClient := KubernetesClient{} - err = k8sClient.init(inst.Request.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion, inst.ID) if err != nil { log.Printf("Getting CloudRegion Information: %s", err.Error()) //Move onto the next cloud region @@ -374,7 +374,7 @@ func scheduleResources(c chan configResourceList) { log.Printf("[scheduleResources]: DELETE %v %v", data.profile, data.resourceTemplates) for _, inst := range resp { k8sClient := KubernetesClient{} - err = k8sClient.init(inst.Request.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion, inst.ID) if err != nil { log.Printf("Getting CloudRegion Information: %s", err.Error()) //Move onto the next cloud region diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index d28fe799..5cfdaea1 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -127,8 +127,10 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) { return InstanceResponse{}, pkgerrors.Wrap(err, "Error resolving helm charts") } + id := generateInstanceID() + k8sClient := KubernetesClient{} - err = k8sClient.init(i.CloudRegion) + err = k8sClient.init(i.CloudRegion, id) if err != nil { return InstanceResponse{}, pkgerrors.Wrap(err, "Getting CloudRegion Information") } @@ -138,8 +140,6 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) { return InstanceResponse{}, pkgerrors.Wrap(err, "Create Kubernetes Resources") } - id := generateInstanceID() - //Compose the return response resp := InstanceResponse{ ID: id, @@ -292,7 +292,7 @@ func (v *InstanceClient) Delete(id string) error { } k8sClient := KubernetesClient{} - err = k8sClient.init(inst.Request.CloudRegion) + err = k8sClient.init(inst.Request.CloudRegion, inst.ID) if err != nil { return pkgerrors.Wrap(err, "Getting CloudRegion Information") } |