Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 07667e7

Browse files
authored
test(e2e): Use ghcr.io/mesosphere/kind-node for bootstrap (nutanix-cloud-native#406)
1 parent 604db96 commit 07667e7

File tree

3 files changed

+124
-9
lines changed

3 files changed

+124
-9
lines changed

test/e2e/e2e_suite_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
addonsv1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
2424
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
2525
"sigs.k8s.io/cluster-api/test/framework"
26-
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
26+
capibootstrap "sigs.k8s.io/cluster-api/test/framework/bootstrap"
2727
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929

30+
"github.com/d2iq-labs/capi-runtime-extensions/test/framework/bootstrap"
3031
clusterctltemp "github.com/d2iq-labs/capi-runtime-extensions/test/framework/clusterctl"
3132
)
3233

@@ -56,6 +57,18 @@ func init() { //nolint:gochecknoinits // Idiomatically used to set up flags.
5657
false,
5758
"if true, the test uses the current cluster instead of creating a new one (default discovery rules apply)",
5859
)
60+
flag.StringVar(
61+
&bootstrapNodeImageRepository,
62+
"e2e.bootstrap-kind-image",
63+
"ghcr.io/mesosphere/kind-node",
64+
"the image to use for the bootstrap cluster",
65+
)
66+
flag.StringVar(
67+
&bootstrapKubernetesVersion,
68+
"e2e.bootstrap-kind-version",
69+
"v1.29.2",
70+
"the version of the image used in bootstrap cluster",
71+
)
5972
}
6073

6174
func TestE2E(t *testing.T) {
@@ -189,16 +202,20 @@ func setupBootstrapCluster(
189202
config *clusterctl.E2EConfig,
190203
scheme *runtime.Scheme,
191204
useExistingCluster bool,
192-
) (bootstrap.ClusterProvider, framework.ClusterProxy) {
193-
var clusterProvider bootstrap.ClusterProvider
205+
) (capibootstrap.ClusterProvider, framework.ClusterProxy) {
206+
var clusterProvider capibootstrap.ClusterProvider
194207
kubeconfigPath := ""
195208
if !useExistingCluster {
196209
clusterProvider = bootstrap.CreateKindBootstrapClusterAndLoadImages(
197210
context.TODO(),
198211
bootstrap.CreateKindBootstrapClusterAndLoadImagesInput{
199-
Name: config.ManagementClusterName,
200-
RequiresDockerSock: config.HasDockerProvider(),
201-
Images: config.Images,
212+
NodeImageRepository: bootstrapNodeImageRepository,
213+
CreateKindBootstrapClusterAndLoadImagesInput: capibootstrap.CreateKindBootstrapClusterAndLoadImagesInput{
214+
Name: config.ManagementClusterName,
215+
RequiresDockerSock: config.HasDockerProvider(),
216+
Images: config.Images,
217+
KubernetesVersion: bootstrapKubernetesVersion,
218+
},
202219
},
203220
)
204221
Expect(clusterProvider).NotTo(BeNil(), "Failed to create a bootstrap cluster")
@@ -209,11 +226,11 @@ func setupBootstrapCluster(
209226
).To(BeAnExistingFile(), "Failed to get the kubeconfig file for the bootstrap cluster")
210227
} else {
211228
// Loading image for already created cluster
212-
imagesInput := bootstrap.LoadImagesToKindClusterInput{
229+
imagesInput := capibootstrap.LoadImagesToKindClusterInput{
213230
Name: "cre-e2e",
214231
Images: config.Images,
215232
}
216-
err := bootstrap.LoadImagesToKindCluster(context.TODO(), imagesInput)
233+
err := capibootstrap.LoadImagesToKindCluster(context.TODO(), imagesInput)
217234
Expect(err).To(BeNil(), "Failed to load images to the bootstrap cluster: %s", err)
218235
}
219236

@@ -245,7 +262,7 @@ func initBootstrapCluster(
245262
}
246263

247264
func tearDown(
248-
bootstrapClusterProvider bootstrap.ClusterProvider,
265+
bootstrapClusterProvider capibootstrap.ClusterProvider,
249266
bootstrapClusterProxy framework.ClusterProxy,
250267
) {
251268
if bootstrapClusterProxy != nil {

test/e2e/e2e_suite_vars.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ var (
3636

3737
// skipLogCollection prevents the log collection process from running.
3838
skipLogCollection bool
39+
40+
// bootstrapNodeImageRepository is the image to use for the bootstrap cluster.
41+
bootstrapNodeImageRepository string
42+
43+
// bootstrapKubernetesVersion is the version of the image used in bootstrap cluster.
44+
bootstrapKubernetesVersion string
3945
)
4046

4147
// Test suite global vars.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//go:build e2e
2+
3+
// Copyright 2024 D2iQ, Inc. All rights reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package bootstrap
7+
8+
import (
9+
"context"
10+
"fmt"
11+
12+
. "github.com/onsi/ginkgo/v2"
13+
. "github.com/onsi/gomega"
14+
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
15+
)
16+
17+
// CreateKindBootstrapClusterAndLoadImagesInput is the input for CreateKindBootstrapClusterAndLoadImages.
18+
type CreateKindBootstrapClusterAndLoadImagesInput struct {
19+
// NodeImageRepository defines the image repository to use for the bootstrap cluster nodes.
20+
NodeImageRepository string
21+
22+
bootstrap.CreateKindBootstrapClusterAndLoadImagesInput
23+
}
24+
25+
// CreateKindBootstrapClusterAndLoadImages returns a new Kubernetes cluster with pre-loaded images.
26+
func CreateKindBootstrapClusterAndLoadImages(
27+
ctx context.Context,
28+
input CreateKindBootstrapClusterAndLoadImagesInput, //nolint:gocritic // Copied from upstream.
29+
) bootstrap.ClusterProvider {
30+
Expect(ctx).NotTo(BeNil(), "ctx is required for CreateKindBootstrapClusterAndLoadImages")
31+
Expect(
32+
input.Name,
33+
).ToNot(BeEmpty(), "Invalid argument. Name can't be empty when calling CreateKindBootstrapClusterAndLoadImages")
34+
35+
fmt.Fprintf(GinkgoWriter, "INFO: Creating a kind cluster with name %q\n", input.Name)
36+
37+
options := []bootstrap.KindClusterOption{}
38+
nodeImageRepository := bootstrap.DefaultNodeImageRepository
39+
if input.NodeImageRepository != "" {
40+
nodeImageRepository = input.NodeImageRepository
41+
}
42+
43+
if input.KubernetesVersion != "" {
44+
options = append(
45+
options,
46+
bootstrap.WithNodeImage(
47+
fmt.Sprintf("%s:%s", nodeImageRepository, input.KubernetesVersion),
48+
),
49+
)
50+
}
51+
if input.RequiresDockerSock {
52+
options = append(options, bootstrap.WithDockerSockMount())
53+
}
54+
if input.IPFamily == "IPv6" {
55+
options = append(options, bootstrap.WithIPv6Family())
56+
}
57+
if input.IPFamily == "dual" {
58+
options = append(options, bootstrap.WithDualStackFamily())
59+
}
60+
if input.LogFolder != "" {
61+
options = append(options, bootstrap.LogFolder(input.LogFolder))
62+
}
63+
clusterProvider := bootstrap.NewKindClusterProvider(input.Name, options...)
64+
Expect(clusterProvider).ToNot(BeNil(), "Failed to create a kind cluster")
65+
66+
clusterProvider.Create(ctx)
67+
Expect(
68+
clusterProvider.GetKubeconfigPath(),
69+
).To(
70+
BeAnExistingFile(),
71+
"The kubeconfig file for the kind cluster with name %q does not exists at %q as expected",
72+
input.Name,
73+
clusterProvider.GetKubeconfigPath(),
74+
)
75+
76+
fmt.Fprintf(
77+
GinkgoWriter,
78+
"INFO: The kubeconfig file for the kind cluster is %s\n",
79+
clusterProvider.GetKubeconfigPath(),
80+
)
81+
82+
err := bootstrap.LoadImagesToKindCluster(ctx, bootstrap.LoadImagesToKindClusterInput{
83+
Name: input.Name,
84+
Images: input.Images,
85+
})
86+
if err != nil {
87+
clusterProvider.Dispose(ctx)
88+
Expect(err).ToNot(HaveOccurred()) // re-surface the error to fail the test
89+
}
90+
91+
return clusterProvider
92+
}

0 commit comments

Comments
 (0)