Skip to content

Commit eb84fb4

Browse files
committed
generatename for templates
1 parent 1529b3d commit eb84fb4

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

pkg/capi/gcp.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
)
2121

2222
const (
23-
gcpMachineTemplateName = "gcp-machine-template"
24-
OnHostMaintenanceTerminate = "Terminate"
25-
OnHostMaintenanceMigrate = "Migrate"
23+
gcpMachineTemplateNamePrefix = "gcp-machine-template-"
24+
OnHostMaintenanceTerminate = "Terminate"
25+
OnHostMaintenanceMigrate = "Migrate"
2626
)
2727

2828
var (
29-
clusterName string
30-
cl client.Client
29+
clusterName string
30+
cl client.Client
31+
gcpMachineTemplateName string
3132
)
3233

3334
var _ = Describe("Cluster API GCP MachineSet", framework.LabelCAPI, framework.LabelDisruptive, Ordered, func() {
@@ -60,6 +61,11 @@ var _ = Describe("Cluster API GCP MachineSet", framework.LabelCAPI, framework.La
6061
framework.CreateCoreCluster(ctx, cl, clusterName, "GCPCluster")
6162
mapiMachineSpec = getGCPMAPIProviderSpec(cl)
6263
})
64+
65+
BeforeEach(func() {
66+
gcpMachineTemplateName = fmt.Sprintf("%s%s", gcpMachineTemplateNamePrefix, framework.GenerateRandomString(6))
67+
})
68+
6369
AfterEach(func() {
6470
if platform != configv1.GCPPlatformType {
6571
// Because AfterEach always runs, even when tests are skipped, we have to
@@ -194,8 +200,15 @@ var _ = Describe("Cluster API GCP MachineSet", framework.LabelCAPI, framework.La
194200
Namespace: framework.ClusterAPINamespace,
195201
Name: gcpMachineTemplateName,
196202
}, createdTemplate)).To(Succeed())
197-
var confidentialComputevalue = *createdTemplate.Spec.Template.Spec.ConfidentialCompute
198-
Expect(fmt.Sprintf("%v", confidentialComputevalue)).To(Equal(fmt.Sprintf("%v", *confidentialCompute)))
203+
204+
var expectedConfidentialComputeValue string
205+
if *confidentialCompute == gcpv1.ConfidentialComputePolicyEnabled {
206+
expectedConfidentialComputeValue = "Enabled"
207+
} else {
208+
expectedConfidentialComputeValue = "Disabled"
209+
}
210+
211+
Expect(fmt.Sprintf("%v", expectedConfidentialComputeValue)).To(Equal(fmt.Sprintf("%v", *confidentialCompute)))
199212
},
200213
Entry("Confidential Compute enabled", &confidentialComputeEnabled),
201214
Entry("Confidential Compute disabled", &confidentialComputeDisabled),

pkg/framework/utils.go

+14
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math/rand"
2324
"net/url"
2425
"strconv"
26+
"time"
2527

2628
"github.com/onsi/gomega"
2729
configv1 "github.com/openshift/api/config/v1"
@@ -113,3 +115,15 @@ func GetControlPlaneHostAndPort(ctx context.Context, cl client.Client) (string,
113115

114116
return apiURL.Hostname(), int32(port), nil
115117
}
118+
func GenerateRandomString(n int) string {
119+
const letters = "abcdefghijklmnopqrstuvwxyz0123456789"
120+
121+
randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
122+
123+
s := make([]byte, n)
124+
for i := range s {
125+
s[i] = letters[randGen.Intn(len(letters))]
126+
}
127+
128+
return string(s)
129+
}

0 commit comments

Comments
 (0)