diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-05-01 12:31:14 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-05-02 15:25:21 -0700 |
commit | a2ae972e814f80184033ee75e9715d1d76323410 (patch) | |
tree | 0916ce2ef051b455a76756ba8bd4d9c6d8efd72e /src/k8splugin/internal/app/client.go | |
parent | 2eec43edc8b9a438865422fcf6ae340c2aec036d (diff) |
Create kubeconfig files in kubeconfig dir
The connectivity api should allow the creation
of kubeconfig files in the kubeconfig dir.
Issue-ID: MULTICLOUD-292
Change-Id: I5ecc92622648c6c90b71ffad433a132e191cf4b3
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/app/client.go')
-rw-r--r-- | src/k8splugin/internal/app/client.go | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index 7024420c..158d21de 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -19,6 +19,8 @@ import ( "strings" utils "k8splugin/internal" + "k8splugin/internal/config" + "k8splugin/internal/connection" "k8splugin/internal/helm" pkgerrors "github.com/pkg/errors" @@ -43,12 +45,32 @@ type KubernetesClient struct { restMapper meta.RESTMapper } -// GetKubeClient loads the Kubernetes configuation values stored into the local configuration file -func (k *KubernetesClient) init(configPath string) error { - if configPath == "" { - return pkgerrors.New("config not passed and is not found in ~/.kube. ") +// getKubeConfig uses the connectivity client to get the kubeconfig based on the name +// of the cloudregion. This is written out to a file. +func (k *KubernetesClient) getKubeConfig(cloudregion string) (string, error) { + conn := connection.NewConnectionClient() + kubeConfigPath, err := conn.Download(cloudregion, config.GetConfiguration().KubeConfigDir) + if err != nil { + return "", pkgerrors.Wrap(err, "Downloading kubeconfig") + } + + return kubeConfigPath, nil +} + +// init loads the Kubernetes configuation values stored into the local configuration file +func (k *KubernetesClient) init(cloudregion string) error { + if cloudregion == "" { + return pkgerrors.New("Cloudregion is empty") } + configPath, err := k.getKubeConfig(cloudregion) + if err != nil { + return pkgerrors.Wrap(err, "Get kubeconfig file") + } + + //Remove kubeconfigfile after the clients are created + defer os.Remove(configPath) + config, err := clientcmd.BuildConfigFromFlags("", configPath) if err != nil { return pkgerrors.Wrap(err, "setConfig: Build config from flags raised an error") |