Skip to content

Commit

Permalink
Add ControllerModifyVolume e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Catlett <conncatl@amazon.com>
  • Loading branch information
ConnorJC3 committed Feb 21, 2024
1 parent 8290f1b commit 2171a69
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ e2e/single-az: bin/helm bin/ginkgo
TEST_PATH=./tests/e2e/... \
GINKGO_FOCUS="\[ebs-csi-e2e\] \[single-az\]" \
GINKGO_PARALLEL=5 \
HELM_EXTRA_FLAGS="--set=controller.volumeModificationFeature.enabled=true" \
HELM_EXTRA_FLAGS="--set=controller.volumeModificationFeature.enabled=true,sidecars.provisioner.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true',sidecars.resizer.additionalArgs[0]='--feature-gates=VolumeAttributesClass=true'" \
./hack/e2e/run.sh

.PHONY: e2e/multi-az
Expand Down
8 changes: 8 additions & 0 deletions hack/e2e/kops/patch-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
spec:
kubeAPIServer:
featureGates:
VolumeAttributesClass: "true"
runtimeConfig:
storage.k8s.io/v1alpha1: "true"
kubeControllerManager:
featureGates:
VolumeAttributesClass: "true"
additionalPolicies:
node: |
[
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/modify_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [modify-volume] Modifying a PVC", fu
for testName, modifyVolumeTest := range modifyVolumeTests {
modifyVolumeTest := modifyVolumeTest
Context(testName, func() {
It("will modify associated PV and EBS Volume", func() {
modifyVolumeTest.Run(cs, ns, ebsDriver)
It("will modify associated PV and EBS Volume via volume-modifier-for-k8s", func() {
modifyVolumeTest.Run(cs, ns, ebsDriver, testsuites.VolumeModifierForK8s)
})
It("will modify associated PV and EBS Volume via external-resizer", func() {
modifyVolumeTest.Run(cs, ns, ebsDriver, testsuites.ExternalResizier)
})
})
}
Expand Down
18 changes: 17 additions & 1 deletion tests/e2e/testsuites/e2e_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package testsuites
import (
"context"
"fmt"
"time"

"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
"time"
)

const (
Expand Down Expand Up @@ -139,6 +140,21 @@ func WaitForPvToModify(c clientset.Interface, ns *v1.Namespace, pvName string, e
return fmt.Errorf("gave up after waiting %v for pv %q to complete modifying", timeout, pvName)
}

// WaitForVacToApplyToPv waits for a PV's VAC to match the PVC's VAC
func WaitForVacToApplyToPv(c clientset.Interface, ns *v1.Namespace, pvName string, expectedVac string, timeout time.Duration, interval time.Duration) error {
framework.Logf("waiting up to %v for pv in namespace %q to be modified via VAC", timeout, ns.Name)

for start := time.Now(); time.Since(start) < timeout; time.Sleep(interval) {
modifyingPv, _ := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{})

if modifyingPv.Spec.VolumeAttributesClassName != nil && *modifyingPv.Spec.VolumeAttributesClassName == expectedVac {
framework.Logf("vac updated to %v", *modifyingPv.Spec.VolumeAttributesClassName)
return nil
}
}
return fmt.Errorf("gave up after waiting %v for pv %q to complete modifying via VAC", timeout, pvName)
}

func CreateVolumeDetails(createVolumeParameters map[string]string, volumeSize string) *VolumeDetails {
allowVolumeExpansion := true

Expand Down
35 changes: 31 additions & 4 deletions tests/e2e/testsuites/modify_volume_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package testsuites
import (
"context"
"fmt"

"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver"
. "github.com/onsi/ginkgo/v2"
v1 "k8s.io/api/core/v1"
"k8s.io/api/storage/v1alpha1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
Expand All @@ -41,7 +43,14 @@ var (
volumeSize = "10Gi" // Different from driver.MinimumSizeForVolumeType to simplify iops, throughput, volumeType modification
)

func (modifyVolumeTest *ModifyVolumeTest) Run(c clientset.Interface, ns *v1.Namespace, ebsDriver driver.PVTestDriver) {
type ModifyTestType int64

const (
VolumeModifierForK8s ModifyTestType = iota
ExternalResizier
)

func (modifyVolumeTest *ModifyVolumeTest) Run(c clientset.Interface, ns *v1.Namespace, ebsDriver driver.PVTestDriver, testType ModifyTestType) {
By("setting up pvc")
volumeDetails := CreateVolumeDetails(modifyVolumeTest.CreateVolumeParameters, volumeSize)
testVolume, _ := volumeDetails.SetupDynamicPersistentVolumeClaim(c, ns, ebsDriver)
Expand All @@ -59,7 +68,22 @@ func (modifyVolumeTest *ModifyVolumeTest) Run(c clientset.Interface, ns *v1.Name

By("modifying the pvc")
modifyingPvc, _ := c.CoreV1().PersistentVolumeClaims(ns.Name).Get(context.TODO(), testVolume.persistentVolumeClaim.Name, metav1.GetOptions{})
AnnotatePvc(modifyingPvc, modifyVolumeTest.ModifyVolumeAnnotations)
if testType == VolumeModifierForK8s {
AnnotatePvc(modifyingPvc, modifyVolumeTest.ModifyVolumeAnnotations)
} else if testType == ExternalResizier {
vac, err := c.StorageV1alpha1().VolumeAttributesClasses().Create(context.Background(), &v1alpha1.VolumeAttributesClass{
ObjectMeta: metav1.ObjectMeta{
Name: formatOptionMountPod.pod.Name,
Namespace: ns.Name,
},
DriverName: "ebs.csi.aws.com",
Parameters: modifyVolumeTest.ModifyVolumeAnnotations,
}, metav1.CreateOptions{})
framework.ExpectNoError(err)

vacName := vac.Name
modifyingPvc.Spec.VolumeAttributesClassName = &vacName
}

var updatedPvcSize resource.Quantity
if modifyVolumeTest.ShouldResizeVolume {
Expand All @@ -73,9 +97,12 @@ func (modifyVolumeTest *ModifyVolumeTest) Run(c clientset.Interface, ns *v1.Name
}
framework.Logf("updated pvc: %s\n", modifiedPvc.Annotations)

// Confirm Volume Modified
By("wait for and confirm pv modification")
err = WaitForPvToModify(c, ns, testVolume.persistentVolume.Name, modifyVolumeTest.ModifyVolumeAnnotations, DefaultModificationTimeout, DefaultK8sApiPollingInterval)
if testType == VolumeModifierForK8s {
err = WaitForPvToModify(c, ns, testVolume.persistentVolume.Name, modifyVolumeTest.ModifyVolumeAnnotations, DefaultModificationTimeout, DefaultK8sApiPollingInterval)
} else if testType == ExternalResizier {
err = WaitForVacToApplyToPv(c, ns, testVolume.persistentVolume.Name, *modifyingPvc.Spec.VolumeAttributesClassName, DefaultModificationTimeout, DefaultK8sApiPollingInterval)
}
framework.ExpectNoError(err, fmt.Sprintf("fail to modify pv(%s): %v", modifyingPvc.Name, err))
if modifyVolumeTest.ShouldResizeVolume {
err = WaitForPvToResize(c, ns, testVolume.persistentVolume.Name, updatedPvcSize, DefaultResizeTimout, DefaultK8sApiPollingInterval)
Expand Down

0 comments on commit 2171a69

Please sign in to comment.