@@ -1006,16 +1006,33 @@ func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Clie
10061006 client.MatchingLabels {clusterv1 .ClusterNameLabel : workloadClusterName },
10071007 ); err == nil {
10081008 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+ var infraMachinePool * unstructured.Unstructured
1010+
1011+ // Fallback to v1beta1's objectReference
1012+ if coreCAPIStorageVersion == "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+ }
10141018
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+ }
10181034 }
1035+
10191036 // Check if the InfraMachinePool has an infrastructureMachineKind field. If it does not, we should skip checking for MachinePool machines.
10201037 err = util .UnstructuredUnmarshalField (infraMachinePool , ptr .To ("" ), "status" , "infrastructureMachineKind" )
10211038 if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
0 commit comments