Skip to content

Commit

Permalink
Add an integ test
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Jan 31, 2024
1 parent bed4bf9 commit db2dbe8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
}, nil
}

// ControllerExpandVolume resizes/updates the volume (not supported yet on Exoscale Public API)
// ControllerExpandVolume resizes Block Storage volume.
func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
klog.V(4).Infof("ControllerExpandVolume")
_, volumeID, err := getExoscaleID(req.GetVolumeId())
Expand Down
54 changes: 54 additions & 0 deletions internal/integ/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"

"github.com/exoscale/exoscale/csi-driver/internal/integ/cluster"
"github.com/exoscale/exoscale/csi-driver/internal/integ/k8s"
Expand Down Expand Up @@ -167,6 +170,57 @@ func TestDeleteVolume(t *testing.T) {
// TODO (sauterp) once ego v3 is available check if volume is deleted (and retainPolicy)
}

func TestVolumeExpand(t *testing.T) {
ns := k8s.CreateTestNamespace(t, cluster.Get().K8s, "vol-expand")

ns.Apply(basicPVC)
ns.Apply(basicDeployment)

go ns.K.PrintEvents(ns.CTX, ns.Name)

var storage1 resource.Quantity
awaitExpectation(t, "Bound", func() interface{} {
pvc, err := ns.K.ClientSet.CoreV1().PersistentVolumeClaims(ns.Name).Get(ns.CTX, "my-sbs-pvc", metav1.GetOptions{})
assert.NoError(t, err)

storage := pvc.Status.Capacity.Storage()
require.NotNil(t, storage)
storage1 = *storage

return pvc.Status.Phase
})

awaitExpectation(t, "Bound", func() interface{} {
updatedPVC, err := ns.K.ClientSet.CoreV1().PersistentVolumeClaims(ns.Name).Patch(
ns.CTX,
"my-sbs-pvc",
types.MergePatchType,
[]byte(`{"spec":{"resources":{"requests":{"storage":"300Gi"}}}}`),
metav1.PatchOptions{},
)
assert.NoError(t, err)

return updatedPVC.Status.Phase
})

var storage2 resource.Quantity
awaitExpectation(t, "Bound", func() interface{} {
pvc, err := ns.K.ClientSet.CoreV1().PersistentVolumeClaims(ns.Name).Get(ns.CTX, "my-sbs-pvc", metav1.GetOptions{})
assert.NoError(t, err)

storage := pvc.Status.Capacity.Storage()
require.NotNil(t, storage)
storage2 = *storage

return pvc.Status.Phase
})

// Cmp returns 0 if the quantity is equal to y,
// -1 if the quantity is less than y,
// or 1 if the quantity is greater than y.
require.Equal(t, 1, storage1.Cmp(storage2))
}

const basicSnapshot = `
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
Expand Down

0 comments on commit db2dbe8

Please # to comment.