@@ -11,52 +11,124 @@ import (
1111 . "github.com/onsi/ginkgo/v2"
1212 . "github.com/onsi/gomega"
1313
14+ apierrors "k8s.io/apimachinery/pkg/api/errors"
15+ "sigs.k8s.io/controller-runtime/pkg/client"
16+
17+ clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1418 "sigs.k8s.io/cluster-api/test/framework"
19+ "sigs.k8s.io/cluster-api/test/framework/clusterctl"
1520)
1621
17- var _ = Describe ("Basic Cluster Creation" , Ordered , func () {
18- var (
19- ec * E2ECluster
20- )
22+ var _ = Describe ("Basic Cluster" , Ordered , func () {
2123
2224 BeforeAll (func () {
2325 e2eCtx = NewE2EContext ()
2426 e2eCtx .ProvideBootstrapCluster ()
2527 e2eCtx .CreateClusterctlConfig (context .TODO ())
2628 e2eCtx .InitManagementCluster (context .TODO ())
27-
28- DeferCleanup (e2eCtx .Teardown , context .TODO ())
29- })
30-
31- BeforeEach (func () {
32- ec = nil
3329 })
3430
3531 kubernetesVersions := strings .Split (os .Getenv ("E2E_KUBERNETES_VERSIONS" ), "," )
3632 Expect (kubernetesVersions ).ToNot (BeEmpty (), "E2E_KUBERNETES_VERSIONS must be set" )
3733
3834 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 ,
35+ Context (fmt .Sprintf ("with kubernetes %s" , v ), Ordered , func () {
36+ var (
37+ ec * E2ECluster
38+ ctx context.Context
39+ )
40+
41+ BeforeEach (func () {
42+ ctx = context .Background ()
43+ })
44+
45+ It ("create new cluster" , func () {
46+ ec = createE2ECluster (ctx , e2eCtx , ClusterConfig {
47+ SpecName : "basic-cluster-creation-" + v ,
48+ NamespaceName : fmt .Sprintf ("e2e-basic-cluster-creation-%d" , i ),
49+ ClusterName : fmt .Sprintf ("simple-%d" , i ),
50+ KubernetesVersion : v ,
51+ ControlPlaneMachineImage : os .Getenv ("E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX" ) + strings .TrimPrefix (v , "v" ),
52+ ControlPlaneMachineCount : 1 ,
53+ WorkerMachineImage : os .Getenv ("E2E_WORKER_MACHINE_IMAGE_PREFIX" ) + strings .TrimPrefix (v , "v" ),
54+ WorkerMachineCount : 1 ,
55+ })
56+ Expect (ec ).ToNot (BeNil ())
57+ })
58+
59+ It ("move from bootstrap to workload cluster" , func () {
60+ Expect (ec ).NotTo (BeNil (), "e2e cluster required" )
61+
62+ clusterctl .InitManagementClusterAndWatchControllerLogs (ctx , clusterctl.InitManagementClusterAndWatchControllerLogsInput {
63+ ClusterProxy : ec .Refs .Workload ,
64+ ClusterctlConfigPath : e2eCtx .Environment .ClusterctlConfigPath ,
65+ InfrastructureProviders : e2eCtx .E2EConfig .InfrastructureProviders (),
66+ LogFolder : path .Join (e2eCtx .Environment .artifactsPath , "clusters" , ec .ClusterName , "init" ),
67+ })
68+
69+ clusterctl .Move (ctx , clusterctl.MoveInput {
70+ LogFolder : path .Join (ec .E2EContext .Environment .artifactsPath , "clusters" , ec .ClusterName , "move-to" ),
71+ ClusterctlConfigPath : ec .E2EContext .Environment .ClusterctlConfigPath ,
72+ FromKubeconfigPath : ec .E2EContext .Environment .Bootstrap .GetKubeconfigPath (),
73+ ToKubeconfigPath : ec .Refs .Workload .GetKubeconfigPath (),
74+ Namespace : ec .NamespaceName ,
75+ })
76+
77+ cluster := & clusterv1.Cluster {}
78+ err := e2eCtx .Environment .Bootstrap .GetClient ().Get (ctx , client.ObjectKey {
79+ Namespace : ec .NamespaceName ,
80+ Name : ec .ClusterName ,
81+ }, cluster )
82+ Expect (err ).To (Satisfy (apierrors .IsNotFound ), "cluster should have been moved" )
83+
84+ cluster = & clusterv1.Cluster {}
85+ err = ec .Refs .Workload .GetClient ().Get (ctx , client.ObjectKey {
86+ Namespace : ec .NamespaceName ,
87+ Name : ec .ClusterName ,
88+ }, cluster )
89+ Expect (err ).ToNot (HaveOccurred (), "cluster should be present" )
90+ })
91+
92+ It ("move from workload to bootstrap cluster" , func () {
93+ Expect (ec ).NotTo (BeNil (), "e2e cluster required" )
94+
95+ clusterctl .Move (ctx , clusterctl.MoveInput {
96+ LogFolder : path .Join (ec .E2EContext .Environment .artifactsPath , "clusters" , ec .ClusterName , "move-back" ),
97+ ClusterctlConfigPath : ec .E2EContext .Environment .ClusterctlConfigPath ,
98+ FromKubeconfigPath : ec .Refs .Workload .GetKubeconfigPath (),
99+ ToKubeconfigPath : ec .E2EContext .Environment .Bootstrap .GetKubeconfigPath (),
100+ Namespace : ec .NamespaceName ,
101+ })
102+
103+ cluster := & clusterv1.Cluster {}
104+ err := ec .Refs .Workload .GetClient ().Get (ctx , client.ObjectKey {
105+ Namespace : ec .NamespaceName ,
106+ Name : ec .ClusterName ,
107+ }, cluster )
108+ Expect (err ).To (Satisfy (apierrors .IsNotFound ), "cluster should have been moved" )
109+
110+ cluster = & clusterv1.Cluster {}
111+ err = e2eCtx .Environment .Bootstrap .GetClient ().Get (ctx , client.ObjectKey {
112+ Namespace : ec .NamespaceName ,
113+ Name : ec .ClusterName ,
114+ }, cluster )
115+ Expect (err ).ToNot (HaveOccurred (), "cluster should be present" )
116+ })
117+
118+ It ("delete cluster" , func () {
119+ ec .Teardown (ctx )
120+ // TODO: expect resources to be gone
51121 })
52- Expect (ec ).ToNot (BeNil ())
53122 })
54123 }
124+
125+ It ("teardown management cluster" , func () {
126+ e2eCtx .Teardown (context .Background ())
127+ })
55128})
56129
57130func createE2ECluster (ctx context.Context , e2eCtx * E2EContext , cfg ClusterConfig ) * E2ECluster {
58131 ec := e2eCtx .NewE2ECluster (cfg )
59- DeferCleanup (ec .Teardown , ctx )
60132
61133 ec .SetupMetalStackPreconditions (ctx )
62134 ec .SetupNamespace (ctx )
0 commit comments