Skip to content

Commit 918f2a5

Browse files
committed
Updated to use komega pattern
1 parent 6cb6b22 commit 918f2a5

File tree

1 file changed

+33
-49
lines changed

1 file changed

+33
-49
lines changed

e2e/machine_migration_vap_tests.go

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MA
7373

7474
Context("spec field restrictions", func() {
7575
It("should prevent updating spec.providerID", func() {
76-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
76+
verifyUpdatePrevented(testMAPIMachine, func() {
7777
providerIDValue := testProviderID
78-
m.Spec.ProviderID = &providerIDValue
78+
testMAPIMachine.Spec.ProviderID = &providerIDValue
7979
}, vapSpecLockedMessage)
8080
})
8181

8282
It("should prevent updating spec.taints", func() {
83-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
84-
m.Spec.Taints = []corev1.Taint{{
83+
verifyUpdatePrevented(testMAPIMachine, func() {
84+
testMAPIMachine.Spec.Taints = []corev1.Taint{{
8585
Key: "test-taint",
8686
Value: testTaintValue,
8787
Effect: corev1.TaintEffectNoSchedule,
@@ -90,23 +90,23 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MA
9090
})
9191

9292
It("should prevent updating spec.metadata", func() {
93-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
94-
if m.Spec.ObjectMeta.Labels == nil {
95-
m.Spec.ObjectMeta.Labels = make(map[string]string)
93+
verifyUpdatePrevented(testMAPIMachine, func() {
94+
if testMAPIMachine.Spec.ObjectMeta.Labels == nil {
95+
testMAPIMachine.Spec.ObjectMeta.Labels = make(map[string]string)
9696
}
97-
m.Spec.ObjectMeta.Labels["test-spec-label"] = testLabelValue
97+
testMAPIMachine.Spec.ObjectMeta.Labels["test-spec-label"] = testLabelValue
9898
}, vapSpecLockedMessage)
9999
})
100-
/* TODO: TO BE Manually Verified
100+
/* TODO: TO BE Manually Verified unable to reproduce frequently
101101
It("should prevent updating spec.providerSpec", func() {
102-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
102+
verifyUpdatePrevented(testMAPIMachine, func() {
103103
// Modify instanceType in providerSpec to trigger VAP
104-
if m.Spec.ProviderSpec.Value != nil && len(m.Spec.ProviderSpec.Value.Raw) > 0 {
104+
if testMAPIMachine.Spec.ProviderSpec.Value != nil && len(testMAPIMachine.Spec.ProviderSpec.Value.Raw) > 0 {
105105
providerSpec := &mapiv1beta1.AWSMachineProviderConfig{}
106-
if err := yaml.Unmarshal(m.Spec.ProviderSpec.Value.Raw, providerSpec); err == nil {
106+
if err := yaml.Unmarshal(testMAPIMachine.Spec.ProviderSpec.Value.Raw, providerSpec); err == nil {
107107
providerSpec.InstanceType = testInstanceType
108108
if modifiedRaw, err := yaml.Marshal(providerSpec); err == nil {
109-
m.Spec.ProviderSpec.Value.Raw = modifiedRaw
109+
testMAPIMachine.Spec.ProviderSpec.Value.Raw = modifiedRaw
110110
}
111111
}
112112
}
@@ -122,40 +122,40 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MA
122122

123123
Context("protected label restrictions", func() {
124124
It("should prevent modifying machine.openshift.io/* labels", func() {
125-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
126-
if m.Labels == nil {
127-
m.Labels = make(map[string]string)
125+
verifyUpdatePrevented(testMAPIMachine, func() {
126+
if testMAPIMachine.Labels == nil {
127+
testMAPIMachine.Labels = make(map[string]string)
128128
}
129-
m.Labels["machine.openshift.io/test-label"] = testLabelValue
129+
testMAPIMachine.Labels["machine.openshift.io/test-label"] = testLabelValue
130130
}, vapProtectedLabelMessage)
131131
})
132132

133133
It("should allow modifying non-protected labels", func() {
134-
verifyUpdateAllowed(testMAPIMachine, func(m *mapiv1beta1.Machine) {
135-
if m.Labels == nil {
136-
m.Labels = make(map[string]string)
134+
verifyUpdateAllowed(testMAPIMachine, func() {
135+
if testMAPIMachine.Labels == nil {
136+
testMAPIMachine.Labels = make(map[string]string)
137137
}
138-
m.Labels["test-label"] = "allowed-value"
138+
testMAPIMachine.Labels["test-label"] = "allowed-value"
139139
})
140140
})
141141
})
142142

143143
Context("protected annotation restrictions", func() {
144144
It("should prevent modifying machine.openshift.io/* annotations", func() {
145-
verifyUpdatePrevented(testMAPIMachine, func(m *mapiv1beta1.Machine) {
146-
if m.Annotations == nil {
147-
m.Annotations = make(map[string]string)
145+
verifyUpdatePrevented(testMAPIMachine, func() {
146+
if testMAPIMachine.Annotations == nil {
147+
testMAPIMachine.Annotations = make(map[string]string)
148148
}
149-
m.Annotations["machine.openshift.io/test-annotation"] = "test-value"
149+
testMAPIMachine.Annotations["machine.openshift.io/test-annotation"] = "test-value"
150150
}, vapProtectedAnnotationMessage)
151151
})
152152

153153
It("should allow modifying non-protected annotations", func() {
154-
verifyUpdateAllowed(testMAPIMachine, func(m *mapiv1beta1.Machine) {
155-
if m.Annotations == nil {
156-
m.Annotations = make(map[string]string)
154+
verifyUpdateAllowed(testMAPIMachine, func() {
155+
if testMAPIMachine.Annotations == nil {
156+
testMAPIMachine.Annotations = make(map[string]string)
157157
}
158-
m.Annotations["test-annotation"] = "allowed-value"
158+
testMAPIMachine.Annotations["test-annotation"] = "allowed-value"
159159
})
160160
})
161161
})
@@ -169,35 +169,19 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MA
169169
})
170170

171171
// verifyUpdatePrevented verifies that a machine update is prevented by VAP
172-
func verifyUpdatePrevented(machine *mapiv1beta1.Machine, updateFunc func(*mapiv1beta1.Machine), expectedError string) {
172+
func verifyUpdatePrevented(machine *mapiv1beta1.Machine, updateFunc func(), expectedError string) {
173173
By("Verifying that machine update is prevented by VAP")
174174

175-
Eventually(func() error {
176-
// Get fresh copy to avoid conflicts
177-
freshMachine := &mapiv1beta1.Machine{}
178-
if err := cl.Get(ctx, client.ObjectKeyFromObject(machine), freshMachine); err != nil {
179-
return err
180-
}
181-
updateFunc(freshMachine)
182-
return cl.Update(ctx, freshMachine)
183-
}, capiframework.WaitMedium, capiframework.RetryMedium).Should(
175+
Eventually(komega.Update(machine, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(
184176
MatchError(ContainSubstring(expectedError)),
185177
"Expected machine update to be blocked by VAP")
186178
}
187179

188180
// verifyUpdateAllowed verifies that a machine update is allowed (not blocked by VAP)
189-
func verifyUpdateAllowed(machine *mapiv1beta1.Machine, updateFunc func(*mapiv1beta1.Machine)) {
181+
func verifyUpdateAllowed(machine *mapiv1beta1.Machine, updateFunc func()) {
190182
By("Verifying that machine update is allowed")
191183

192-
Eventually(func() error {
193-
// Get fresh copy to avoid conflicts
194-
freshMachine := &mapiv1beta1.Machine{}
195-
if err := cl.Get(ctx, client.ObjectKeyFromObject(machine), freshMachine); err != nil {
196-
return err
197-
}
198-
updateFunc(freshMachine)
199-
return cl.Update(ctx, freshMachine)
200-
}, capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
184+
Eventually(komega.Update(machine, updateFunc), capiframework.WaitMedium, capiframework.RetryMedium).Should(Succeed(),
201185
"Expected machine update to succeed")
202186
}
203187

0 commit comments

Comments
 (0)