Skip to content

Commit ba687f5

Browse files
committed
Added Verification Of Expected Parameters for e2e tests
1 parent fbbc758 commit ba687f5

File tree

4 files changed

+260
-0
lines changed

4 files changed

+260
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2025 The Kubernetes Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the 'License');
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an 'AS IS' BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package testsuites
16+
17+
import (
18+
"strconv"
19+
20+
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver"
21+
. "github.com/onsi/ginkgo/v2"
22+
v1 "k8s.io/api/core/v1"
23+
"k8s.io/apimachinery/pkg/api/resource"
24+
clientset "k8s.io/client-go/kubernetes"
25+
)
26+
27+
// DynamicallyProvisionedVolumePropertiesTest will create a pod along with a volume.
28+
// It will then wait until the volume is created in order to verify that the volume
29+
// was created with parametes inputted at by the user.
30+
type DynamicallyProvisionedVolumePropertiesTest struct {
31+
CreateVolumeParameters map[string]string
32+
ClaimSize string
33+
}
34+
35+
func (t *DynamicallyProvisionedVolumePropertiesTest) Run(c clientset.Interface, ns *v1.Namespace, ebsDriver driver.PVTestDriver) {
36+
By("setting up pvc")
37+
volumeDetails := CreateVolumeDetails(t.CreateVolumeParameters, t.ClaimSize)
38+
testVolume, _ := volumeDetails.SetupDynamicPersistentVolumeClaim(c, ns, ebsDriver)
39+
40+
By("deploying pod with volume")
41+
pod := createPodWithVolume(c, ns, "", testVolume, volumeDetails)
42+
pod.WaitForSuccess()
43+
44+
By("verifying volume properties before cleanup")
45+
volumeID := testVolume.persistentVolume.Spec.CSI.VolumeHandle
46+
47+
verification := ExpectedParameters{}
48+
49+
quantity, _ := resource.ParseQuantity(t.ClaimSize)
50+
sizeGiB := int32(quantity.Value() / (1024 * 1024 * 1024))
51+
verification.Size = &sizeGiB
52+
53+
if iopsStr, ok := t.CreateVolumeParameters[Iops]; ok {
54+
expectedIOPS, _ := strconv.ParseInt(iopsStr, 10, 32)
55+
iops := int32(expectedIOPS)
56+
verification.IOPS = &iops
57+
}
58+
59+
if throughputStr, ok := t.CreateVolumeParameters[Throughput]; ok {
60+
expectedThroughput, _ := strconv.ParseInt(throughputStr, 10, 32)
61+
throughput := int32(expectedThroughput)
62+
verification.Throughput = &throughput
63+
}
64+
65+
if volType, ok := t.CreateVolumeParameters[VolumeType]; ok {
66+
verification.VolumeType = &volType
67+
}
68+
69+
VerifyVolumeProperties(volumeID, verification)
70+
71+
By("cleaning up pod")
72+
pod.Cleanup()
73+
74+
By("cleaning up pvc")
75+
testVolume.Cleanup()
76+
}

tests/e2e/testsuites/e2e_utils.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"fmt"
2020
"time"
2121

22+
"github.com/aws/aws-sdk-go-v2/config"
23+
"github.com/aws/aws-sdk-go-v2/service/ec2"
2224
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util"
2325
v1 "k8s.io/api/core/v1"
2426
"k8s.io/apimachinery/pkg/api/resource"
@@ -181,3 +183,62 @@ func PrefixAnnotations(prefix string, parameters map[string]string) map[string]s
181183
}
182184
return result
183185
}
186+
187+
type ExpectedParameters struct {
188+
Size *int32
189+
IOPS *int32
190+
Throughput *int32
191+
VolumeType *string
192+
}
193+
194+
func VerifyVolumeProperties(volumeID string, verification ExpectedParameters) {
195+
cfg, err := config.LoadDefaultConfig(context.Background())
196+
framework.ExpectNoError(err, "failed to load AWS config")
197+
198+
ec2Client := ec2.NewFromConfig(cfg)
199+
resp, err := ec2Client.DescribeVolumes(context.Background(), &ec2.DescribeVolumesInput{
200+
VolumeIds: []string{volumeID},
201+
})
202+
framework.ExpectNoError(err, fmt.Sprintf("failed to describe volume %s", volumeID))
203+
if len(resp.Volumes) == 0 {
204+
framework.Failf("volume %s not found", volumeID)
205+
}
206+
volume := &resp.Volumes[0]
207+
208+
if verification.Size != nil && volume.Size != nil {
209+
if *volume.Size != *verification.Size {
210+
framework.Failf("volume size mismatch: expected %d GiB, got %d GiB", *verification.Size, *volume.Size)
211+
}
212+
}
213+
214+
if verification.IOPS != nil && volume.Iops != nil {
215+
if *volume.Iops != *verification.IOPS {
216+
framework.Failf("volume IOPS mismatch: expected %d, got %d", *verification.IOPS, *volume.Iops)
217+
}
218+
}
219+
220+
if verification.Throughput != nil && volume.Throughput != nil {
221+
if *volume.Throughput != *verification.Throughput {
222+
framework.Failf("volume throughput mismatch: expected %d, got %d", *verification.Throughput, *volume.Throughput)
223+
}
224+
}
225+
226+
if verification.VolumeType != nil {
227+
if string(volume.VolumeType) != *verification.VolumeType {
228+
framework.Failf("volume type mismatch: expected %s, got %s", *verification.VolumeType, volume.VolumeType)
229+
}
230+
}
231+
232+
var size, iops, throughput int32
233+
if volume.Size != nil {
234+
size = *volume.Size
235+
}
236+
if volume.Iops != nil {
237+
iops = *volume.Iops
238+
}
239+
if volume.Throughput != nil {
240+
throughput = *volume.Throughput
241+
}
242+
framework.Logf("Volume %s verified: Size=%d GiB, IOPS=%d, Throughput=%d, Type=%s",
243+
volumeID, size, iops, throughput, volume.VolumeType)
244+
}

tests/e2e/testsuites/modify_volume_tester.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package testsuites
1717
import (
1818
"context"
1919
"fmt"
20+
"strconv"
2021

2122
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util"
2223
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver"
@@ -112,6 +113,38 @@ func (modifyVolumeTest *ModifyVolumeTest) Run(c clientset.Interface, ns *v1.Name
112113
err = WaitForPvToResize(c, ns, testVolume.persistentVolume.Name, updatedPvcSize, DefaultResizeTimout, DefaultK8sAPIPollingInterval)
113114
framework.ExpectNoError(err, fmt.Sprintf("fail to resize pv(%s): %v", modifyingPvc.Name, err))
114115
}
116+
117+
By("verifying volume properties before cleanup")
118+
verifyVolumeBeforeCleanup(testVolume, modifyVolumeTest.ModifyVolumeParameters, modifyVolumeTest.ShouldResizeVolume, updatedPvcSize)
119+
}
120+
121+
func verifyVolumeBeforeCleanup(testVolume *TestPersistentVolumeClaim, modifyParams map[string]string, resized bool, updatedSize resource.Quantity) {
122+
volumeID := testVolume.persistentVolume.Spec.CSI.VolumeHandle
123+
124+
verification := ExpectedParameters{}
125+
126+
if resized {
127+
expectedSizeGiB := int32(updatedSize.Value() / (1024 * 1024 * 1024))
128+
verification.Size = &expectedSizeGiB
129+
}
130+
131+
if iopsStr, ok := modifyParams[Iops]; ok {
132+
expectedIOPS, _ := strconv.ParseInt(iopsStr, 10, 32)
133+
iops := int32(expectedIOPS)
134+
verification.IOPS = &iops
135+
}
136+
137+
if throughputStr, ok := modifyParams[Throughput]; ok {
138+
expectedThroughput, _ := strconv.ParseInt(throughputStr, 10, 32)
139+
throughput := int32(expectedThroughput)
140+
verification.Throughput = &throughput
141+
}
142+
143+
if volType, ok := modifyParams[VolumeType]; ok {
144+
verification.VolumeType = &volType
145+
}
146+
147+
VerifyVolumeProperties(volumeID, verification)
115148
}
116149

117150
func attemptInvalidModification(c clientset.Interface, ns *v1.Namespace, testVolume *TestPersistentVolumeClaim) {

tests/e2e/volume_properties.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2025 The Kubernetes Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the 'License');
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an 'AS IS' BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
awscloud "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
19+
ebscsidriver "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver"
20+
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver"
21+
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/testsuites"
22+
. "github.com/onsi/ginkgo/v2"
23+
v1 "k8s.io/api/core/v1"
24+
clientset "k8s.io/client-go/kubernetes"
25+
"k8s.io/kubernetes/test/e2e/framework"
26+
admissionapi "k8s.io/pod-security-admission/api"
27+
)
28+
29+
var _ = Describe("[ebs-csi-e2e] [single-az] Volume Properties Verification", func() {
30+
f := framework.NewDefaultFramework("ebs")
31+
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
32+
33+
var (
34+
cs clientset.Interface
35+
ns *v1.Namespace
36+
ebsDriver driver.PVTestDriver
37+
)
38+
39+
BeforeEach(func() {
40+
cs = f.ClientSet
41+
ns = f.Namespace
42+
ebsDriver = driver.InitEbsCSIDriver()
43+
})
44+
45+
It("should create a gp3 volume with custom IOPS", func() {
46+
test := testsuites.DynamicallyProvisionedVolumePropertiesTest{
47+
CreateVolumeParameters: map[string]string{
48+
ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeGP3,
49+
ebscsidriver.IopsKey: "4000",
50+
},
51+
ClaimSize: "10Gi",
52+
}
53+
test.Run(cs, ns, ebsDriver)
54+
})
55+
56+
It("should create a gp3 volume with custom IOPS and throughput", func() {
57+
test := testsuites.DynamicallyProvisionedVolumePropertiesTest{
58+
CreateVolumeParameters: map[string]string{
59+
ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeGP3,
60+
ebscsidriver.IopsKey: "5000",
61+
ebscsidriver.ThroughputKey: "250",
62+
},
63+
ClaimSize: "10Gi",
64+
}
65+
test.Run(cs, ns, ebsDriver)
66+
})
67+
68+
It("should create a gp3 volume with custom IOPS, throughput, and tags", func() {
69+
test := testsuites.DynamicallyProvisionedVolumePropertiesTest{
70+
CreateVolumeParameters: map[string]string{
71+
ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeGP3,
72+
ebscsidriver.IopsKey: "4000",
73+
ebscsidriver.ThroughputKey: "150",
74+
},
75+
ClaimSize: "10Gi",
76+
}
77+
test.Run(cs, ns, ebsDriver)
78+
})
79+
80+
It("should create an io2 volume with custom IOPS", func() {
81+
test := testsuites.DynamicallyProvisionedVolumePropertiesTest{
82+
CreateVolumeParameters: map[string]string{
83+
ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeIO2,
84+
ebscsidriver.IopsKey: "10000",
85+
},
86+
ClaimSize: "10Gi",
87+
}
88+
test.Run(cs, ns, ebsDriver)
89+
})
90+
})

0 commit comments

Comments
 (0)