@@ -19,7 +19,6 @@ package v1beta1_test
19
19
import (
20
20
"context"
21
21
22
- infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
23
22
"github.com/aws/cluster-api-provider-cloudstack/test/dummies"
24
23
. "github.com/onsi/ginkgo"
25
24
. "github.com/onsi/gomega"
@@ -31,6 +30,8 @@ var _ = Describe("CloudStackMachine webhook", func() {
31
30
BeforeEach (func () { // Reset test vars to initial state.
32
31
dummies .SetDummyVars ()
33
32
ctx = context .Background ()
33
+ // Clear out any remaining machines. Ignore errors.
34
+ _ = k8sClient .Delete (ctx , dummies .CSMachine1 )
34
35
})
35
36
36
37
Context ("When creating a CloudStackMachine with all attributes" , func () {
@@ -63,38 +64,45 @@ var _ = Describe("CloudStackMachine webhook", func() {
63
64
})
64
65
})
65
66
66
- Context ( "When updating a CloudStackMachine" , func () {
67
- It ( "Should be rejected by the validating webhooks " , func () {
68
- Ω ( k8sClient . Create ( ctx , dummies . CSMachine1 )). Should ( Succeed ())
67
+ // Need the `-- not template` here to make the context unique. Apparently ginkgo uses startswith.
68
+ Context ( "When updating a CloudStackMachine -- not CloudStackMachineTemplate " , func () {
69
+ forbiddenRegex := "admission webhook.*denied the request.*Forbidden \\ : %s"
69
70
70
- forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\ : %s"
71
- cloudStackMachineUpdate := & infrav1.CloudStackMachine {}
71
+ BeforeEach (func () { // Reset test vars to initial state.
72
+ Ω (k8sClient .Create (ctx , dummies .CSMachine1 )).Should (Succeed ())
73
+ })
72
74
73
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
74
- cloudStackMachineUpdate .Spec .Template = "Template2"
75
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "template" ))
75
+ It ("should reject VM offering updates." , func () {
76
+ dummies .CSMachine1 .Spec .Offering = "ArbitraryUpdateOffering"
77
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).Should (MatchRegexp (forbiddenRegex , "offering" ))
78
+ })
76
79
77
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
78
- cloudStackMachineUpdate .Spec .Offering = "Offering2"
79
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "offering" ))
80
+ It ("should reject VM template updates." , func () {
81
+ dummies .CSMachine1 .Spec .Template = "ArbitraryUpdateTemplate"
82
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).Should (MatchRegexp (forbiddenRegex , "template" ))
83
+ })
80
84
81
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
82
- cloudStackMachineUpdate .Spec .Details = map [string ]string {
83
- "memoryOvercommitRatio" : "1.5" ,
84
- }
85
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "details" ))
85
+ It ("should reject updates to VM details." , func () {
86
+ dummies .CSMachine1 .Spec .Details = map [string ]string {"memoryOvercommitRatio" : "1.5" }
87
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).Should (MatchRegexp (forbiddenRegex , "details" ))
88
+ })
86
89
87
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
88
- cloudStackMachineUpdate .Spec .IdentityRef .Kind = "ConfigMap"
89
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Kind" ))
90
+ It ("should reject identity reference kind udpates." , func () {
91
+ dummies .CSMachine1 .Spec .IdentityRef .Kind = "ConfigMap"
92
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).
93
+ Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Kind" ))
94
+ })
90
95
91
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
92
- cloudStackMachineUpdate .Spec .IdentityRef .Name = "IDentityConfigMap"
93
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Name" ))
96
+ It ("should reject identity reference name udpates." , func () {
97
+ dummies .CSMachine1 .Spec .IdentityRef .Name = "IdentityConfigMap"
98
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).
99
+ Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Name" ))
100
+ })
94
101
95
- dummies .CSMachine1 .DeepCopyInto (cloudStackMachineUpdate )
96
- cloudStackMachineUpdate .Spec .AffinityGroupIDs = []string {"28b907b8-75a7-4214-bd3d-6c61961fc2af" }
97
- Expect (k8sClient .Update (ctx , cloudStackMachineUpdate ).Error ()).Should (MatchRegexp (forbiddenRegex , "AffinityGroupIDs" ))
102
+ It ("should reject udpates to the list of affinty groups." , func () {
103
+ dummies .CSMachine1 .Spec .AffinityGroupIDs = []string {"28b907b8-75a7-4214-bd3d-6c61961fc2af" }
104
+ Ω (k8sClient .Update (ctx , dummies .CSMachine1 ).Error ()).
105
+ Should (MatchRegexp (forbiddenRegex , "AffinityGroupIDs" ))
98
106
})
99
107
})
100
108
})
0 commit comments