Skip to content

Commit 737980a

Browse files
committed
E2E tests
1 parent 13eb94d commit 737980a

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
2+
kind: VSphereMachineTemplate
3+
metadata:
4+
name: '${CLUSTER_NAME}'
5+
namespace: '${NAMESPACE}'
6+
spec:
7+
template:
8+
spec:
9+
dataDisks:
10+
- name: "etcd"
11+
sizeGiB: 10
12+
- name: "container-images"
13+
sizeGiB: 20
14+
---
15+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
16+
kind: VSphereMachineTemplate
17+
metadata:
18+
name: '${CLUSTER_NAME}-worker'
19+
namespace: '${NAMESPACE}'
20+
spec:
21+
template:
22+
spec:
23+
dataDisks:
24+
- name: "container-images"
25+
sizeGiB: 20
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../base
5+
patchesStrategicMerge:
6+
- data-disks-patch.yaml

test/e2e/multi-disk_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Copyright 2022 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+
"strings"
23+
24+
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
26+
"github.com/vmware/govmomi/vim25/types"
27+
corev1 "k8s.io/api/core/v1"
28+
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
29+
. "sigs.k8s.io/cluster-api/test/framework/ginkgoextensions"
30+
capiutil "sigs.k8s.io/cluster-api/util"
31+
)
32+
33+
type DiskSpecInput struct {
34+
InfraClients
35+
Global GlobalInput
36+
SpecName string
37+
Namespace *corev1.Namespace
38+
Template string
39+
ToVersion string
40+
}
41+
42+
var _ = Describe("Multi-Disk support", func() {
43+
const specName = "multi-disk"
44+
Setup(specName, func(testSpecificSettingsGetter func() testSettings) {
45+
var (
46+
namespace *corev1.Namespace
47+
)
48+
49+
BeforeEach(func() {
50+
Expect(bootstrapClusterProxy).NotTo(BeNil(), "BootstrapClusterProxy can't be nil")
51+
namespace = setupSpecNamespace(specName, testSpecificSettingsGetter().PostNamespaceCreatedFunc)
52+
})
53+
54+
AfterEach(func() {
55+
cleanupSpecNamespace(namespace)
56+
})
57+
58+
It("should create control plane with multiple disks", func() {
59+
Expect(e2eConfig.GetVariable("VSPHERE_TEMPLATE")).NotTo(BeEmpty())
60+
61+
VerifyDisks(ctx, DiskSpecInput{
62+
SpecName: specName,
63+
Namespace: namespace,
64+
Template: e2eConfig.GetVariable("VSPHERE_TEMPLATE"),
65+
ToVersion: "vmx-17",
66+
InfraClients: InfraClients{
67+
Client: vsphereClient,
68+
RestClient: restClient,
69+
Finder: vsphereFinder,
70+
},
71+
Global: GlobalInput{
72+
BootstrapClusterProxy: bootstrapClusterProxy,
73+
ClusterctlConfigPath: testSpecificSettingsGetter().ClusterctlConfigPath,
74+
E2EConfig: e2eConfig,
75+
ArtifactFolder: artifactFolder,
76+
},
77+
})
78+
})
79+
})
80+
})
81+
82+
func VerifyDisks(ctx context.Context, input DiskSpecInput) {
83+
var (
84+
specName = input.SpecName
85+
namespace = input.Namespace
86+
clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult)
87+
)
88+
89+
clusterName := fmt.Sprintf("%s-%s", specName, capiutil.RandomString(6))
90+
By("Creating a cluster")
91+
configCluster := defaultConfigCluster(clusterName, namespace.Name, specName, 1, 1, input.Global)
92+
93+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
94+
ClusterProxy: input.Global.BootstrapClusterProxy,
95+
ConfigCluster: configCluster,
96+
WaitForClusterIntervals: input.Global.E2EConfig.GetIntervals(specName, "wait-cluster"),
97+
WaitForControlPlaneIntervals: input.Global.E2EConfig.GetIntervals(specName, "wait-control-plane"),
98+
WaitForMachineDeployments: input.Global.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
99+
}, clusterResources)
100+
101+
Byf("Fetching the VSphereVM objects for the cluster %s", clusterName)
102+
vms := getVSphereVMsForCluster(clusterName, namespace.Name)
103+
104+
By("Verifying the disks attached to the VMs")
105+
for _, vm := range vms.Items {
106+
vmObj, err := input.Finder.VirtualMachine(ctx, vm.Name)
107+
Expect(err).NotTo(HaveOccurred())
108+
109+
devices, err := vmObj.Device(ctx)
110+
Expect(err).NotTo(HaveOccurred())
111+
112+
// We expect control plane VMs to have 3 disks, and the compute VMs will have 2.
113+
disks := devices.SelectByType((*types.VirtualDisk)(nil))
114+
if strings.Contains(vm.Name, "-worker") {
115+
Expect(len(disks)).To(HaveLen(2))
116+
} else {
117+
Expect(len(disks)).To(HaveLen(3))
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)