Skip to content

Commit

Permalink
make changes to machineList loop and move code
Browse files Browse the repository at this point in the history
  • Loading branch information
furkatgofurov7 committed Aug 9, 2023
1 parent 2efe273 commit 414de84
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type ClusterctlUpgradeSpecInput struct {
// UpgradeClusterctlVariables can be used to set additional variables for clusterctl upgrade.
UpgradeClusterctlVariables map[string]string
SkipCleanup bool
GroupVersion schema.GroupVersion

// InfrastructureProviders specifies the infrastructure to use for clusterctl
// operations (Example: get cluster templates).
Expand Down Expand Up @@ -205,7 +206,9 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
if input.InitWithProvidersContract != "" {
initContract = input.InitWithProvidersContract
}

if input.GroupVersion.Empty() {
input.GroupVersion = clusterv1.GroupVersion
}
initKubernetesVersion = input.InitWithKubernetesVersion
if initKubernetesVersion == "" {
Expect(input.E2EConfig.Variables).To(HaveKey(initWithKubernetesVersion), "Invalid argument. %s variable must be defined when calling %s spec", initWithKubernetesVersion, specName)
Expand Down Expand Up @@ -336,18 +339,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(),
Expand Down Expand Up @@ -401,22 +392,36 @@ 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,
client.InNamespace(testNamespace.Name),
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++
}
}
}
}
Expand Down

0 comments on commit 414de84

Please sign in to comment.