Skip to content

Commit 9ef0c96

Browse files
authored
Merge pull request kubernetes-sigs#10804 from chrischdi/pr-test-extend-kind-mgmt-cluster
🌱 e2e: add function to create the ClusterProxy when using a secondary kind-based management cluster
2 parents 132cf04 + cfc670e commit 9ef0c96

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type ClusterctlUpgradeSpecInput struct {
6666
// NOTE: given that the bootstrap cluster could be shared by several tests, it is not practical to use it for testing clusterctl upgrades.
6767
// So we are creating a new management cluster where to install older version of providers
6868
UseKindForManagementCluster bool
69+
// KindManagementClusterNewClusterProxyFunc is used to create the ClusterProxy used in the test after creating the kind based management cluster.
70+
// This allows to use a custom ClusterProxy implementation or create a ClusterProxy with a custom scheme and options.
71+
KindManagementClusterNewClusterProxyFunc func(name string, kubeconfigPath string) framework.ClusterProxy
6972

7073
// InitWithBinary must be used to specify the URL of the clusterctl binary of the old version of Cluster API. The spec will interpolate the
7174
// 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}
@@ -201,21 +204,23 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
201204
initKubernetesVersion string
202205

203206
workloadClusterName string
204-
205-
scheme *apiruntime.Scheme
206207
)
207208

208209
BeforeEach(func() {
209-
scheme = apiruntime.NewScheme()
210-
framework.TryAddDefaultSchemes(scheme)
211-
212210
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
213211
input = inputGetter()
214212
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
215213
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
216214
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
217215
Expect(input.InitWithBinary).ToNot(BeEmpty(), "Invalid argument. input.InitWithBinary can't be empty when calling %s spec", specName)
218216
Expect(input.InitWithKubernetesVersion).ToNot(BeEmpty(), "Invalid argument. input.InitWithKubernetesVersion can't be empty when calling %s spec", specName)
217+
if input.KindManagementClusterNewClusterProxyFunc == nil {
218+
input.KindManagementClusterNewClusterProxyFunc = func(name string, kubeconfigPath string) framework.ClusterProxy {
219+
scheme := apiruntime.NewScheme()
220+
framework.TryAddDefaultSchemes(scheme)
221+
return framework.NewClusterProxy(name, kubeconfigPath, scheme)
222+
}
223+
}
219224

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

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

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

832837
return cluster

0 commit comments

Comments
 (0)