@@ -1006,16 +1006,33 @@ func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Clie
1006
1006
client.MatchingLabels {clusterv1 .ClusterNameLabel : workloadClusterName },
1007
1007
); err == nil {
1008
1008
for _ , mp := range machinePoolList .Items {
1009
- ref := & corev1.ObjectReference {}
1010
- err = util .UnstructuredUnmarshalField (& mp , ref , "spec" , "template" , "spec" , "infrastructureRef" )
1011
- if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
1012
- return 0 , err
1013
- }
1009
+ infraMachinePool := & unstructured.Unstructured {}
1010
+
1011
+ // Fallback to v1beta1's objectReference
1012
+ if clusterv1 .GroupVersion .Version == "v1beta1" {
1013
+ ref := & corev1.ObjectReference {}
1014
+ err = util .UnstructuredUnmarshalField (& mp , ref , "spec" , "template" , "spec" , "infrastructureRef" )
1015
+ if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
1016
+ return 0 , err
1017
+ }
1014
1018
1015
- infraMachinePool , err := external .Get (ctx , c , ref )
1016
- if err != nil {
1017
- return 0 , err
1019
+ infraMachinePool , err = external .Get (ctx , c , ref )
1020
+ if err != nil {
1021
+ return 0 , err
1022
+ }
1023
+ } else {
1024
+ ref := clusterv1.ContractVersionedObjectReference {}
1025
+ err = util .UnstructuredUnmarshalField (& mp , & ref , "spec" , "template" , "spec" , "infrastructureRef" )
1026
+ if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
1027
+ return 0 , err
1028
+ }
1029
+
1030
+ infraMachinePool , err = external .GetObjectFromContractVersionedRef (ctx , c , ref , mp .GetNamespace ())
1031
+ if err != nil {
1032
+ return 0 , err
1033
+ }
1018
1034
}
1035
+
1019
1036
// Check if the InfraMachinePool has an infrastructureMachineKind field. If it does not, we should skip checking for MachinePool machines.
1020
1037
err = util .UnstructuredUnmarshalField (infraMachinePool , ptr .To ("" ), "status" , "infrastructureMachineKind" )
1021
1038
if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
0 commit comments