From 63afbd1a74644ece8760229214856fdd57ed7863 Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Tue, 12 Dec 2023 13:24:37 +0200 Subject: [PATCH] OVA: Add random suffix for ova PV and PVC server Signed-off-by: Bella Khizgiyaev --- pkg/controller/provider/ova-setup.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/controller/provider/ova-setup.go b/pkg/controller/provider/ova-setup.go index 37eae5f7d..1810924a5 100644 --- a/pkg/controller/provider/ova-setup.go +++ b/pkg/controller/provider/ova-setup.go @@ -3,8 +3,10 @@ package provider import ( "context" "fmt" + "math/rand" "os" "strings" + "time" api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1" appsv1 "k8s.io/api/apps/v1" @@ -33,14 +35,14 @@ func (r Reconciler) CreateOVAServerDeployment(provider *api.Provider, ctx contex Name: provider.Name, UID: provider.UID, } - pvName := fmt.Sprintf("%s-pv-%s-%s", ovaServer, provider.Name, provider.Namespace) + pvName := fmt.Sprintf("%s-pv-%s-%s-%s", ovaServer, provider.Name, provider.Namespace, generateRandomSuffix()) err = r.createPvForNfs(provider, ctx, ownerReference, pvName) if err != nil { r.Log.Error(err, "Failed to create PV for the OVA server") return } - pvcName := fmt.Sprintf("%s-pvc-%s", ovaServer, provider.Name) + pvcName := fmt.Sprintf("%s-pvc-%s-%s", ovaServer, provider.Name, generateRandomSuffix()) err = r.createPvcForNfs(provider, ctx, ownerReference, pvName, pvcName) if err != nil { r.Log.Error(err, "Failed to create PVC for the OVA server") @@ -262,3 +264,15 @@ func (r *Reconciler) isEnforcedRestrictionNamespace(namespaceName string) bool { return enforceExists && enforceLabel == "restricted" && !(auditExists && auditLabel == "restricted") } + +func generateRandomSuffix() (randomSeed string) { + rand.Seed(time.Now().UnixNano()) + // Generate a 6-character random seed + var letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789") + b := make([]rune, 6) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] + } + randomSeed = string(b) + return +}