diff options
author | Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com> | 2020-06-26 22:22:13 +0000 |
---|---|---|
committer | Ritu Sood <ritu.sood@intel.com> | 2020-06-27 20:11:33 -0700 |
commit | 8f338f5fb69c509439eb7f9ac7cfe7bd47849f8b (patch) | |
tree | 5839a7e861033ec259da8bcf31e496997b6143fe /src/rsync/pkg/app | |
parent | 8e446beb55c68314896f16cb3105816cacc05f84 (diff) |
Remove config and yaml file creation
Signed-off-by: Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>
Issue-ID: MULTICLOUD-1005
Change-Id: Iaa8b70f38cf1fc1f89cf2d95fbe37c242fc44f65
Diffstat (limited to 'src/rsync/pkg/app')
-rw-r--r-- | src/rsync/pkg/app/client.go | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/src/rsync/pkg/app/client.go b/src/rsync/pkg/app/client.go index fb57d46b..49997ed0 100644 --- a/src/rsync/pkg/app/client.go +++ b/src/rsync/pkg/app/client.go @@ -30,7 +30,6 @@ import ( "github.com/onap/multicloud-k8s/src/clm/pkg/cluster" ) -const basePath string = "/tmp/rsync/" // KubernetesClient encapsulates the different clients' interfaces // we need when interacting with a Kubernetes cluster @@ -44,45 +43,25 @@ type KubernetesClient struct { // getKubeConfig uses the connectivity client to get the kubeconfig based on the name // of the clustername. This is written out to a file. -func (k *KubernetesClient) getKubeConfig(clustername string, id string) (string, error) { +func (k *KubernetesClient) getKubeConfig(clustername string, id string) ([]byte, error) { if !strings.Contains(clustername, "+") { - return "", pkgerrors.New("Not a valid cluster name") + return nil, pkgerrors.New("Not a valid cluster name") } strs := strings.Split(clustername, "+") if len(strs) != 2 { - return "", pkgerrors.New("Not a valid cluster name") + return nil, pkgerrors.New("Not a valid cluster name") } kubeConfig, err := cluster.NewClusterClient().GetClusterContent(strs[0], strs[1]) if err != nil { - return "", pkgerrors.New("Get kubeconfig failed") + return nil, pkgerrors.New("Get kubeconfig failed") } - var kubeConfigPath string = basePath + id + "/" + clustername + "/" - - if _, err := os.Stat(kubeConfigPath); os.IsNotExist(err) { - err = os.MkdirAll(kubeConfigPath, 0755) - if err != nil { - return "", err - } - } - kubeConfigPath = kubeConfigPath + "config" - - f, err := os.Create(kubeConfigPath) - defer f.Close() - if err != nil { - return "", err - } dec, err := base64.StdEncoding.DecodeString(kubeConfig.Kubeconfig) if err != nil { - return "", err + return nil, err } - _, err = f.Write(dec) - if err != nil { - return "", err - } - - return kubeConfigPath, nil + return dec, nil } // init loads the Kubernetes configuation values stored into the local configuration file @@ -97,15 +76,12 @@ func (k *KubernetesClient) Init(clustername string, iid string) error { k.instanceID = iid - configPath, err := k.getKubeConfig(clustername, iid) + configData, err := k.getKubeConfig(clustername, iid) 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) + config, err := clientcmd.RESTConfigFromKubeConfig(configData) if err != nil { return pkgerrors.Wrap(err, "setConfig: Build config from flags raised an error") } |