@@ -315,7 +315,7 @@ func getDNS() (*osconfigv1.DNS, error) {
315
315
return dns , nil
316
316
}
317
317
318
- type machineAdmissionFn func (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList )
318
+ type machineAdmissionFn func (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList )
319
319
320
320
type admissionConfig struct {
321
321
clusterID string
@@ -396,7 +396,7 @@ func getMachineValidatorOperation(platform osconfigv1.PlatformType) machineAdmis
396
396
return validateNutanix
397
397
default :
398
398
// just no-op
399
- return func (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
399
+ return func (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
400
400
return true , []string {}, nil
401
401
}
402
402
}
@@ -441,7 +441,7 @@ func getMachineDefaulterOperation(platformStatus *osconfigv1.PlatformStatus) mac
441
441
return defaultNutanix
442
442
default :
443
443
// just no-op
444
- return func (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
444
+ return func (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
445
445
return true , []string {}, nil
446
446
}
447
447
}
@@ -462,7 +462,7 @@ func (h *machineValidatorHandler) validateMachine(m, oldM *machinev1beta1.Machin
462
462
463
463
errs := validateMachineLifecycleHooks (m , oldM )
464
464
465
- ok , warnings , opErrs := h .webhookOperations (m , h .admissionConfig )
465
+ ok , warnings , opErrs := h .webhookOperations (m , oldM , h .admissionConfig )
466
466
if ! ok {
467
467
errs = append (errs , opErrs ... )
468
468
}
@@ -549,7 +549,7 @@ func (h *machineDefaulterHandler) Default(ctx context.Context, obj runtime.Objec
549
549
m .Labels [machinev1beta1 .MachineClusterIDLabel ] = h .clusterID
550
550
}
551
551
552
- ok , _ , errs := h .webhookOperations (m , h .admissionConfig )
552
+ ok , _ , errs := h .webhookOperations (m , nil , h .admissionConfig )
553
553
if ! ok {
554
554
return errs .ToAggregate ()
555
555
}
@@ -561,7 +561,7 @@ type awsDefaulter struct {
561
561
region string
562
562
}
563
563
564
- func (a awsDefaulter ) defaultAWS (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
564
+ func (a awsDefaulter ) defaultAWS (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
565
565
klog .V (3 ).Infof ("Defaulting AWS providerSpec" )
566
566
567
567
var errs field.ErrorList
@@ -633,7 +633,7 @@ func validateUnknownFields(m *machinev1beta1.Machine, providerSpec interface{})
633
633
return nil
634
634
}
635
635
636
- func validateAWS (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
636
+ func validateAWS (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
637
637
klog .V (3 ).Infof ("Validating AWS providerSpec" )
638
638
639
639
var errs field.ErrorList
@@ -803,7 +803,7 @@ func getDuplicatedTags(tagSpecs []machinev1beta1.TagSpecification) []string {
803
803
return duplicatedTags
804
804
}
805
805
806
- func defaultAzure (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
806
+ func defaultAzure (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
807
807
klog .V (3 ).Infof ("Defaulting Azure providerSpec" )
808
808
809
809
var errs field.ErrorList
@@ -864,7 +864,7 @@ func defaultAzure(m *machinev1beta1.Machine, config *admissionConfig) (bool, []s
864
864
return true , warnings , nil
865
865
}
866
866
867
- func validateAzure (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
867
+ func validateAzure (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
868
868
klog .V (3 ).Infof ("Validating Azure providerSpec" )
869
869
870
870
var errs field.ErrorList
@@ -931,6 +931,18 @@ func validateAzure(m *machinev1beta1.Machine, config *admissionConfig) (bool, []
931
931
fmt .Sprintf ("osDisk.diskSettings.ephemeralStorageLocation can either be omitted or set to %s" , azureEphemeralStorageLocationLocal )))
932
932
}
933
933
934
+ if mOld != nil {
935
+ oldProviderSpec := new (machinev1beta1.AzureMachineProviderSpec )
936
+ if err := unmarshalInto (mOld , oldProviderSpec ); err != nil {
937
+ errs = append (errs , err )
938
+ return false , warnings , errs
939
+ }
940
+ if providerSpec .CapacityReservationGroupID != "" && ! validateAzureImmutabilityForCapacityReservationGroupID (oldProviderSpec .CapacityReservationGroupID , providerSpec .CapacityReservationGroupID ) {
941
+ errs = append (errs , field .Invalid (field .NewPath ("providerSpec" , "capacityReservationGroupID" ),
942
+ providerSpec .CapacityReservationGroupID , "capacityReservationGroupID is immutable" ))
943
+ }
944
+ }
945
+
934
946
if providerSpec .CapacityReservationGroupID != "" {
935
947
err := validateAzureCapacityReservationGroupID (providerSpec .CapacityReservationGroupID )
936
948
if err != nil {
@@ -1031,7 +1043,7 @@ func validateAzureDiagnostics(diagnosticsSpec machinev1beta1.AzureDiagnostics, p
1031
1043
return errs
1032
1044
}
1033
1045
1034
- func defaultGCP (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1046
+ func defaultGCP (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1035
1047
klog .V (3 ).Infof ("Defaulting GCP providerSpec" )
1036
1048
1037
1049
var errs field.ErrorList
@@ -1119,7 +1131,7 @@ func defaultGCPDisks(disks []*machinev1beta1.GCPDisk, clusterID string) []*machi
1119
1131
return disks
1120
1132
}
1121
1133
1122
- func validateGCP (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1134
+ func validateGCP (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1123
1135
klog .V (3 ).Infof ("Validating GCP providerSpec" )
1124
1136
1125
1137
var errs field.ErrorList
@@ -1354,7 +1366,7 @@ func validateGCPServiceAccounts(serviceAccounts []machinev1beta1.GCPServiceAccou
1354
1366
return errs
1355
1367
}
1356
1368
1357
- func defaultVSphere (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1369
+ func defaultVSphere (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1358
1370
klog .V (3 ).Infof ("Defaulting vSphere providerSpec" )
1359
1371
1360
1372
var errs field.ErrorList
@@ -1386,7 +1398,7 @@ func defaultVSphere(m *machinev1beta1.Machine, config *admissionConfig) (bool, [
1386
1398
return true , warnings , nil
1387
1399
}
1388
1400
1389
- func validateVSphere (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1401
+ func validateVSphere (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1390
1402
klog .V (3 ).Infof ("Validating vSphere providerSpec" )
1391
1403
1392
1404
var errs field.ErrorList
@@ -1502,7 +1514,7 @@ func validateVSphereNetwork(network machinev1beta1.NetworkSpec, parentPath *fiel
1502
1514
return errs
1503
1515
}
1504
1516
1505
- func defaultNutanix (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1517
+ func defaultNutanix (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1506
1518
klog .V (3 ).Infof ("Defaulting nutanix providerSpec" )
1507
1519
1508
1520
var errs field.ErrorList
@@ -1534,7 +1546,7 @@ func defaultNutanix(m *machinev1beta1.Machine, config *admissionConfig) (bool, [
1534
1546
return true , warnings , nil
1535
1547
}
1536
1548
1537
- func validateNutanix (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1549
+ func validateNutanix (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1538
1550
klog .V (3 ).Infof ("Validating nutanix providerSpec" )
1539
1551
1540
1552
var errs field.ErrorList
@@ -1843,7 +1855,7 @@ func validateAzureDataDisks(machineName string, spec *machinev1beta1.AzureMachin
1843
1855
return errs
1844
1856
}
1845
1857
1846
- func defaultPowerVS (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1858
+ func defaultPowerVS (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1847
1859
klog .V (3 ).Infof ("Defaulting PowerVS providerSpec" )
1848
1860
1849
1861
var errs field.ErrorList
@@ -1890,7 +1902,7 @@ func defaultPowerVS(m *machinev1beta1.Machine, config *admissionConfig) (bool, [
1890
1902
return true , warnings , nil
1891
1903
}
1892
1904
1893
- func validatePowerVS (m * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1905
+ func validatePowerVS (m , mOld * machinev1beta1.Machine , config * admissionConfig ) (bool , []string , field.ErrorList ) {
1894
1906
klog .V (3 ).Infof ("Validating PowerVS providerSpec" )
1895
1907
1896
1908
var errs field.ErrorList
@@ -2069,6 +2081,10 @@ func validateGVK(gvk schema.GroupVersionKind, platform osconfigv1.PlatformType)
2069
2081
}
2070
2082
}
2071
2083
2084
+ func validateAzureImmutabilityForCapacityReservationGroupID (oldID string , newID string ) bool {
2085
+ return oldID == newID
2086
+ }
2087
+
2072
2088
func validateAzureCapacityReservationGroupID (capacityReservationGroupID string ) error {
2073
2089
id := strings .TrimPrefix (capacityReservationGroupID , azureProviderIDPrefix )
2074
2090
err := parseAzureResourceID (id )
0 commit comments