From 4421b8d8ac5fdd842edb188eaf14256218f6478d Mon Sep 17 00:00:00 2001 From: Furkat Gofurov Date: Thu, 10 Aug 2023 00:21:51 +0300 Subject: [PATCH] make changes to machineList loop and move code --- test/e2e/clusterctl_upgrade.go | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index ae19f3b55935..b5eaa70eef64 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -336,18 +336,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg By("THE MANAGEMENT CLUSTER WITH THE OLDER VERSION OF PROVIDERS IS UP&RUNNING!") - machineCRD := &apiextensionsv1.CustomResourceDefinition{} - if err := managementClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "machines.cluster.x-k8s.io"}, machineCRD); err != nil { - Expect(err).ToNot(HaveOccurred(), "failed to retrieve a machine CRD") - } - - // Build GroupVersionKind for Machine resources - machineListGVK := schema.GroupVersionKind{ - Group: machineCRD.Spec.Group, - Version: machineCRD.Spec.Versions[0].Name, - Kind: machineCRD.Spec.Names.ListKind, - } - Byf("Creating a namespace for hosting the %s test workload cluster", specName) testNamespace, testCancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{ Creator: managementClusterProxy.GetClient(), @@ -401,12 +389,23 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg input.PreWaitForCluster(managementClusterProxy, testNamespace.Name, workLoadClusterName) } - machineList := &unstructured.UnstructuredList{} - machineList.SetGroupVersionKind(machineListGVK) + machineCRD := &apiextensionsv1.CustomResourceDefinition{} + if err := managementClusterProxy.GetClient().Get(ctx, client.ObjectKey{Name: "machines.cluster.x-k8s.io"}, machineCRD); err != nil { + Expect(err).ToNot(HaveOccurred(), "failed to retrieve a machine CRD") + } + + // Build GroupVersionKind for Machine resources + machineListGVK := schema.GroupVersionKind{ + Group: machineCRD.Spec.Group, + Version: machineCRD.Spec.Versions[0].Name, + Kind: machineCRD.Spec.Names.ListKind, + } By("Waiting for the machines to exist") Eventually(func() (int64, error) { var n int64 + machineList := &unstructured.UnstructuredList{} + machineList.SetGroupVersionKind(machineListGVK) if err := managementClusterProxy.GetClient().List( ctx, machineList, @@ -414,9 +413,12 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg client.MatchingLabels{clusterv1.ClusterNameLabel: workLoadClusterName}, ); err == nil { for _, m := range machineList.Items { - _, found, err := unstructured.NestedMap(m.Object, "status", "nodeRef") - if err == nil && found { - n++ + machineStatus, _, _ := unstructured.NestedMap(m.Object, "status") + if machineStatus != nil { + nodeRef, _ := machineStatus["nodeRef"].(map[string]interface{}) + if nodeRef != nil { + n++ + } } } }