Skip to content

Commit a093c19

Browse files
committed
Test for clusterctl move
1 parent 4a6a7bf commit a093c19

File tree

1 file changed

+92
-21
lines changed

1 file changed

+92
-21
lines changed

test/e2e/frmwrk/bootstrap_test.go

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ package frmwrk
33
import (
44
"context"
55
"fmt"
6+
apierrors "k8s.io/apimachinery/pkg/api/errors"
67
"os"
78
"path"
9+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
810
"strings"
911

1012
"github.com/drone/envsubst/v2"
1113
. "github.com/onsi/ginkgo/v2"
1214
. "github.com/onsi/gomega"
1315

16+
client "sigs.k8s.io/controller-runtime/pkg/client"
17+
1418
"sigs.k8s.io/cluster-api/test/framework"
19+
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
1520
)
1621

1722
var _ = Describe("Basic Cluster Creation", Ordered, func() {
18-
var (
19-
ec *E2ECluster
20-
)
2123

2224
BeforeAll(func() {
2325
e2eCtx = NewE2EContext()
@@ -28,35 +30,104 @@ var _ = Describe("Basic Cluster Creation", Ordered, func() {
2830
DeferCleanup(e2eCtx.Teardown, context.TODO())
2931
})
3032

31-
BeforeEach(func() {
32-
ec = nil
33-
})
34-
3533
kubernetesVersions := strings.Split(os.Getenv("E2E_KUBERNETES_VERSIONS"), ",")
3634
Expect(kubernetesVersions).ToNot(BeEmpty(), "E2E_KUBERNETES_VERSIONS must be set")
3735

3836
for i, v := range kubernetesVersions {
39-
It(fmt.Sprintf("create new cluster with kubernetes %s", v), func() {
40-
ctx := context.Background()
41-
42-
ec = createE2ECluster(ctx, e2eCtx, ClusterConfig{
43-
SpecName: "basic-cluster-creation-" + v,
44-
NamespaceName: fmt.Sprintf("e2e-basic-cluster-creation-%d", i),
45-
ClusterName: fmt.Sprintf("simple-%d", i),
46-
KubernetesVersion: v,
47-
ControlPlaneMachineImage: os.Getenv("E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
48-
ControlPlaneMachineCount: 1,
49-
WorkerMachineImage: os.Getenv("E2E_WORKER_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
50-
WorkerMachineCount: 1,
37+
Context(fmt.Sprintf("with kubernetes %s", v), Ordered, func() {
38+
var (
39+
ec *E2ECluster
40+
ctx context.Context
41+
)
42+
43+
BeforeEach(func() {
44+
ctx = context.Background()
45+
})
46+
47+
It("create new cluster", func() {
48+
ec = createE2ECluster(ctx, e2eCtx, ClusterConfig{
49+
SpecName: "basic-cluster-creation-" + v,
50+
NamespaceName: fmt.Sprintf("e2e-basic-cluster-creation-%d", i),
51+
ClusterName: fmt.Sprintf("simple-%d", i),
52+
KubernetesVersion: v,
53+
ControlPlaneMachineImage: os.Getenv("E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
54+
ControlPlaneMachineCount: 1,
55+
WorkerMachineImage: os.Getenv("E2E_WORKER_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
56+
WorkerMachineCount: 1,
57+
})
58+
Expect(ec).ToNot(BeNil())
59+
})
60+
61+
It("move from bootstrap to workload cluster", func() {
62+
Expect(ec).NotTo(BeNil(), "e2e cluster required")
63+
64+
clusterctl.InitManagementClusterAndWatchControllerLogs(ctx, clusterctl.InitManagementClusterAndWatchControllerLogsInput{
65+
ClusterProxy: ec.Refs.Workload,
66+
ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath,
67+
InfrastructureProviders: e2eCtx.E2EConfig.InfrastructureProviders(),
68+
LogFolder: path.Join(e2eCtx.Environment.artifactsPath, "clusters", ec.ClusterName, "init"),
69+
})
70+
71+
clusterctl.Move(ctx, clusterctl.MoveInput{
72+
LogFolder: path.Join(ec.E2EContext.Environment.artifactsPath, "clusters", ec.ClusterName, "move-to"),
73+
ClusterctlConfigPath: ec.E2EContext.Environment.ClusterctlConfigPath,
74+
FromKubeconfigPath: ec.E2EContext.Environment.kubeconfigPath,
75+
ToKubeconfigPath: ec.Refs.Workload.GetKubeconfigPath(),
76+
Namespace: ec.NamespaceName,
77+
})
78+
79+
cluster := &clusterv1.Cluster{}
80+
err := e2eCtx.Environment.Bootstrap.GetClient().Get(ctx, client.ObjectKey{
81+
Namespace: ec.NamespaceName,
82+
Name: ec.ClusterName,
83+
}, cluster)
84+
Expect(err).To(Satisfy(apierrors.IsNotFound), "cluster should have been moved")
85+
86+
cluster = &clusterv1.Cluster{}
87+
err = ec.Refs.Workload.GetClient().Get(ctx, client.ObjectKey{
88+
Namespace: ec.NamespaceName,
89+
Name: ec.ClusterName,
90+
}, cluster)
91+
Expect(err).ToNot(HaveOccurred(), "cluster should be present")
92+
})
93+
94+
It("move from workload to bootstrap cluster", func() {
95+
Expect(ec).NotTo(BeNil(), "e2e cluster required")
96+
97+
clusterctl.Move(ctx, clusterctl.MoveInput{
98+
LogFolder: path.Join(ec.E2EContext.Environment.artifactsPath, "clusters", ec.ClusterName, "move-back"),
99+
ClusterctlConfigPath: ec.E2EContext.Environment.ClusterctlConfigPath,
100+
FromKubeconfigPath: ec.Refs.Workload.GetKubeconfigPath(),
101+
ToKubeconfigPath: ec.E2EContext.Environment.kubeconfigPath,
102+
Namespace: ec.NamespaceName,
103+
})
104+
105+
cluster := &clusterv1.Cluster{}
106+
err := ec.Refs.Workload.GetClient().Get(ctx, client.ObjectKey{
107+
Namespace: ec.NamespaceName,
108+
Name: ec.ClusterName,
109+
}, cluster)
110+
Expect(err).To(Satisfy(apierrors.IsNotFound), "cluster should have been moved")
111+
112+
cluster = &clusterv1.Cluster{}
113+
err = e2eCtx.Environment.Bootstrap.GetClient().Get(ctx, client.ObjectKey{
114+
Namespace: ec.NamespaceName,
115+
Name: ec.ClusterName,
116+
}, cluster)
117+
Expect(err).ToNot(HaveOccurred(), "cluster should be present")
118+
})
119+
120+
It("delete cluster", func() {
121+
ec.Teardown(ctx)
122+
// TODO: expect resources to be gone
51123
})
52-
Expect(ec).ToNot(BeNil())
53124
})
54125
}
126+
55127
})
56128

57129
func createE2ECluster(ctx context.Context, e2eCtx *E2EContext, cfg ClusterConfig) *E2ECluster {
58130
ec := e2eCtx.NewE2ECluster(cfg)
59-
DeferCleanup(ec.Teardown, ctx)
60131

61132
ec.SetupMetalStackPreconditions(ctx)
62133
ec.SetupNamespace(ctx)

0 commit comments

Comments
 (0)