Skip to content

Commit 8054ff1

Browse files
committed
test: fix MachinePool on upgrades to use correct struct for infrastructureRef
1 parent f18db74 commit 8054ff1

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
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+
}
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

Comments
 (0)