Skip to content

Commit

Permalink
OVA: Add random suffix for ova PV and PVC server
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Dec 12, 2023
1 parent cd0ae24 commit 279294f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/controller/provider/ova-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -262,3 +264,17 @@ func (r *Reconciler) isEnforcedRestrictionNamespace(namespaceName string) bool {

return enforceExists && enforceLabel == "restricted" && !(auditExists && auditLabel == "restricted")
}

func generateRandomSuffix() (randomSeed string) {
src := rand.NewSource(time.Now().UnixNano())
rnd := rand.New(src)

// Generate a 6-character random seed
var letters = []int32("abcdefghijklmnopqrstuvwxyz0123456789")
b := make([]int32, 6)
for i := range b {
b[i] = letters[rnd.Intn(len(letters))]
}
randomSeed = string(b)
return
}

0 comments on commit 279294f

Please sign in to comment.