@@ -478,7 +478,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
478
478
By ("Calculating expected MachineDeployment and MachinePool Machine and Node counts" )
479
479
expectedMachineDeploymentMachineCount := calculateExpectedMachineDeploymentMachineCount (ctx , managementClusterProxy .GetClient (), workloadClusterUnstructured , coreCAPIStorageVersion )
480
480
expectedMachinePoolNodeCount := calculateExpectedMachinePoolNodeCount (ctx , managementClusterProxy .GetClient (), workloadClusterUnstructured , coreCAPIStorageVersion )
481
- expectedMachinePoolMachineCount , err := calculateExpectedMachinePoolMachineCount (ctx , managementClusterProxy .GetClient (), workloadClusterNamespace , workloadClusterName )
481
+ expectedMachinePoolMachineCount , err := calculateExpectedMachinePoolMachineCount (ctx , managementClusterProxy .GetClient (), workloadClusterNamespace , workloadClusterName , coreCAPIStorageVersion )
482
482
Expect (err ).ToNot (HaveOccurred ())
483
483
484
484
expectedMachineCount := * controlPlaneMachineCount + expectedMachineDeploymentMachineCount + expectedMachinePoolMachineCount
@@ -512,16 +512,27 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
512
512
By ("Waiting for MachinePool to be ready with correct number of replicas" )
513
513
Eventually (func () (int64 , error ) {
514
514
var n int64
515
- machinePoolList := & expv1.MachinePoolList {}
515
+ machinePoolList := & unstructured.UnstructuredList {}
516
+ machinePoolList .SetGroupVersionKind (schema.GroupVersionKind {
517
+ Group : clusterv1 .GroupVersion .Group ,
518
+ Version : coreCAPIStorageVersion ,
519
+ Kind : "MachinePoolList" ,
520
+ })
516
521
if err := managementClusterProxy .GetClient ().List (
517
522
ctx ,
518
523
machinePoolList ,
519
524
client .InNamespace (workloadClusterNamespace ),
520
525
client.MatchingLabels {clusterv1 .ClusterNameLabel : workloadClusterName },
521
526
); err == nil {
522
- for _ , mp := range machinePoolList .Items {
523
- if mp .Status .Phase == string (expv1 .MachinePoolPhaseRunning ) {
524
- n += int64 (mp .Status .ReadyReplicas )
527
+ for _ , m := range machinePoolList .Items {
528
+ phase , found , err := unstructured .NestedString (m .Object , "status" , "phase" )
529
+ if err != nil || ! found || phase != string (expv1 .MachinePoolPhaseRunning ) {
530
+ continue
531
+ }
532
+
533
+ replicas , found , err := unstructured .NestedInt64 (m .Object , "status" , "readyReplicas" )
534
+ if err == nil && found {
535
+ n += replicas
525
536
}
526
537
}
527
538
}
@@ -935,18 +946,29 @@ func calculateExpectedMachineDeploymentMachineCount(ctx context.Context, c clien
935
946
return expectedMachineDeploymentWorkerCount
936
947
}
937
948
938
- func calculateExpectedMachinePoolMachineCount (ctx context.Context , c client.Client , workloadClusterNamespace , workloadClusterName string ) (int64 , error ) {
949
+ func calculateExpectedMachinePoolMachineCount (ctx context.Context , c client.Client , workloadClusterNamespace , workloadClusterName , coreCAPIStorageVersion string ) (int64 , error ) {
939
950
expectedMachinePoolMachineCount := int64 (0 )
940
951
941
- machinePoolList := & expv1.MachinePoolList {}
952
+ machinePoolList := & unstructured.UnstructuredList {}
953
+ machinePoolList .SetGroupVersionKind (schema.GroupVersionKind {
954
+ Group : clusterv1 .GroupVersion .Group ,
955
+ Version : coreCAPIStorageVersion ,
956
+ Kind : "MachinePoolList" ,
957
+ })
942
958
if err := c .List (
943
959
ctx ,
944
960
machinePoolList ,
945
961
client .InNamespace (workloadClusterNamespace ),
946
962
client.MatchingLabels {clusterv1 .ClusterNameLabel : workloadClusterName },
947
963
); err == nil {
948
964
for _ , mp := range machinePoolList .Items {
949
- infraMachinePool , err := external .Get (ctx , c , & mp .Spec .Template .Spec .InfrastructureRef )
965
+ ref := & corev1.ObjectReference {}
966
+ err = util .UnstructuredUnmarshalField (& mp , ref , "spec" , "template" , "spec" , "infrastructureRef" )
967
+ if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
968
+ return 0 , err
969
+ }
970
+
971
+ infraMachinePool , err := external .Get (ctx , c , ref )
950
972
if err != nil {
951
973
return 0 , err
952
974
}
@@ -955,8 +977,10 @@ func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Clie
955
977
if err != nil && ! errors .Is (err , util .ErrUnstructuredFieldNotFound ) {
956
978
return 0 , err
957
979
}
958
- if err == nil {
959
- expectedMachinePoolMachineCount += int64 (* mp .Spec .Replicas )
980
+
981
+ replicas , found , err := unstructured .NestedInt64 (mp .Object , "spec" , "replicas" )
982
+ if err == nil && found {
983
+ expectedMachinePoolMachineCount += replicas
960
984
}
961
985
}
962
986
}
0 commit comments