@@ -676,7 +676,7 @@ func validateMachineHealthChecks(cluster *clusterv1.Cluster, clusterClass *clust
676
676
for i := range cluster .Spec .Topology .Workers .MachineDeployments {
677
677
md := cluster .Spec .Topology .Workers .MachineDeployments [i ]
678
678
if md .MachineHealthCheck != nil {
679
- fldPath := field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" , "machineHealthCheck" ). Index ( i )
679
+ fldPath := field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ). Key ( md . Name ). Child ( "machineHealthCheck" )
680
680
681
681
// Validate the MachineDeployment MachineHealthCheck if defined.
682
682
if ! md .MachineHealthCheck .MachineHealthCheckClass .IsZero () {
@@ -791,7 +791,7 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust
791
791
792
792
if cluster .Spec .Topology .Workers != nil {
793
793
// Validate MachineDeployment variable overrides.
794
- for i , md := range cluster .Spec .Topology .Workers .MachineDeployments {
794
+ for _ , md := range cluster .Spec .Topology .Workers .MachineDeployments {
795
795
// Continue if there are no variable overrides.
796
796
if md .Variables == nil || len (md .Variables .Overrides ) == 0 {
797
797
continue
@@ -801,12 +801,12 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust
801
801
md .Variables .Overrides ,
802
802
oldMDVariables [md .Name ],
803
803
clusterClass .Status .Variables ,
804
- field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ).Index ( i ).Child ("variables" , "overrides" ))... ,
804
+ field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ).Key ( md . Name ).Child ("variables" , "overrides" ))... ,
805
805
)
806
806
}
807
807
808
808
// Validate MachinePool variable overrides.
809
- for i , mp := range cluster .Spec .Topology .Workers .MachinePools {
809
+ for _ , mp := range cluster .Spec .Topology .Workers .MachinePools {
810
810
// Continue if there are no variable overrides.
811
811
if mp .Variables == nil || len (mp .Variables .Overrides ) == 0 {
812
812
continue
@@ -816,7 +816,7 @@ func DefaultAndValidateVariables(ctx context.Context, cluster, oldCluster *clust
816
816
mp .Variables .Overrides ,
817
817
oldMPVariables [mp .Name ],
818
818
clusterClass .Status .Variables ,
819
- field .NewPath ("spec" , "topology" , "workers" , "machinePools" ).Index ( i ).Child ("variables" , "overrides" ))... ,
819
+ field .NewPath ("spec" , "topology" , "workers" , "machinePools" ).Key ( mp . Name ).Child ("variables" , "overrides" ))... ,
820
820
)
821
821
}
822
822
}
@@ -855,13 +855,13 @@ func DefaultVariables(cluster *clusterv1.Cluster, clusterClass *clusterv1.Cluste
855
855
856
856
if cluster .Spec .Topology .Workers != nil {
857
857
// Default MachineDeployment variable overrides.
858
- for i , md := range cluster .Spec .Topology .Workers .MachineDeployments {
858
+ for _ , md := range cluster .Spec .Topology .Workers .MachineDeployments {
859
859
// Continue if there are no variable overrides.
860
860
if md .Variables == nil || len (md .Variables .Overrides ) == 0 {
861
861
continue
862
862
}
863
863
defaultedVariables , errs := variables .DefaultMachineVariables (md .Variables .Overrides , clusterClass .Status .Variables ,
864
- field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ).Index ( i ).Child ("variables" , "overrides" ))
864
+ field .NewPath ("spec" , "topology" , "workers" , "machineDeployments" ).Key ( md . Name ).Child ("variables" , "overrides" ))
865
865
if len (errs ) > 0 {
866
866
allErrs = append (allErrs , errs ... )
867
867
} else {
@@ -870,13 +870,13 @@ func DefaultVariables(cluster *clusterv1.Cluster, clusterClass *clusterv1.Cluste
870
870
}
871
871
872
872
// Default MachinePool variable overrides.
873
- for i , mp := range cluster .Spec .Topology .Workers .MachinePools {
873
+ for _ , mp := range cluster .Spec .Topology .Workers .MachinePools {
874
874
// Continue if there are no variable overrides.
875
875
if mp .Variables == nil || len (mp .Variables .Overrides ) == 0 {
876
876
continue
877
877
}
878
878
defaultedVariables , errs := variables .DefaultMachineVariables (mp .Variables .Overrides , clusterClass .Status .Variables ,
879
- field .NewPath ("spec" , "topology" , "workers" , "machinePools" ).Index ( i ).Child ("variables" , "overrides" ))
879
+ field .NewPath ("spec" , "topology" , "workers" , "machinePools" ).Key ( mp . Name ).Child ("variables" , "overrides" ))
880
880
if len (errs ) > 0 {
881
881
allErrs = append (allErrs , errs ... )
882
882
} else {
@@ -978,14 +978,14 @@ func validateTopologyMetadata(topology *clusterv1.Topology, fldPath *field.Path)
978
978
var allErrs field.ErrorList
979
979
allErrs = append (allErrs , topology .ControlPlane .Metadata .Validate (fldPath .Child ("controlPlane" , "metadata" ))... )
980
980
if topology .Workers != nil {
981
- for idx , md := range topology .Workers .MachineDeployments {
981
+ for _ , md := range topology .Workers .MachineDeployments {
982
982
allErrs = append (allErrs , md .Metadata .Validate (
983
- fldPath .Child ("workers" , "machineDeployments" ).Index ( idx ).Child ("metadata" ),
983
+ fldPath .Child ("workers" , "machineDeployments" ).Key ( md . Name ).Child ("metadata" ),
984
984
)... )
985
985
}
986
- for idx , mp := range topology .Workers .MachinePools {
986
+ for _ , mp := range topology .Workers .MachinePools {
987
987
allErrs = append (allErrs , mp .Metadata .Validate (
988
- fldPath .Child ("workers" , "machinePools" ).Index ( idx ).Child ("metadata" ),
988
+ fldPath .Child ("workers" , "machinePools" ).Key ( mp . Name ).Child ("metadata" ),
989
989
)... )
990
990
}
991
991
}
@@ -1003,7 +1003,7 @@ func validateAutoscalerAnnotationsForCluster(cluster *clusterv1.Cluster, cluster
1003
1003
}
1004
1004
1005
1005
fldPath := field .NewPath ("spec" , "topology" )
1006
- for i , mdt := range cluster .Spec .Topology .Workers .MachineDeployments {
1006
+ for _ , mdt := range cluster .Spec .Topology .Workers .MachineDeployments {
1007
1007
if mdt .Replicas == nil {
1008
1008
continue
1009
1009
}
@@ -1012,8 +1012,8 @@ func validateAutoscalerAnnotationsForCluster(cluster *clusterv1.Cluster, cluster
1012
1012
allErrs = append (
1013
1013
allErrs ,
1014
1014
field .Invalid (
1015
- fldPath .Child ("workers" , "machineDeployments" ).Index ( i ).Child ("replicas" ),
1016
- cluster . Spec . Topology . Workers . MachineDeployments [ i ] .Replicas ,
1015
+ fldPath .Child ("workers" , "machineDeployments" ).Key ( mdt . Name ).Child ("replicas" ),
1016
+ mdt .Replicas ,
1017
1017
fmt .Sprintf ("cannot be set for cluster %q in namespace %q if the same MachineDeploymentTopology has autoscaler annotations" ,
1018
1018
cluster .Name , cluster .Namespace ),
1019
1019
),
@@ -1036,8 +1036,8 @@ func validateAutoscalerAnnotationsForCluster(cluster *clusterv1.Cluster, cluster
1036
1036
allErrs = append (
1037
1037
allErrs ,
1038
1038
field .Invalid (
1039
- fldPath .Child ("workers" , "machineDeployments" ).Index ( i ).Child ("replicas" ),
1040
- cluster . Spec . Topology . Workers . MachineDeployments [ i ] .Replicas ,
1039
+ fldPath .Child ("workers" , "machineDeployments" ).Key ( mdt . Name ).Child ("replicas" ),
1040
+ mdt .Replicas ,
1041
1041
fmt .Sprintf ("cannot be set for cluster %q in namespace %q if the source class %q of this MachineDeploymentTopology has autoscaler annotations" ,
1042
1042
cluster .Name , cluster .Namespace , mdt .Class ),
1043
1043
),
0 commit comments