Skip to content

Commit

Permalink
Fetch machine CRD GVK and pass it to unstructured instead of hardcodi…
Browse files Browse the repository at this point in the history
…ng it

Signed-off-by: Furkat Gofurov <[email protected]>
  • Loading branch information
furkatgofurov7 committed Aug 9, 2023
1 parent 89b2d18 commit 2efe273
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
32 changes: 27 additions & 5 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/discovery"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -334,6 +336,18 @@ 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 @@ -387,13 +401,21 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
input.PreWaitForCluster(managementClusterProxy, testNamespace.Name, workLoadClusterName)
}

machineList := &unstructured.UnstructuredList{}
machineList.SetGroupVersionKind(machineListGVK)

By("Waiting for the machines to exist")
Eventually(func() (int64, error) {
var n int64
machineList := &clusterv1alpha3.MachineList{}
if err := managementClusterProxy.GetClient().List(ctx, machineList, client.InNamespace(testNamespace.Name), client.MatchingLabels{clusterv1.ClusterNameLabel: workLoadClusterName}); err == nil {
for _, machine := range machineList.Items {
if machine.Status.NodeRef != nil {
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++
}
}
Expand All @@ -411,7 +433,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
// Get the workloadCluster before the management cluster is upgraded to make sure that the upgrade did not trigger
// any unexpected rollouts.
preUpgradeMachineList := &unstructured.UnstructuredList{}
preUpgradeMachineList.SetGroupVersionKind(clusterv1alpha3.GroupVersion.WithKind("MachineList"))
preUpgradeMachineList.SetGroupVersionKind(machineListGVK)
err = managementClusterProxy.GetClient().List(
ctx,
preUpgradeMachineList,
Expand Down
12 changes: 2 additions & 10 deletions test/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ var _ = Describe("When testing clusterctl upgrades (v1.4=>current)", func() {
InitWithBootstrapProviders: []string{"kubeadm:v1.4.5"},
InitWithControlPlaneProviders: []string{"kubeadm:v1.4.5"},
InitWithInfrastructureProviders: []string{"docker:v1.4.5"},
// We have to set this to an empty array as clusterctl v1.4 doesn't support
// runtime extension providers. If we don't do this the test will automatically
// try to deploy the latest version of our test-extension from docker.yaml.
InitWithRuntimeExtensionProviders: []string{},
InitWithProvidersContract: "v1beta1",
InitWithProvidersContract: "v1beta1",
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/e2e/data/infrastructure-docker/v1.4/bases.
InitWithKubernetesVersion: "v1.27.3",
WorkloadKubernetesVersion: "v1.27.3",
Expand Down Expand Up @@ -123,11 +119,7 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.4=>cur
InitWithBootstrapProviders: []string{"kubeadm:v1.4.5"},
InitWithControlPlaneProviders: []string{"kubeadm:v1.4.5"},
InitWithInfrastructureProviders: []string{"docker:v1.4.5"},
// We have to set this to an empty array as clusterctl v1.4 doesn't support
// runtime extension providers. If we don't do this the test will automatically
// try to deploy the latest version of our test-extension from docker.yaml.
InitWithRuntimeExtensionProviders: []string{},
InitWithProvidersContract: "v1beta1",
InitWithProvidersContract: "v1beta1",
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/e2e/data/infrastructure-docker/v1.4/bases.
InitWithKubernetesVersion: "v1.27.3",
WorkloadKubernetesVersion: "v1.27.3",
Expand Down

0 comments on commit 2efe273

Please sign in to comment.