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 63afbd1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 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,15 @@ func (r *Reconciler) isEnforcedRestrictionNamespace(namespaceName string) bool {

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

func generateRandomSuffix() (randomSeed string) {
rand.Seed(time.Now().UnixNano())

Check failure on line 269 in pkg/controller/provider/ova-setup.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
// 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
}

0 comments on commit 63afbd1

Please sign in to comment.