Skip to content

Commit

Permalink
Use unstructured client for fetching objects
Browse files Browse the repository at this point in the history
Also, allow passing GroupVersion to ClusterctlUpgradeSpecInput struct to be
able to use with unstructured later in the tests

Signed-off-by: Furkat Gofurov <furkat.gofurov@suse.com>
  • Loading branch information
furkatgofurov7 committed Aug 9, 2023
1 parent 89b2d18 commit 6bd98c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
32 changes: 26 additions & 6 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
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 @@ -95,6 +96,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 @@ -387,14 +389,32 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
input.PreWaitForCluster(managementClusterProxy, testNamespace.Name, workLoadClusterName)
}

// Get the input
input := inputGetter()

// If GroupVersion is not set, default it to v1beta1
if input.GroupVersion.Empty() {
input.GroupVersion = clusterv1.GroupVersion
}

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 {
n++
machineList := &unstructured.UnstructuredList{}
machineList.SetGroupVersionKind(input.GroupVersion.WithKind("MachineList"))
if err := managementClusterProxy.GetClient().List(
ctx,
machineList,
client.InNamespace(testNamespace.Name),
client.MatchingLabels{clusterv1.ClusterNameLabel: workLoadClusterName},
); err == nil {
for _, m := range machineList.Items {
machineStatus, _, _ := unstructured.NestedMap(m.Object, "status")
if machineStatus != nil {
nodeRef, _ := machineStatus["nodeRef"].(map[string]interface{})
if nodeRef != nil {
n++
}
}
}
}
Expand All @@ -411,7 +431,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(input.GroupVersion.WithKind("MachineList"))
err = managementClusterProxy.GetClient().List(
ctx,
preUpgradeMachineList,
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
. "github.com/onsi/ginkgo/v2"
"k8s.io/utils/pointer"

clusterv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/test/framework"
)

Expand All @@ -34,6 +36,7 @@ var _ = Describe("When testing clusterctl upgrades (v1.0=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
GroupVersion: clusterv1alpha3.GroupVersion,
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.5/clusterctl-{OS}-{ARCH}",
// We have to pin the providers because with `InitWithProvidersContract` the test would
Expand Down Expand Up @@ -74,6 +77,7 @@ var _ = Describe("When testing clusterctl upgrades (v1.4=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
GroupVersion: clusterv1alpha3.GroupVersion,
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.5/clusterctl-{OS}-{ARCH}",
// We have to pin the providers because with `InitWithProvidersContract` the test would
Expand Down Expand Up @@ -115,6 +119,7 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.4=>cur
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
GroupVersion: clusterv1alpha3.GroupVersion,
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.5/clusterctl-{OS}-{ARCH}",
// We have to pin the providers because with `InitWithProvidersContract` the test would
Expand Down Expand Up @@ -156,6 +161,7 @@ var _ = Describe("When testing clusterctl upgrades (v1.5=>current)", func() {
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
GroupVersion: clusterv1alpha4.GroupVersion,
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.0/clusterctl-{OS}-{ARCH}",
InitWithProvidersContract: "v1beta1",
Expand Down Expand Up @@ -187,6 +193,7 @@ var _ = Describe("When testing clusterctl upgrades using ClusterClass (v1.5=>cur
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
GroupVersion: clusterv1alpha4.GroupVersion,
InfrastructureProvider: pointer.String("docker"),
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.0/clusterctl-{OS}-{ARCH}",
InitWithProvidersContract: "v1beta1",
Expand Down

0 comments on commit 6bd98c3

Please sign in to comment.