Skip to content

Commit 13aa54b

Browse files
Fix MP error in clusterctl upgrade test
1 parent 5eab9b4 commit 13aa54b

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

test/e2e/clusterctl_upgrade.go

+34-10
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
478478
By("Calculating expected MachineDeployment and MachinePool Machine and Node counts")
479479
expectedMachineDeploymentMachineCount := calculateExpectedMachineDeploymentMachineCount(ctx, managementClusterProxy.GetClient(), workloadClusterUnstructured, coreCAPIStorageVersion)
480480
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)
482482
Expect(err).ToNot(HaveOccurred())
483483

484484
expectedMachineCount := *controlPlaneMachineCount + expectedMachineDeploymentMachineCount + expectedMachinePoolMachineCount
@@ -512,16 +512,27 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
512512
By("Waiting for MachinePool to be ready with correct number of replicas")
513513
Eventually(func() (int64, error) {
514514
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+
})
516521
if err := managementClusterProxy.GetClient().List(
517522
ctx,
518523
machinePoolList,
519524
client.InNamespace(workloadClusterNamespace),
520525
client.MatchingLabels{clusterv1.ClusterNameLabel: workloadClusterName},
521526
); 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
525536
}
526537
}
527538
}
@@ -935,18 +946,29 @@ func calculateExpectedMachineDeploymentMachineCount(ctx context.Context, c clien
935946
return expectedMachineDeploymentWorkerCount
936947
}
937948

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) {
939950
expectedMachinePoolMachineCount := int64(0)
940951

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+
})
942958
if err := c.List(
943959
ctx,
944960
machinePoolList,
945961
client.InNamespace(workloadClusterNamespace),
946962
client.MatchingLabels{clusterv1.ClusterNameLabel: workloadClusterName},
947963
); err == nil {
948964
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)
950972
if err != nil {
951973
return 0, err
952974
}
@@ -955,8 +977,10 @@ func calculateExpectedMachinePoolMachineCount(ctx context.Context, c client.Clie
955977
if err != nil && !errors.Is(err, util.ErrUnstructuredFieldNotFound) {
956978
return 0, err
957979
}
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
960984
}
961985
}
962986
}

test/e2e/clusterctl_upgrade_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.9=>cur
275275
})
276276

277277
// Note: This test should be changed during "prepare main branch", it should test n-1 => current.
278-
var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.10=>current) [ClusterClass]", Label("ClusterClass"), func() {
278+
var _ = FDescribe("When testing clusterctl upgrades using ClusterClass (v1.10=>current) [ClusterClass]", Label("ClusterClass"), func() {
279279
// Get n-1 latest stable release
280280
version := "1.10"
281281
stableRelease, err := GetLatestReleaseOfMinor(ctx, version) // NOTE: use GetStableReleaseOfMinor as soon as v1.10 is GA

0 commit comments

Comments
 (0)