diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-08-23 12:33:06 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-08-26 15:59:36 -0700 |
commit | d6b4c825bcafccb2495566332090778ef922b634 (patch) | |
tree | adc6ac1c4ad94e5ccef1a88992c3c236758a6bc8 /src/k8splugin/internal/app/instance.go | |
parent | dcace0784979890bb986fb078348b4b3ceef146c (diff) |
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 <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/app/instance.go')
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 13 |
1 files changed, 3 insertions, 10 deletions
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) |