Skip to content

Commit d4d7f0d

Browse files
committed
Started work on 2 cluster e2e test
1 parent b3dcbdb commit d4d7f0d

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

test/e2e/config/cloudstack.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ providers:
8383
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-invalid-worker-offering.yaml"
8484
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-node-drain.yaml"
8585
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-machine-remediation.yaml"
86+
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-second-cluster.yaml"
8687
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
8788
versions:
8889
- name: v1.0.0
@@ -109,6 +110,7 @@ variables:
109110
CLOUDSTACK_NETWORK_NAME: isolated-for-e2e-1
110111
CLUSTER_ENDPOINT_IP: 172.16.2.199
111112
CLUSTER_ENDPOINT_PORT: 6443
113+
CLUSTER_ENDPOINT_PORT_2: 6444
112114
CLOUDSTACK_CONTROL_PLANE_MACHINE_OFFERING: "Large Instance"
113115
CLOUDSTACK_INVALID_CONTROL_PLANE_MACHINE_OFFERING: "OfferingXXXX"
114116
CLOUDSTACK_EXTREMELY_LARGE_CONTROL_PLANE_MACHINE_OFFERING: "Extremely Large Instance"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
2+
kind: CloudStackCluster
3+
metadata:
4+
name: ${CLUSTER_NAME}
5+
spec:
6+
controlPlaneEndpoint:
7+
port: ${CLUSTER_ENDPOINT_PORT_2}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bases:
2+
- ../bases/cluster-with-kcp.yaml
3+
- ../bases/md.yaml
4+
5+
patchesStrategicMerge:
6+
- ./cloudstack-cluster.yaml

test/e2e/second_cluster.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
"path/filepath"
24+
25+
. "github.com/onsi/ginkgo"
26+
. "github.com/onsi/gomega"
27+
corev1 "k8s.io/api/core/v1"
28+
"k8s.io/utils/pointer"
29+
30+
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
31+
"sigs.k8s.io/cluster-api/util"
32+
)
33+
34+
// SecondClusterSpec implements a test that verifies two clusters can co-exist.
35+
func SecondClusterSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
36+
37+
const specName = "second-cluster"
38+
39+
var (
40+
input CommonSpecInput
41+
namespace *corev1.Namespace
42+
cancelWatches context.CancelFunc
43+
clusterResources1 *clusterctl.ApplyClusterTemplateAndWaitResult
44+
clusterResources2 *clusterctl.ApplyClusterTemplateAndWaitResult
45+
)
46+
47+
createCluster := func(flavor string, resources *clusterctl.ApplyClusterTemplateAndWaitResult) {
48+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
49+
ClusterProxy: input.BootstrapClusterProxy,
50+
CNIManifestPath: input.E2EConfig.GetVariable(CNIPath),
51+
ConfigCluster: clusterctl.ConfigClusterInput{
52+
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()),
53+
ClusterctlConfigPath: input.ClusterctlConfigPath,
54+
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(),
55+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
56+
Flavor: flavor,
57+
Namespace: namespace.Name,
58+
ClusterName: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
59+
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersion),
60+
ControlPlaneMachineCount: pointer.Int64Ptr(1),
61+
WorkerMachineCount: pointer.Int64Ptr(1),
62+
},
63+
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"),
64+
WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),
65+
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
66+
}, resources)
67+
}
68+
69+
BeforeEach(func() {
70+
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
71+
input = inputGetter()
72+
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
73+
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
74+
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
75+
Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)
76+
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion))
77+
Expect(input.E2EConfig.Variables).To(HaveValidVersion(input.E2EConfig.GetVariable(KubernetesVersion)))
78+
79+
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
80+
namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder)
81+
clusterResources1 = new(clusterctl.ApplyClusterTemplateAndWaitResult)
82+
clusterResources2 = new(clusterctl.ApplyClusterTemplateAndWaitResult)
83+
})
84+
85+
It("should successfully add and remove a second cluster", func() {
86+
By("create the first cluster")
87+
createCluster(clusterctl.DefaultFlavor, clusterResources1)
88+
89+
By("create the second cluster")
90+
createCluster("second-cluster", clusterResources2)
91+
92+
By("verify that the second cluster works")
93+
94+
By("delete the second cluster")
95+
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources2.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
96+
97+
By("verify that the second cluster is gone")
98+
99+
By("verify that the first cluster still works")
100+
101+
By("PASSED!")
102+
})
103+
104+
AfterEach(func() {
105+
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
106+
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources1.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
107+
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources2.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
108+
})
109+
}

test/e2e/second_cluster_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//go:build e2e
2+
// +build e2e
3+
4+
/*
5+
Copyright 2021 The Kubernetes Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package e2e
21+
22+
import (
23+
"context"
24+
. "github.com/onsi/ginkgo"
25+
)
26+
27+
var _ = Describe("with a second cluster [SecondCluster]", func() {
28+
29+
SecondClusterSpec(context.TODO(), func() CommonSpecInput {
30+
return CommonSpecInput{
31+
E2EConfig: e2eConfig,
32+
ClusterctlConfigPath: clusterctlConfigPath,
33+
BootstrapClusterProxy: bootstrapClusterProxy,
34+
ArtifactFolder: artifactFolder,
35+
SkipCleanup: skipCleanup,
36+
}
37+
})
38+
39+
})

0 commit comments

Comments
 (0)