-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
var _ = Describe("Persistent Volume", Label(smoke), func() { | ||
DescribeTable("should provision PVCs", func(ctx context.Context, pvcName string) { | ||
const namespace = "default" | ||
manifest := fmt.Sprintf("static_resources/pvc-%s.yaml", pvcName) | ||
podName := fmt.Sprintf("bb-%s", pvcName) | ||
By(fmt.Sprintf("Creating a pod with %s", pvcName)) | ||
|
||
f, err := staticResources.Open(manifest) | ||
Expect(err).NotTo(HaveOccurred()) | ||
defer func() { | ||
err = f.Close() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}() | ||
pod, err := loadResourcesFromYaml(f) | ||
Expect(err).NotTo(HaveOccurred()) | ||
createResources(ctx, pod...) | ||
|
||
DeferCleanup(func(ctx context.Context) { | ||
cleanupResources(ctx, pod...) | ||
}) | ||
|
||
expectPodRunning(ctx, namespace, podName) | ||
expectPVCBound(ctx, namespace, pvcName) | ||
|
||
pvc := GetK8sObjectWithRetry(ctx, clients.Kubernetes.CoreV1().PersistentVolumeClaims(namespace).Get, pvcName, metav1.GetOptions{}) | ||
pvName := pvc.Spec.VolumeName | ||
Expect(pvName).NotTo(BeEmpty()) | ||
expectPVBound(ctx, pvName) | ||
}, | ||
Entry(nil, "azurefile-csi"), | ||
Entry(nil, "managed-csi"), | ||
Entry(nil, "managed-csi-encrypted-cmk"), | ||
) | ||
}) | ||
|
||
func expectPVCBound(ctx context.Context, namespace, name string) { | ||
GinkgoHelper() | ||
By("Checking the PVC status") | ||
Eventually(func(g Gomega, ctx context.Context) { | ||
pvc, err := clients.Kubernetes.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, name, metav1.GetOptions{}) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(pvc.Status.Phase).To(Equal(corev1.ClaimBound)) | ||
}, DefaultEventuallyTimeout, 10*time.Second, ctx).Should(Succeed()) | ||
} | ||
|
||
func expectPVBound(ctx context.Context, name string) { | ||
GinkgoHelper() | ||
By("Checking the PV status") | ||
Eventually(func(g Gomega, ctx context.Context) { | ||
pv, err := clients.Kubernetes.CoreV1().PersistentVolumes().Get(ctx, name, metav1.GetOptions{}) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(pv.Status.Phase).To(Equal(corev1.VolumeBound)) | ||
}, DefaultEventuallyTimeout, 10*time.Second, ctx).Should(Succeed()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: azurefile-csi | ||
namespace: default | ||
spec: | ||
storageClassName: azurefile-csi | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: bb-azurefile-csi | ||
namespace: default | ||
spec: | ||
containers: | ||
- image: mcr.microsoft.com/cbl-mariner/busybox:2.0 | ||
command: | ||
- sleep | ||
- "3600" | ||
imagePullPolicy: IfNotPresent | ||
name: busybox | ||
volumeMounts: | ||
- mountPath: "/pv" | ||
name: pv | ||
restartPolicy: Always | ||
volumes: | ||
- name: pv | ||
persistentVolumeClaim: | ||
claimName: azurefile-csi |
34 changes: 34 additions & 0 deletions
34
test/e2e/static_resources/pvc-managed-csi-encrypted-cmk.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: managed-csi-encrypted-cmk | ||
namespace: default | ||
spec: | ||
storageClassName: managed-csi-encrypted-cmk | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: bb-managed-csi-encrypted-cmk | ||
namespace: default | ||
spec: | ||
containers: | ||
- image: mcr.microsoft.com/cbl-mariner/busybox:2.0 | ||
command: | ||
- sleep | ||
- "3600" | ||
imagePullPolicy: IfNotPresent | ||
name: busybox | ||
volumeMounts: | ||
- mountPath: "/pv" | ||
name: pv | ||
restartPolicy: Always | ||
volumes: | ||
- name: pv | ||
persistentVolumeClaim: | ||
claimName: managed-csi-encrypted-cmk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: managed-csi | ||
namespace: default | ||
spec: | ||
storageClassName: managed-csi | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: bb-managed-csi | ||
namespace: default | ||
spec: | ||
containers: | ||
- image: mcr.microsoft.com/cbl-mariner/busybox:2.0 | ||
command: | ||
- sleep | ||
- "3600" | ||
imagePullPolicy: IfNotPresent | ||
name: busybox | ||
volumeMounts: | ||
- mountPath: "/pv" | ||
name: pv | ||
restartPolicy: Always | ||
volumes: | ||
- name: pv | ||
persistentVolumeClaim: | ||
claimName: managed-csi |