Skip to content

Commit a29c250

Browse files
author
Joshua Reed
committed
Some cleanup.
1 parent f533e3b commit a29c250

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

api/v1beta1/cloudstackcluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Kubernetes Authors.
2+
nfraCopyright 2022 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ type Network struct {
4848
// + optional
4949
Type string `json:"type,omitempty"`
5050

51-
// Name of the infrastructure identity to be used.
51+
// Cloudstack Network Name the cluster is built in.
5252
// +optional
5353
Name string `json:"name"`
5454
}

api/v1beta1/cloudstackcluster_webhook_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
5454
})
5555

5656
It("Should reject a CloudStackCluster with IdentityRef not of kind 'Secret'", func() {
57-
dummies.CSCluster.Spec.IdentityRef.Kind = "ConfigMap"
57+
dummies.CSCluster.Spec.IdentityRef.Kind = "NewType"
5858
Ω(k8sClient.Create(ctx, dummies.CSCluster)).
5959
Should(MatchError(MatchRegexp(forbiddenRegex, "must be a Secret")))
6060
})
@@ -69,7 +69,7 @@ var _ = Describe("CloudStackCluster webhooks", func() {
6969
dummies.CSCluster.Spec.Zones = []infrav1.Zone{dummies.Zone1}
7070
Ω(k8sClient.Update(ctx, dummies.CSCluster)).Should(MatchError(MatchRegexp(forbiddenRegex, "Zones and sub")))
7171
})
72-
It("Should reject updates to CloudStackCluster Zones", func() {
72+
It("Should reject updates to Networks specified in CloudStackCluster Zones", func() {
7373
dummies.CSCluster.Spec.Zones[0].Network.Name = "ArbitraryUpdateNetworkName"
7474
Ω(k8sClient.Update(ctx, dummies.CSCluster)).Should(MatchError(MatchRegexp(forbiddenRegex, "Zones and sub")))
7575
})
@@ -85,12 +85,12 @@ var _ = Describe("CloudStackCluster webhooks", func() {
8585
Should(MatchError(MatchRegexp(forbiddenRegex, "controlplaneendpoint\\.port")))
8686
})
8787
It("Should reject updates to the CloudStackCluster identity reference kind", func() {
88-
dummies.CSCluster.Spec.IdentityRef.Kind = "ConfigMap"
88+
dummies.CSCluster.Spec.IdentityRef.Kind = "NewType"
8989
Ω(k8sClient.Update(ctx, dummies.CSCluster)).
9090
Should(MatchError(MatchRegexp(forbiddenRegex, "identityref\\.kind")))
9191
})
9292
It("Should reject updates to the CloudStackCluster identity reference name", func() {
93-
dummies.CSCluster.Spec.IdentityRef.Name = "ConfigMap"
93+
dummies.CSCluster.Spec.IdentityRef.Name = "NewType"
9494
Ω(k8sClient.Update(ctx, dummies.CSCluster)).
9595
Should(MatchError(MatchRegexp(forbiddenRegex, "identityref\\.name")))
9696
})

controllers/cloudstackmachine_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ func (r *CloudStackMachineReconciler) reconcile(
173173
zones[zidx] = zoneID
174174
zidx++
175175
}
176-
rand.Seed(time.Now().Unix())
177-
randNum := (rand.Int() % len(csCluster.Spec.Zones)) // #nosec G404 -- weack crypt rand doesn't matter here.
176+
randNum := (rand.Int() % len(csCluster.Spec.Zones)) // #nosec G404 -- weak crypt rand doesn't matter here.
178177
csMachine.Status.ZoneID = zones[randNum]
179178
}
180179

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package main
1818

1919
import (
2020
"fmt"
21+
"math/rand"
2122
"os"
2223
"strings"
24+
"time"
2325

2426
"github.com/aws/cluster-api-provider-cloudstack/pkg/cloud"
2527
flag "github.com/spf13/pflag"
@@ -143,6 +145,9 @@ func main() {
143145
os.Exit(1)
144146
}
145147

148+
// Set a random seed for randomly placing CloudStackMachines in Zones.
149+
rand.Seed(time.Now().Unix())
150+
146151
// Register machine and cluster reconcilers with the controller manager.
147152
if err = (&controllers.CloudStackClusterReconciler{
148153
Client: mgr.GetClient(),

test/dummies/vars.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func SetDummyTagVars() {
9292
Tags = map[string]string{Tag1Key: Tag1Val, Tag2Key: Tag2Val}
9393
}
9494

95-
// SetDummyClusterSpecVars resets the values in each of the exported CloudStackMachines related dummy variables.
95+
// SetDummyCSMachineTemplateVars resets the values in each of the exported CloudStackMachinesTemplate dummy variables.
9696
func SetDummyCSMachineTemplateVars() {
9797
CSMachineTemplate1 = &capcv1.CloudStackMachineTemplate{
9898
TypeMeta: metav1.TypeMeta{
@@ -125,7 +125,7 @@ func SetDummyCSMachineTemplateVars() {
125125
}
126126
}
127127

128-
// SetDummyClusterSpecVars resets the values in each of the exported CloudStackMachines related dummy variables.
128+
// SetDummyCSMachineVars resets the values in each of the exported CloudStackMachine dummy variables.
129129
func SetDummyCSMachineVars() {
130130
CSMachine1 = &capcv1.CloudStackMachine{
131131
TypeMeta: metav1.TypeMeta{
@@ -153,8 +153,8 @@ func SetDummyCSMachineVars() {
153153
CSMachine1.ObjectMeta.SetName("test-vm")
154154
}
155155

156-
// SetDummyClusterSpecVars resets the values in each of the exported CloudStackCluster related dummy variables.
157-
// It is intended to be called in BeforeEach( functions.
156+
// SetDummyCAPCClusterVars resets the values in each of the exported CloudStackCluster related dummy variables.
157+
// It is intended to be called in BeforeEach() functions.
158158
func SetDummyCAPCClusterVars() {
159159
DomainID = "FakeDomainID"
160160
Domain = "FakeDomainName"
@@ -199,11 +199,13 @@ func SetDummyCAPCClusterVars() {
199199
}
200200
}
201201

202+
// SetDummyDomainAndAccount sets domain and account in the CSCluster Spec. This is not the default.
202203
func SetDummyDomainAndAccount() {
203204
CSCluster.Spec.Account = Account
204205
CSCluster.Spec.Domain = Domain
205206
}
206207

208+
// SetDummyDomainAndAccount sets domainID in the CSCluster Status. This is not the default.
207209
func SetDummyDomainID() {
208210
CSCluster.Status.DomainID = "FakeDomainID"
209211
}

0 commit comments

Comments
 (0)