Skip to content

Commit

Permalink
e2e: add function to create the ClusterProxy when using a secondary k…
Browse files Browse the repository at this point in the history
…ind-based management cluster
  • Loading branch information
chrischdi committed Jun 28, 2024
1 parent 1e6896e commit ffe313b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type ClusterctlUpgradeSpecInput struct {
// NOTE: given that the bootstrap cluster could be shared by several tests, it is not practical to use it for testing clusterctl upgrades.
// So we are creating a new management cluster where to install older version of providers
UseKindForManagementCluster bool
// KindManagementClusterNewClusterProxyFunc is used to create the ClusterProxy used in the test after creating the kind based management cluster.
// This allows to use a custom ClusterProxy implementation or create a ClusterProxy with a custom scheme and options.
KindManagementClusterNewClusterProxyFunc func(name string, kubeconfigPath string) framework.ClusterProxy

// InitWithBinary must be used to specify the URL of the clusterctl binary of the old version of Cluster API. The spec will interpolate the
// strings `{OS}` and `{ARCH}` to `runtime.GOOS` and `runtime.GOARCH` respectively, e.g. https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.3.23/clusterctl-{OS}-{ARCH}
Expand Down Expand Up @@ -201,21 +204,24 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
initKubernetesVersion string

workloadClusterName string

scheme *apiruntime.Scheme
)

BeforeEach(func() {
scheme = apiruntime.NewScheme()
framework.TryAddDefaultSchemes(scheme)

Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
input = inputGetter()
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
Expect(input.InitWithBinary).ToNot(BeEmpty(), "Invalid argument. input.InitWithBinary can't be empty when calling %s spec", specName)
Expect(input.InitWithKubernetesVersion).ToNot(BeEmpty(), "Invalid argument. input.InitWithKubernetesVersion can't be empty when calling %s spec", specName)
if input.KindManagementClusterNewClusterProxyFunc == nil {
input.KindManagementClusterNewClusterProxyFunc = func(name string, kubeconfigPath string) framework.ClusterProxy {
scheme := apiruntime.NewScheme()
framework.TryAddDefaultSchemes(scheme)
return framework.NewClusterProxy(name, kubeconfigPath, scheme)
}
Expect(input.KindManagementClusterNewClusterProxyFunc).ToNot(BeNil(), "Invalid argument. input.KindManagementClusterNewClusterProxyFunc can't be nil when calling %s spec", specName)
}

clusterctlBinaryURLTemplate := input.InitWithBinary
clusterctlBinaryURLReplacer := strings.NewReplacer("{OS}", runtime.GOOS, "{ARCH}", runtime.GOARCH)
Expand Down Expand Up @@ -276,7 +282,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
kubeconfigPath := managementClusterProvider.GetKubeconfigPath()
Expect(kubeconfigPath).To(BeAnExistingFile(), "Failed to get the kubeconfig file for the kind cluster")

managementClusterProxy = framework.NewClusterProxy(managementClusterName, kubeconfigPath, scheme)
managementClusterProxy = input.KindManagementClusterNewClusterProxyFunc(managementClusterName, kubeconfigPath)
Expect(managementClusterProxy).ToNot(BeNil(), "Failed to get a kind cluster proxy")

managementClusterResources.Cluster = &clusterv1.Cluster{
Expand Down Expand Up @@ -826,7 +832,7 @@ func discoveryAndWaitForCluster(ctx context.Context, input discoveryAndWaitForCl
clusterPhase, ok, err := unstructured.NestedString(cluster.Object, "status", "phase")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(ok).To(BeTrue(), "could not get status.phase field")
g.Expect(clusterPhase).To(Equal(string(clusterv1.ClusterPhaseProvisioned)), "Timed out waiting for Cluster %s to provision")
g.Expect(clusterPhase).To(Equal(string(clusterv1.ClusterPhaseProvisioned)), "Timed out waiting for Cluster %s to provision", klog.KObj(cluster))
}, intervals...).Should(Succeed(), "Failed to get Cluster object %s", klog.KRef(input.Namespace, input.Name))

return cluster
Expand Down

0 comments on commit ffe313b

Please sign in to comment.