@@ -21,7 +21,6 @@ import (
21
21
"fmt"
22
22
"reflect"
23
23
24
- "k8s.io/apimachinery/pkg/api/equality"
25
24
"k8s.io/apimachinery/pkg/runtime"
26
25
"k8s.io/apimachinery/pkg/util/validation/field"
27
26
"k8s.io/utils/ptr"
@@ -201,15 +200,17 @@ func (*openStackClusterWebhook) ValidateUpdate(_ context.Context, oldObjRaw, new
201
200
allErrs = append (allErrs , field .Forbidden (field .NewPath ("spec" , "managedSubnets" ), "cannot add or remove subnets" ))
202
201
} else {
203
202
// Build maps of subnets by CIDR
204
- oldSubnetMap := make (map [string ]infrav1.SubnetSpec )
205
- newSubnetMap := make (map [string ]infrav1.SubnetSpec )
203
+ oldSubnetMap := make (map [string ]* infrav1.SubnetSpec )
206
204
207
- for _ , subnet := range oldObj .Spec .ManagedSubnets {
208
- oldSubnetMap [subnet .CIDR ] = subnet
205
+ for i := range oldObj .Spec .ManagedSubnets {
206
+ oldSubnet := & oldObj .Spec .ManagedSubnets [i ]
207
+ oldSubnetMap [oldSubnet .CIDR ] = oldSubnet
209
208
}
210
209
211
210
// Check if all new subnets have matching old subnets with the same CIDR
212
- for _ , newSubnet := range newObj .Spec .ManagedSubnets {
211
+ for i := range newObj .Spec .ManagedSubnets {
212
+ newSubnet := & newObj .Spec .ManagedSubnets [i ]
213
+
213
214
oldSubnet , exists := oldSubnetMap [newSubnet .CIDR ]
214
215
if ! exists {
215
216
allErrs = append (allErrs , field .Forbidden (
@@ -219,34 +220,10 @@ func (*openStackClusterWebhook) ValidateUpdate(_ context.Context, oldObjRaw, new
219
220
continue
220
221
}
221
222
222
- // Check if AllocationPools have changed
223
- if ! equality .Semantic .DeepEqual (oldSubnet .AllocationPools , newSubnet .AllocationPools ) {
224
- allErrs = append (allErrs , field .Forbidden (
225
- field .NewPath ("spec" , "managedSubnets" ).Child ("allocationPools" ),
226
- "cannot modify allocation pools in existing subnet" ,
227
- ))
228
- }
229
-
230
- newSubnetMap [newSubnet .CIDR ] = newSubnet
223
+ // DNSNameservers is mutable
224
+ oldSubnet .DNSNameservers = nil
225
+ newSubnet .DNSNameservers = nil
231
226
}
232
-
233
- // Create modified copies of the subnets with DNSNameservers cleared
234
- oldSubnets := make ([]infrav1.SubnetSpec , 0 , len (oldObj .Spec .ManagedSubnets ))
235
- newSubnets := make ([]infrav1.SubnetSpec , 0 , len (newObj .Spec .ManagedSubnets ))
236
- for _ , subnet := range oldObj .Spec .ManagedSubnets {
237
- subnetCopy := subnet
238
- subnetCopy .DNSNameservers = nil
239
- oldSubnets = append (oldSubnets , subnetCopy )
240
-
241
- if newSubnet , exists := newSubnetMap [subnet .CIDR ]; exists {
242
- newSubnetCopy := newSubnet
243
- newSubnetCopy .DNSNameservers = nil
244
- newSubnets = append (newSubnets , newSubnetCopy )
245
- }
246
- }
247
-
248
- oldObj .Spec .ManagedSubnets = oldSubnets
249
- newObj .Spec .ManagedSubnets = newSubnets
250
227
}
251
228
}
252
229
0 commit comments