From d6b4c825bcafccb2495566332090778ef922b634 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Fri, 23 Aug 2019 12:33:06 -0700 Subject: Add a namegenerator package Adds a namegenerator package which generates readable names for instances. This will go with a small change in the API where we expect instance names and will generate the names if they are not provided. Issue-ID: MULTICLOUD-716 Change-Id: I69d8b7fb62667b8b60f3e02eb26dc937961d26d2 Signed-off-by: Kiran Kamineni --- src/k8splugin/internal/app/instance.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/k8splugin/internal/app/instance.go') diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index cf96d50c..47cea972 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -17,13 +17,12 @@ package app import ( - "encoding/base64" "encoding/json" "log" - "math/rand" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/namegenerator" "github.com/onap/multicloud-k8s/src/k8splugin/internal/rb" pkgerrors "github.com/pkg/errors" @@ -88,13 +87,6 @@ type InstanceClient struct { tagInst string } -// Using 6 bytes of randomness to generate an 8 character string -func generateInstanceID() string { - b := make([]byte, 6) - rand.Read(b) - return base64.URLEncoding.EncodeToString(b) -} - // NewInstanceClient returns an instance of the InstanceClient // which implements the InstanceManager func NewInstanceClient() *InstanceClient { @@ -127,7 +119,8 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) { return InstanceResponse{}, pkgerrors.Wrap(err, "Error resolving helm charts") } - id := generateInstanceID() + // TODO: Only generate if id is not provided + id := namegenerator.Generate() k8sClient := KubernetesClient{} err = k8sClient.init(i.CloudRegion, id) -- cgit 1.2.3-korg