Skip to content

Commit 84cddbd

Browse files
committed
E2E tests
1 parent 13eb94d commit 84cddbd

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ generate-e2e-templates-main: $(KUSTOMIZE) ## Generate test templates for the mai
374374
cp "$(RELEASE_DIR)/main/cluster-template-ignition.yaml" "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/base/cluster-template-ignition.yaml"
375375
"$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/base" > "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/cluster-template.yaml"
376376
"$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/hw-upgrade" > "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/cluster-template-hw-upgrade.yaml"
377+
"$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/multi-disk" > "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/cluster-template-multi-disk.yaml"
377378
"$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/storage-policy" > "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/cluster-template-storage-policy.yaml"
378379
"$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/conformance" > "$(E2E_GOVMOMI_TEMPLATE_DIR)/main/cluster-template-conformance.yaml"
379380
# Since CAPI uses different flavor names for KCP and MD remediation using MHC

test/e2e/config/vsphere.yaml

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

0 commit comments

Comments
 (0)