@@ -98,7 +98,7 @@ var _ = Describe("BIOSSettings Webhook", func() {
9898 Expect (k8sClient .Create (ctx , biosSettingsV2 )).To (Succeed ())
9999 })
100100
101- It ("should deny update if spec.serverRef is duplicate" , func () {
101+ It ("should deny update if spec.serverRef and version are both duplicate" , func () {
102102 By ("Creating a BIOSSettings with different ServerRef" )
103103 biosSettingsV2 := & metalv1alpha1.BIOSSettings {
104104 ObjectMeta : metav1.ObjectMeta {
@@ -119,12 +119,67 @@ var _ = Describe("BIOSSettings Webhook", func() {
119119 }
120120 Expect (k8sClient .Create (ctx , biosSettingsV2 )).To (Succeed ())
121121
122- By ("Updating an biosSettingsV2 with a conflicting ServerRef" )
122+ By ("Updating biosSettingsV2 with both a conflicting ServerRef and matching version " )
123123 biosSettingsV2Updated := biosSettingsV2 .DeepCopy ()
124124 biosSettingsV2Updated .Spec .ServerRef = & v1.LocalObjectReference {Name : "foo" }
125+ biosSettingsV2Updated .Spec .Version = defaultMockUpServerBiosVersion
125126 Expect (validator .ValidateUpdate (ctx , biosSettingsV2 , biosSettingsV2Updated )).Error ().To (HaveOccurred ())
126127 })
127128
129+ It ("should allow update if spec.serverRef changes to an existing one but version differs" , func () {
130+ By ("Creating a BIOSSettings with different ServerRef" )
131+ biosSettingsV2 := & metalv1alpha1.BIOSSettings {
132+ ObjectMeta : metav1.ObjectMeta {
133+ GenerateName : "test-" ,
134+ },
135+ Spec : metalv1alpha1.BIOSSettingsSpec {
136+ ServerRef : & v1.LocalObjectReference {Name : "bar" },
137+ BIOSSettingsTemplate : metalv1alpha1.BIOSSettingsTemplate {
138+ Version : anotherMockUpServerBiosVersion ,
139+ SettingsFlow : []metalv1alpha1.SettingsFlowItem {{
140+ Settings : map [string ]string {},
141+ Priority : 1 ,
142+ Name : "one" ,
143+ }},
144+ ServerMaintenancePolicy : metalv1alpha1 .ServerMaintenancePolicyEnforced ,
145+ },
146+ },
147+ }
148+ Expect (k8sClient .Create (ctx , biosSettingsV2 )).To (Succeed ())
149+
150+ By ("Updating biosSettingsV2 with a serverRef matching V1 but a different version" )
151+ biosSettingsV2Updated := biosSettingsV2 .DeepCopy ()
152+ biosSettingsV2Updated .Spec .ServerRef = & v1.LocalObjectReference {Name : "foo" }
153+ Expect (validator .ValidateUpdate (ctx , biosSettingsV2 , biosSettingsV2Updated )).Error ().ToNot (HaveOccurred ())
154+ })
155+
156+ It ("should allow update when spec.serverRef is unchanged even if version now matches another record" , func () {
157+ By ("Creating a BIOSSettings with different ServerRef" )
158+ biosSettingsV2 := & metalv1alpha1.BIOSSettings {
159+ ObjectMeta : metav1.ObjectMeta {
160+ GenerateName : "test-" ,
161+ },
162+ Spec : metalv1alpha1.BIOSSettingsSpec {
163+ ServerRef : & v1.LocalObjectReference {Name : "bar" },
164+ BIOSSettingsTemplate : metalv1alpha1.BIOSSettingsTemplate {
165+ Version : anotherMockUpServerBiosVersion ,
166+ SettingsFlow : []metalv1alpha1.SettingsFlowItem {{
167+ Settings : map [string ]string {},
168+ Priority : 1 ,
169+ Name : "one" ,
170+ }},
171+ ServerMaintenancePolicy : metalv1alpha1 .ServerMaintenancePolicyEnforced ,
172+ },
173+ },
174+ }
175+ Expect (k8sClient .Create (ctx , biosSettingsV2 )).To (Succeed ())
176+
177+ By ("Updating biosSettingsV2 version to match V1 without changing serverRef" )
178+ biosSettingsV2Updated := biosSettingsV2 .DeepCopy ()
179+ biosSettingsV2Updated .Spec .Version = defaultMockUpServerBiosVersion
180+ Expect (validator .ValidateUpdate (ctx , biosSettingsV2 , biosSettingsV2Updated )).Error ().ToNot (HaveOccurred ())
181+ })
182+
128183 It ("should allow update if a different field is duplicate" , func () {
129184 By ("Creating a BIOSSetting with different ServerRef" )
130185 biosSettingsV2 := & metalv1alpha1.BIOSSettings {
0 commit comments