2021-12-21 14:23:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2021-02-22 11:13:40 +00:00
|
|
|
"context"
|
2019-06-18 07:07:11 +00:00
|
|
|
"fmt"
|
2020-06-16 10:56:14 +00:00
|
|
|
"strings"
|
2020-08-03 17:48:24 +00:00
|
|
|
"sync"
|
2019-06-14 09:42:48 +00:00
|
|
|
|
2022-05-24 03:43:35 +00:00
|
|
|
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
|
2022-04-21 05:27:48 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2" // nolint
|
2020-06-16 11:06:15 +00:00
|
|
|
v1 "k8s.io/api/core/v1"
|
2020-06-16 10:56:14 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2019-07-25 06:49:44 +00:00
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
2019-05-31 09:34:04 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2023-02-01 17:06:36 +00:00
|
|
|
e2edebug "k8s.io/kubernetes/test/e2e/framework/debug"
|
2022-09-02 05:03:48 +00:00
|
|
|
"k8s.io/pod-security-admission/api"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-09-20 10:16:55 +00:00
|
|
|
cephFSProvisioner = "csi-cephfsplugin-provisioner.yaml"
|
|
|
|
cephFSProvisionerRBAC = "csi-provisioner-rbac.yaml"
|
|
|
|
cephFSNodePlugin = "csi-cephfsplugin.yaml"
|
|
|
|
cephFSNodePluginRBAC = "csi-nodeplugin-rbac.yaml"
|
|
|
|
cephFSDeploymentName = "csi-cephfsplugin-provisioner"
|
|
|
|
cephFSDeamonSetName = "csi-cephfsplugin"
|
|
|
|
cephFSContainerName = "csi-cephfsplugin"
|
|
|
|
cephFSDirPath = "../deploy/cephfs/kubernetes/"
|
|
|
|
cephFSExamplePath = examplePath + "cephfs/"
|
2020-07-25 16:39:50 +00:00
|
|
|
subvolumegroup = "e2e"
|
2020-08-10 05:32:10 +00:00
|
|
|
fileSystemName = "myfs"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func deployCephfsPlugin() {
|
2019-12-11 08:48:36 +00:00
|
|
|
// delete objects deployed by rook
|
2020-02-26 08:11:05 +00:00
|
|
|
|
2022-02-14 15:56:15 +00:00
|
|
|
err := deleteResource(cephFSDirPath + cephFSProvisionerRBAC)
|
2020-02-26 08:11:05 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete provisioner rbac %s: %v", cephFSDirPath+cephFSProvisionerRBAC, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 15:56:15 +00:00
|
|
|
err = deleteResource(cephFSDirPath + cephFSNodePluginRBAC)
|
2020-02-26 08:11:05 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete nodeplugin rbac %s: %v", cephFSDirPath+cephFSNodePluginRBAC, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 15:48:49 +00:00
|
|
|
createORDeleteCephfsResources(kubectlCreate)
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 14:53:39 +00:00
|
|
|
func deleteCephfsPlugin() {
|
2021-07-26 15:48:49 +00:00
|
|
|
createORDeleteCephfsResources(kubectlDelete)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 15:48:49 +00:00
|
|
|
func createORDeleteCephfsResources(action kubectlAction) {
|
2022-04-15 14:27:28 +00:00
|
|
|
resources := []ResourceDeployer{
|
2022-05-11 10:06:40 +00:00
|
|
|
// shared resources
|
2022-04-15 14:27:28 +00:00
|
|
|
&yamlResource{
|
|
|
|
filename: cephFSDirPath + csiDriverObject,
|
|
|
|
allowMissing: true,
|
|
|
|
},
|
|
|
|
&yamlResource{
|
|
|
|
filename: examplePath + cephConfconfigMap,
|
|
|
|
allowMissing: true,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// dependencies for provisioner
|
2022-04-15 14:27:28 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: cephFSDirPath + cephFSProvisionerRBAC,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// the provisioner itself
|
2022-04-15 14:27:28 +00:00
|
|
|
&yamlResourceNamespaced{
|
2022-05-11 10:06:40 +00:00
|
|
|
filename: cephFSDirPath + cephFSProvisioner,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
oneReplica: true,
|
2022-04-15 14:27:28 +00:00
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// dependencies for the node-plugin
|
2022-04-15 14:27:28 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: cephFSDirPath + cephFSNodePluginRBAC,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// the node-plugin itself
|
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: cephFSDirPath + cephFSNodePlugin,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2022-04-15 14:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, r := range resources {
|
|
|
|
err := r.Do(action)
|
2021-03-30 05:33:01 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to %s resource: %v", action, err)
|
2021-09-02 05:06:21 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateSubvolumeCount(f *framework.Framework, count int, fileSystemName, subvolumegroup string) {
|
|
|
|
subVol, err := listCephFSSubVolumes(f, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list CephFS subvolumes: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
if len(subVol) != count {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("subvolumes [%v]. subvolume count %d not matching expected count %d", subVol, len(subVol), count)
|
2020-01-21 08:22:43 +00:00
|
|
|
}
|
2019-08-07 14:53:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
func validateCephFSSnapshotCount(
|
|
|
|
f *framework.Framework,
|
|
|
|
count int,
|
|
|
|
subvolumegroup string,
|
|
|
|
pv *v1.PersistentVolume,
|
|
|
|
) {
|
|
|
|
subVolumeName := pv.Spec.CSI.VolumeAttributes["subvolumeName"]
|
|
|
|
fsName := pv.Spec.CSI.VolumeAttributes["fsName"]
|
|
|
|
snaps, err := listCephFSSnapshots(f, fsName, subVolumeName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume snapshots: %v", err)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
if len(snaps) != count {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("snapshots [%v]. snapshots count %d not matching expected count %d", snaps, len(snaps), count)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-09 10:32:40 +00:00
|
|
|
func validateSubvolumePath(f *framework.Framework, pvcName, pvcNamespace, fileSystemName, subvolumegroup string) error {
|
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvcName, pvcNamespace)
|
|
|
|
if err != nil {
|
2021-11-22 06:05:49 +00:00
|
|
|
return fmt.Errorf("failed to get PVC %s in namespace %s: %w", pvcName, pvcNamespace, err)
|
2021-02-09 10:32:40 +00:00
|
|
|
}
|
|
|
|
subVolumePathInPV := pv.Spec.CSI.VolumeAttributes["subvolumePath"]
|
|
|
|
subVolume := pv.Spec.CSI.VolumeAttributes["subvolumeName"]
|
|
|
|
if subVolumePathInPV == "" {
|
|
|
|
return fmt.Errorf("subvolumePath is not set in %s PVC", pvcName)
|
|
|
|
}
|
|
|
|
if subVolume == "" {
|
|
|
|
return fmt.Errorf("subvolumeName is not set in %s PVC", pvcName)
|
|
|
|
}
|
|
|
|
subVolumePath, err := getSubvolumePath(f, fileSystemName, subvolumegroup, subVolume)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if subVolumePath != subVolumePathInPV {
|
2021-06-25 12:31:28 +00:00
|
|
|
return fmt.Errorf(
|
|
|
|
"subvolumePath %s is not matching the subvolumePath %s in PV",
|
|
|
|
subVolumePath,
|
|
|
|
subVolumePathInPV)
|
2021-02-09 10:32:40 +00:00
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-09 10:32:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-25 11:51:05 +00:00
|
|
|
var _ = Describe(cephfsType, func() {
|
|
|
|
f := framework.NewDefaultFramework(cephfsType)
|
2022-09-02 05:03:48 +00:00
|
|
|
f.NamespacePodSecurityEnforceLevel = api.LevelPrivileged
|
2019-12-18 08:41:20 +00:00
|
|
|
var c clientset.Interface
|
2020-09-03 09:34:29 +00:00
|
|
|
// deploy CephFS CSI
|
2019-05-31 09:34:04 +00:00
|
|
|
BeforeEach(func() {
|
2020-07-25 16:39:50 +00:00
|
|
|
if !testCephFS || upgradeTesting {
|
2020-07-08 11:46:31 +00:00
|
|
|
Skip("Skipping CephFS E2E")
|
|
|
|
}
|
2019-12-18 08:41:20 +00:00
|
|
|
c = f.ClientSet
|
2020-02-25 08:00:23 +00:00
|
|
|
if deployCephFS {
|
2020-02-25 11:45:54 +00:00
|
|
|
if cephCSINamespace != defaultNs {
|
2020-02-26 08:11:05 +00:00
|
|
|
err := createNamespace(c, cephCSINamespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create namespace %s: %v", cephCSINamespace, err)
|
2020-02-25 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-25 08:00:23 +00:00
|
|
|
deployCephfsPlugin()
|
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err := createConfigMap(cephFSDirPath, f.ClientSet, f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-02-22 11:13:40 +00:00
|
|
|
// create cephFS provisioner secret
|
|
|
|
key, err := createCephUser(f, keyringCephFSProvisionerUsername, cephFSProvisionerCaps())
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create user %s: %v", keyringCephFSProvisionerUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
err = createCephfsSecret(f, cephFSProvisionerSecretName, keyringCephFSProvisionerUsername, key)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create provisioner secret: %v", err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
// create cephFS plugin secret
|
|
|
|
key, err = createCephUser(f, keyringCephFSNodePluginUsername, cephFSNodePluginCaps())
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create user %s: %v", keyringCephFSNodePluginUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
err = createCephfsSecret(f, cephFSNodePluginSecretName, keyringCephFSNodePluginUsername, key)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create node secret: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2022-08-19 16:24:40 +00:00
|
|
|
deployVault(f.ClientSet, deployTimeout)
|
2022-06-14 13:50:42 +00:00
|
|
|
|
|
|
|
// wait for cluster name update in deployment
|
|
|
|
containers := []string{cephFSContainerName}
|
|
|
|
err = waitForContainersArgsUpdate(c, cephCSINamespace, cephFSDeploymentName,
|
|
|
|
"clustername", defaultClusterName, containers, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("timeout waiting for deployment update %s/%s: %v", cephCSINamespace, cephFSDeploymentName, err)
|
2022-06-14 13:50:42 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
2020-07-25 16:39:50 +00:00
|
|
|
if !testCephFS || upgradeTesting {
|
2020-07-08 11:46:31 +00:00
|
|
|
Skip("Skipping CephFS E2E")
|
|
|
|
}
|
2022-11-09 05:02:09 +00:00
|
|
|
if CurrentSpecReport().Failed() {
|
2020-04-01 07:20:43 +00:00
|
|
|
// log pods created by helm chart
|
|
|
|
logsCSIPods("app=ceph-csi-cephfs", c)
|
2021-06-10 11:39:03 +00:00
|
|
|
// log provisioner
|
2019-12-18 08:41:20 +00:00
|
|
|
logsCSIPods("app=csi-cephfsplugin-provisioner", c)
|
|
|
|
// log node plugin
|
|
|
|
logsCSIPods("app=csi-cephfsplugin", c)
|
2020-12-03 11:00:22 +00:00
|
|
|
|
|
|
|
// log all details from the namespace where Ceph-CSI is deployed
|
2023-02-01 17:06:36 +00:00
|
|
|
e2edebug.DumpAllNamespaceInfo(c, cephCSINamespace)
|
2019-12-18 08:41:20 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err := deleteConfigMap(cephFSDirPath)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-06-25 12:31:28 +00:00
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSProvisionerSecretName, metav1.DeleteOptions{})
|
2021-02-22 11:13:40 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete provisioner secret: %v", err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
2021-06-25 12:31:28 +00:00
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSNodePluginSecretName, metav1.DeleteOptions{})
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete node secret: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2022-08-19 16:24:40 +00:00
|
|
|
deleteVault()
|
|
|
|
|
2020-02-25 11:45:54 +00:00
|
|
|
if deployCephFS {
|
|
|
|
deleteCephfsPlugin()
|
|
|
|
if cephCSINamespace != defaultNs {
|
2020-02-26 08:11:05 +00:00
|
|
|
err := deleteNamespace(c, cephCSINamespace)
|
2020-02-25 11:45:54 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete namespace %s: %v", cephCSINamespace, err)
|
2020-02-25 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
Context("Test CephFS CSI", func() {
|
2022-04-19 09:25:54 +00:00
|
|
|
if !testCephFS || upgradeTesting {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
It("Test CephFS CSI", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
pvcPath := cephFSExamplePath + "pvc.yaml"
|
|
|
|
appPath := cephFSExamplePath + "pod.yaml"
|
2022-02-15 14:27:40 +00:00
|
|
|
deplPath := cephFSExamplePath + "deployment.yaml"
|
2022-01-06 15:20:01 +00:00
|
|
|
appRWOPPath := cephFSExamplePath + "pod-rwop.yaml"
|
2021-09-20 10:16:55 +00:00
|
|
|
pvcClonePath := cephFSExamplePath + "pvc-restore.yaml"
|
|
|
|
pvcSmartClonePath := cephFSExamplePath + "pvc-clone.yaml"
|
|
|
|
appClonePath := cephFSExamplePath + "pod-restore.yaml"
|
|
|
|
appSmartClonePath := cephFSExamplePath + "pod-clone.yaml"
|
|
|
|
snapshotPath := cephFSExamplePath + "snapshot.yaml"
|
2021-10-29 09:08:33 +00:00
|
|
|
appEphemeralPath := cephFSExamplePath + "pod-ephemeral.yaml"
|
2022-01-06 15:20:01 +00:00
|
|
|
pvcRWOPPath := cephFSExamplePath + "pvc-rwop.yaml"
|
2022-04-25 11:51:05 +00:00
|
|
|
|
|
|
|
metadataPool, getErr := getCephFSMetadataPoolName(f, fileSystemName)
|
|
|
|
if getErr != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed getting cephFS metadata pool name: %v", getErr)
|
2022-04-25 11:51:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("checking provisioner deployment is running", func() {
|
2021-10-29 08:36:30 +00:00
|
|
|
err := waitForDeploymentComplete(f.ClientSet, cephFSDeploymentName, cephCSINamespace, deployTimeout)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-05-31 09:34:04 +00:00
|
|
|
|
2022-04-14 11:59:47 +00:00
|
|
|
By("checking nodeplugin daemonset pods are running", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
err := waitForDaemonSets(cephFSDeamonSetName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("timeout waiting for daemonset %s: %v", cephFSDeamonSetName, err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-05-31 09:34:04 +00:00
|
|
|
|
2021-04-22 06:57:55 +00:00
|
|
|
// test only if ceph-csi is deployed via helm
|
|
|
|
if helmTest {
|
|
|
|
By("verify PVC and app binding on helm installation", func() {
|
|
|
|
err := validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2021-04-22 06:57:55 +00:00
|
|
|
}
|
|
|
|
// Deleting the storageclass and secret created by helm
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2021-04-22 06:57:55 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2021-04-22 06:57:55 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "secret.yaml")
|
2021-04-22 06:57:55 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2021-04-22 06:57:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-10-29 09:08:33 +00:00
|
|
|
By("verify generic ephemeral volume support", func() {
|
2022-05-26 05:56:35 +00:00
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-05-26 05:56:35 +00:00
|
|
|
}
|
|
|
|
// create application
|
|
|
|
app, err := loadApp(appEphemeralPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-05-26 05:56:35 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create application: %v", err)
|
2022-05-26 05:56:35 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 1, cephfsType, metadataPool, volumesType)
|
|
|
|
// delete pod
|
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete application: %v", err)
|
2022-05-26 05:56:35 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2021-10-29 09:08:33 +00:00
|
|
|
}
|
|
|
|
})
|
2021-04-22 06:57:55 +00:00
|
|
|
|
2022-01-06 15:20:01 +00:00
|
|
|
By("verify RWOP volume support", func() {
|
2022-07-25 04:40:20 +00:00
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcRWOPPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
2022-01-06 15:20:01 +00:00
|
|
|
|
2022-07-25 04:40:20 +00:00
|
|
|
// create application
|
|
|
|
app, err := loadApp(appRWOPPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
baseAppName := app.Name
|
2022-01-06 15:20:01 +00:00
|
|
|
|
2022-07-25 04:40:20 +00:00
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
if rwopMayFail(err) {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("RWOP is not supported: %v", err)
|
2022-04-11 15:54:53 +00:00
|
|
|
|
2022-07-25 04:40:20 +00:00
|
|
|
return
|
2022-01-06 15:20:01 +00:00
|
|
|
}
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create application: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 1, cephfsType, metadataPool, volumesType)
|
2022-01-06 15:20:01 +00:00
|
|
|
|
2022-07-25 04:40:20 +00:00
|
|
|
err = validateRWOPPodCreation(f, pvc, app, baseAppName)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate RWOP pod creation: %v", err)
|
2022-07-25 04:40:20 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-01-06 15:20:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-14 01:48:09 +00:00
|
|
|
By("check static PVC", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
scPath := cephFSExamplePath + "secret.yaml"
|
2020-05-14 01:48:09 +00:00
|
|
|
err := validateCephFsStaticPV(f, appPath, scPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS static pv: %v", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create a storageclass with pool and a PVC then bind it to an app", func() {
|
2020-09-21 14:56:15 +00:00
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2019-08-05 15:40:48 +00:00
|
|
|
})
|
|
|
|
|
2022-08-19 16:30:16 +00:00
|
|
|
if testCephFSFscrypt {
|
|
|
|
kmsToTest := map[string]kmsConfig{
|
|
|
|
"secrets-metadata-test": secretsMetadataKMS,
|
|
|
|
"vault-test": vaultKMS,
|
|
|
|
"vault-tokens-test": vaultTokensKMS,
|
|
|
|
"vault-tenant-sa-test": vaultTenantSAKMS,
|
|
|
|
}
|
|
|
|
|
|
|
|
for kmsID, kmsConf := range kmsToTest {
|
|
|
|
kmsID := kmsID
|
|
|
|
kmsConf := kmsConf
|
|
|
|
By("create a storageclass with pool and an encrypted PVC then bind it to an app with "+kmsID, func() {
|
|
|
|
scOpts := map[string]string{
|
|
|
|
"encrypted": "true",
|
|
|
|
"encryptionKMSID": kmsID,
|
|
|
|
}
|
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, scOpts)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if kmsID == "vault-tokens-test" {
|
|
|
|
var token v1.Secret
|
|
|
|
tenant := f.UniqueName
|
|
|
|
token, err = getSecret(vaultExamplePath + "tenant-token.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load tenant token from secret: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
_, err = c.CoreV1().Secrets(tenant).Create(context.TODO(), &token, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create Secret with tenant token: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = c.CoreV1().Secrets(tenant).Delete(context.TODO(), token.Name, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete Secret with tenant token: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
if kmsID == "vault-tenant-sa-test" {
|
|
|
|
err = createTenantServiceAccount(f.ClientSet, f.UniqueName)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create ServiceAccount: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
defer deleteTenantServiceAccount(f.UniqueName)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = validateFscryptAndAppBinding(pvcPath, appPath, kmsConf, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-08-19 16:30:16 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 14:08:12 +00:00
|
|
|
By("create a PVC and check PVC/PV metadata on CephFS subvolume", func() {
|
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 1, cephfsType, metadataPool, volumesType)
|
|
|
|
|
|
|
|
pvcObj, err := getPersistentVolumeClaim(c, pvc.Namespace, pvc.Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("error getting pvc %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
if pvcObj.Spec.VolumeName == "" {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
subvol, err := listCephFSSubVolumes(f, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list CephFS subvolumes: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
if len(subvol) == 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("cephFS subvolumes list is empty %s", fileSystemName)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
metadata, err := listCephFSSubvolumeMetadata(f, fileSystemName, subvol[0].Name, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume metadata: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if metadata.PVCNameKey != pvc.Name {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcName %q got %q", pvc.Name, metadata.PVCNameKey)
|
2022-05-24 14:08:12 +00:00
|
|
|
} else if metadata.PVCNamespaceKey != pvc.Namespace {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcNamespace %q got %q", pvc.Namespace, metadata.PVCNamespaceKey)
|
2022-05-24 14:08:12 +00:00
|
|
|
} else if metadata.PVNameKey != pvcObj.Spec.VolumeName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvName %q got %q", pvcObj.Spec.VolumeName, metadata.PVNameKey)
|
2022-06-14 13:50:42 +00:00
|
|
|
} else if metadata.ClusterNameKey != defaultClusterName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected clusterName %q got %q", defaultClusterName, metadata.ClusterNameKey)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-05-24 14:08:12 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-02-19 06:01:27 +00:00
|
|
|
By("create PVC in storageClass with volumeNamePrefix", func() {
|
|
|
|
volumeNamePrefix := "foo-bar-"
|
2021-06-25 12:31:28 +00:00
|
|
|
err := createCephfsStorageClass(
|
|
|
|
f.ClientSet,
|
|
|
|
f,
|
|
|
|
false,
|
|
|
|
map[string]string{"volumeNamePrefix": volumeNamePrefix})
|
2021-02-19 06:01:27 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create storageclass: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
// set up PVC
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 1, cephfsType, metadataPool, volumesType)
|
2021-02-19 06:01:27 +00:00
|
|
|
// list subvolumes and check if one of them has the same prefix
|
|
|
|
foundIt := false
|
|
|
|
subvolumes, err := listCephFSSubVolumes(f, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolumes: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
for _, subVol := range subvolumes {
|
|
|
|
fmt.Printf("Checking prefix on %s\n", subVol)
|
|
|
|
if strings.HasPrefix(subVol.Name, volumeNamePrefix) {
|
|
|
|
foundIt = true
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2021-02-19 06:01:27 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// clean up after ourselves
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2021-02-19 06:01:27 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
if !foundIt {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("could not find subvolume with prefix %s", volumeNamePrefix)
|
2021-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-21 15:03:21 +00:00
|
|
|
By("create a storageclass with ceph-fuse and a PVC then bind it to an app", func() {
|
|
|
|
params := map[string]string{
|
|
|
|
"mounter": "fuse",
|
|
|
|
}
|
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, params)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-21 15:03:21 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("create a storageclass with ceph-fuse, mount-options and a PVC then bind it to an app", func() {
|
|
|
|
params := map[string]string{
|
|
|
|
"mounter": "fuse",
|
|
|
|
"fuseMountOptions": "debug",
|
|
|
|
}
|
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, true, params)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-21 15:03:21 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2020-09-21 15:03:21 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-02-15 14:27:40 +00:00
|
|
|
By("verifying that ceph-fuse recovery works for new pods", func() {
|
|
|
|
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, true, map[string]string{
|
|
|
|
"mounter": "fuse",
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
replicas := int32(2)
|
|
|
|
pvc, depl, err := validatePVCAndDeploymentAppBinding(
|
|
|
|
f, pvcPath, deplPath, f.UniqueName, &replicas, deployTimeout,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC and Deployment: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
deplPods, err := listPods(f, depl.Namespace, &metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("app=%s", depl.Labels["app"]),
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list pods for Deployment: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 10:17:19 +00:00
|
|
|
doStat := func(podName string) (string, error) {
|
|
|
|
_, stdErr, execErr := execCommandInContainerByPodName(
|
2022-02-15 14:27:40 +00:00
|
|
|
f,
|
|
|
|
fmt.Sprintf("stat %s", depl.Spec.Template.Spec.Containers[0].VolumeMounts[0].MountPath),
|
|
|
|
depl.Namespace,
|
|
|
|
podName,
|
|
|
|
depl.Spec.Template.Spec.Containers[0].Name,
|
|
|
|
)
|
|
|
|
|
2022-06-01 10:17:19 +00:00
|
|
|
return stdErr, execErr
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
ensureStatSucceeds := func(podName string) error {
|
|
|
|
stdErr, statErr := doStat(podName)
|
|
|
|
if statErr != nil || stdErr != "" {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"expected stat to succeed without error output ; got err %w, stderr %s",
|
|
|
|
statErr, stdErr,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pod1Name, pod2Name := deplPods[0].Name, deplPods[1].Name
|
|
|
|
|
|
|
|
// stat() ceph-fuse mountpoints to make sure they are working.
|
|
|
|
for i := range deplPods {
|
|
|
|
err = ensureStatSucceeds(deplPods[i].Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(err.Error())
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Kill ceph-fuse in cephfs-csi node plugin Pods.
|
|
|
|
nodePluginSelector, err := getDaemonSetLabelSelector(f, cephCSINamespace, cephFSDeamonSetName)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get node plugin DaemonSet label selector: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
_, stdErr, err := execCommandInContainer(
|
|
|
|
f, "killall -9 ceph-fuse", cephCSINamespace, "csi-cephfsplugin", &metav1.ListOptions{
|
|
|
|
LabelSelector: nodePluginSelector,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("killall command failed: err %v, stderr %s", err, stdErr)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
2022-04-11 08:20:27 +00:00
|
|
|
// Verify Pod pod2Name that stat()-ing the mountpoint results in ENOTCONN.
|
2022-02-15 14:27:40 +00:00
|
|
|
stdErr, err = doStat(pod2Name)
|
|
|
|
if err == nil || !strings.Contains(stdErr, "not connected") {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(
|
2022-02-15 14:27:40 +00:00
|
|
|
"expected stat to fail with 'Transport endpoint not connected' or 'Socket not connected'; got err %v, stderr %s",
|
|
|
|
err, stdErr,
|
|
|
|
)
|
|
|
|
}
|
2022-04-11 08:20:27 +00:00
|
|
|
// Delete pod2Name Pod. This serves two purposes: it verifies that deleting pods with
|
2022-02-15 14:27:40 +00:00
|
|
|
// corrupted ceph-fuse mountpoints works, and it lets the replicaset controller recreate
|
|
|
|
// the pod with hopefully mounts working again.
|
|
|
|
err = deletePod(pod2Name, depl.Namespace, c, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(err.Error())
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
// Wait for the second Pod to be recreated.
|
|
|
|
err = waitForDeploymentComplete(c, depl.Name, depl.Namespace, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(err.Error())
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
// List Deployment's pods again to get name of the new pod.
|
|
|
|
deplPods, err = listPods(f, depl.Namespace, &metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("app=%s", depl.Labels["app"]),
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list pods for Deployment: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
for i := range deplPods {
|
|
|
|
if deplPods[i].Name != pod1Name {
|
|
|
|
pod2Name = deplPods[i].Name
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if pod2Name == "" {
|
|
|
|
podNames := make([]string, len(deplPods))
|
|
|
|
for i := range deplPods {
|
|
|
|
podNames[i] = deplPods[i].Name
|
|
|
|
}
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("no new replica found ; found replicas %v", podNames)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
2022-04-11 08:20:27 +00:00
|
|
|
// Verify Pod pod2Name has its ceph-fuse mount working again.
|
2022-02-15 14:27:40 +00:00
|
|
|
err = ensureStatSucceeds(pod2Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(err.Error())
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete created resources.
|
|
|
|
err = deletePVCAndDeploymentApp(f, pvc, depl)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC and Deployment: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-02-15 14:27:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create a PVC and bind it to an app", func() {
|
2020-09-21 14:56:15 +00:00
|
|
|
err := createCephfsStorageClass(f.ClientSet, f, false, nil)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate CephFS pvc and application binding: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-05-31 09:34:04 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create a PVC and bind it to an app with normal user", func() {
|
|
|
|
err := validateNormalUserPVCAccess(pvcPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate normal user CephFS pvc and application binding: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-05-31 09:34:04 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create/delete multiple PVCs and Apps", func() {
|
|
|
|
totalCount := 2
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
2019-06-18 07:07:11 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
// create PVC and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err = createPVCAndApp(name, f, pvc, app, deployTimeout)
|
2019-06-18 07:07:11 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC or application: %v", err)
|
2019-06-18 07:07:11 +00:00
|
|
|
}
|
2021-02-09 10:32:40 +00:00
|
|
|
err = validateSubvolumePath(f, pvc.Name, pvc.Namespace, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate subvolumePath: %v", err)
|
2021-02-09 10:32:40 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, totalCount, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, volumesType)
|
2020-09-03 09:34:29 +00:00
|
|
|
// delete PVC and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err = deletePVCAndApp(name, f, pvc, app)
|
2019-06-18 07:07:11 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2019-06-18 07:07:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2020-09-03 09:34:29 +00:00
|
|
|
})
|
2019-06-18 07:07:11 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("check data persist after recreating pod", func() {
|
|
|
|
err := checkDataPersist(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to check data persist in pvc: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-06-18 07:07:11 +00:00
|
|
|
|
2021-03-22 06:17:42 +00:00
|
|
|
By("Create PVC, bind it to an app, unmount volume and check app deletion", func() {
|
|
|
|
pvc, app, err := createPVCAndAppBinding(pvcPath, appPath, f, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC or application: %v", err)
|
2021-03-22 06:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = unmountCephFSVolume(f, app.Name, pvc.Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to unmount volume: %v", err)
|
2021-03-22 06:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2021-03-22 06:17:42 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create PVC, delete backing subvolume and check pv deletion", func() {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
2020-10-20 09:55:09 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
2020-01-23 01:47:02 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-01-23 01:47:02 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deleteBackingCephFSVolume(f, pvc)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS subvolume: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-01-23 01:47:02 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2020-01-23 01:47:02 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("validate multiple subvolumegroup creation", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-10-01 04:06:06 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
// re-define configmap with information of multiple clusters.
|
2021-10-01 04:06:06 +00:00
|
|
|
clusterInfo := map[string]map[string]string{}
|
|
|
|
clusterID1 := "clusterID-1"
|
|
|
|
clusterID2 := "clusterID-2"
|
|
|
|
clusterInfo[clusterID1] = map[string]string{}
|
|
|
|
clusterInfo[clusterID1]["subvolumeGroup"] = "subvolgrp1"
|
|
|
|
clusterInfo[clusterID2] = map[string]string{}
|
|
|
|
clusterInfo[clusterID2]["subvolumeGroup"] = "subvolgrp2"
|
|
|
|
|
|
|
|
err = createCustomConfigMap(f.ClientSet, cephFSDirPath, clusterInfo)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-09-21 14:56:15 +00:00
|
|
|
params := map[string]string{
|
|
|
|
"clusterID": "clusterID-1",
|
|
|
|
}
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, params)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate pvc and application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-06-10 11:39:03 +00:00
|
|
|
// verify subvolume group creation.
|
2020-09-03 09:34:29 +00:00
|
|
|
err = validateSubvolumegroup(f, "subvolgrp1")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate subvolume group: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-06-25 13:48:48 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
// create resources and verify subvolume group creation
|
|
|
|
// for the second cluster.
|
2020-09-21 14:56:15 +00:00
|
|
|
params["clusterID"] = "clusterID-2"
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, params)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate pvc and application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
err = validateSubvolumegroup(f, "subvolgrp2")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate subvolume group: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteConfigMap(cephFSDirPath)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = createConfigMap(cephFSDirPath, f.ClientSet, f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-09-21 14:56:15 +00:00
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, nil)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2020-06-25 13:48:48 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("Resize PVC and check application directory size", func() {
|
2021-11-03 12:08:32 +00:00
|
|
|
err := resizePVCAndValidateSize(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to resize PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-25 11:09:24 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("Mount pvc as readonly in pod", func() {
|
|
|
|
// create PVC and bind it to an app
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
label := map[string]string{
|
|
|
|
"app": app.Name,
|
|
|
|
}
|
|
|
|
app.Labels = label
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ReadOnly = true
|
|
|
|
err = createPVCAndApp("", f, pvc, app, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC or application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("app=%s", app.Name),
|
|
|
|
}
|
2019-11-25 11:09:24 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
2021-06-25 12:31:28 +00:00
|
|
|
_, stdErr := execCommandInPodAndAllowFail(
|
|
|
|
f,
|
|
|
|
fmt.Sprintf("echo 'Hello World' > %s", filePath),
|
|
|
|
app.Namespace,
|
|
|
|
&opt)
|
2020-09-03 09:34:29 +00:00
|
|
|
readOnlyErr := fmt.Sprintf("cannot create %s: Read-only file system", filePath)
|
|
|
|
if !strings.Contains(stdErr, readOnlyErr) {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(stdErr)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2019-07-03 10:02:36 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
// delete PVC and app
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-06-09 09:39:21 +00:00
|
|
|
By("Test subvolume snapshot and restored PVC metadata", func() {
|
2022-06-08 09:17:09 +00:00
|
|
|
err := createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS snapshotclass: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
|
|
|
snap.Name = f.UniqueName
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create snapshot (%s): %v", snap.Name, err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
subVolumeName := pv.Spec.CSI.VolumeAttributes["subvolumeName"]
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 1, subvolumegroup, pv)
|
2022-06-08 09:17:09 +00:00
|
|
|
snaps, err := listCephFSSnapshots(f, fileSystemName, subVolumeName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume snapshots: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
content, err := getVolumeSnapshotContent(snap.Namespace, snap.Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get snapshotcontent for %s in namespace %s: %v",
|
2022-06-08 09:17:09 +00:00
|
|
|
snap.Name, snap.Namespace, err)
|
|
|
|
}
|
|
|
|
metadata, err := listCephFSSnapshotMetadata(f,
|
|
|
|
fileSystemName, subVolumeName, snaps[0].Name, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume snapshots metadata: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
if metadata.VolSnapNameKey != snap.Name {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed, snapname expected:%s got:%s",
|
2022-06-08 09:17:09 +00:00
|
|
|
snap.Name, metadata.VolSnapNameKey)
|
|
|
|
} else if metadata.VolSnapNamespaceKey != snap.Namespace {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed, snapnamespace expected:%s got:%s",
|
2022-06-08 09:17:09 +00:00
|
|
|
snap.Namespace, metadata.VolSnapNamespaceKey)
|
|
|
|
} else if metadata.VolSnapContentNameKey != content.Name {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed, contentname expected:%s got:%s",
|
2022-06-08 09:17:09 +00:00
|
|
|
content.Name, metadata.VolSnapContentNameKey)
|
2022-07-28 10:48:00 +00:00
|
|
|
} else if metadata.ClusterNameKey != defaultClusterName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected clusterName %q got %q", defaultClusterName, metadata.ClusterNameKey)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
2022-07-28 10:48:00 +00:00
|
|
|
|
2022-06-09 09:39:21 +00:00
|
|
|
// Delete the parent pvc before restoring
|
|
|
|
// another one from snapshot.
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
2022-06-08 09:17:09 +00:00
|
|
|
|
2022-06-09 09:39:21 +00:00
|
|
|
// Test Restore snapshot
|
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = snap.Name
|
|
|
|
// create PVC from the snapshot
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvcClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create pvc clone: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
pvcCloneObj, pvCloneObj, err := getPVCAndPV(f.ClientSet, pvcClone.Name, pvcClone.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("error getting pvc %q in namespace %q: %v", pvcClone.Name, pvcClone.Namespace, err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
subVolumeCloneName := pvCloneObj.Spec.CSI.VolumeAttributes["subvolumeName"]
|
|
|
|
cloneMetadata, err := listCephFSSubvolumeMetadata(f, fileSystemName, subVolumeCloneName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume clone metadata: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
if cloneMetadata.PVCNameKey != pvcClone.Name {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcName %q got %q", pvcClone.Name, cloneMetadata.PVCNameKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
} else if cloneMetadata.PVCNamespaceKey != pvcClone.Namespace {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcNamespace %q got %q", pvcClone.Namespace, cloneMetadata.PVCNamespaceKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
} else if cloneMetadata.PVNameKey != pvcCloneObj.Spec.VolumeName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvName %q got %q", pvcCloneObj.Spec.VolumeName, cloneMetadata.PVNameKey)
|
2022-07-28 10:48:00 +00:00
|
|
|
} else if cloneMetadata.ClusterNameKey != defaultClusterName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected clusterName %q got %q", defaultClusterName, cloneMetadata.ClusterNameKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete clone
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvcClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete pvc clone: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
2022-06-08 09:17:09 +00:00
|
|
|
// delete snapshot
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete snapshot (%s): %v", f.UniqueName, err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2022-11-02 10:50:16 +00:00
|
|
|
|
2022-06-08 09:17:09 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS snapshotclass: %v", err)
|
2022-06-08 09:17:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-06-09 09:39:21 +00:00
|
|
|
By("Test Clone metadata", func() {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create pvc: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvcClone, err := loadPVC(pvcSmartClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = pvc.Name
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvcClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create pvc clone: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
// delete parent PVC
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete pvc: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvcCloneObj, pvCloneObj, err := getPVCAndPV(f.ClientSet, pvcClone.Name, pvcClone.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("error getting pvc %q in namespace %q: %v", pvcClone.Name, pvcClone.Namespace, err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
subVolumeCloneName := pvCloneObj.Spec.CSI.VolumeAttributes["subvolumeName"]
|
|
|
|
cloneMetadata, err := listCephFSSubvolumeMetadata(f, fileSystemName, subVolumeCloneName, subvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to list subvolume clone metadata: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
if cloneMetadata.PVCNameKey != pvcClone.Name {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcName %q got %q", pvc.Name, cloneMetadata.PVCNameKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
} else if cloneMetadata.PVCNamespaceKey != pvcClone.Namespace {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvcNamespace %q got %q", pvc.Namespace, cloneMetadata.PVCNamespaceKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
} else if cloneMetadata.PVNameKey != pvcCloneObj.Spec.VolumeName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected pvName %q got %q", pvcCloneObj.Spec.VolumeName, cloneMetadata.PVNameKey)
|
2022-07-28 10:48:00 +00:00
|
|
|
} else if cloneMetadata.ClusterNameKey != defaultClusterName {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("expected clusterName %q got %q", defaultClusterName, cloneMetadata.ClusterNameKey)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvcClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete pvc clone: %v", err)
|
2022-06-09 09:39:21 +00:00
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
})
|
|
|
|
|
2021-02-10 08:19:40 +00:00
|
|
|
By("Delete snapshot after deleting subvolume and snapshot from backend", func() {
|
2021-11-03 12:07:36 +00:00
|
|
|
err := createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS snapshotclass: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
|
|
|
snap.Name = f.UniqueName
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create snapshot (%s): %v", snap.Name, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 1, subvolumegroup, pv)
|
2021-11-03 12:07:36 +00:00
|
|
|
err = deleteBackingCephFSSubvolumeSnapshot(f, pvc, &snap)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete backing snapshot for snapname:=%s", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
err = deleteBackingCephFSVolume(f, pvc)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete backing subvolume error=%s", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete snapshot:=%s", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
} else {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("successfully deleted snapshot")
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-10 08:19:40 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS snapshotclass: %v", err)
|
2021-02-10 08:19:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-02-18 08:32:38 +00:00
|
|
|
By("Test snapshot retention feature", func() {
|
|
|
|
// Delete the PVC after creating a snapshot,
|
|
|
|
// this should work because of the snapshot
|
|
|
|
// retention feature. Restore a PVC from that
|
|
|
|
// snapshot.
|
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
err := createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS snapshotclass: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
|
|
|
snap.Name = f.UniqueName
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create snapshot (%s): %v", snap.Name, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 1, subvolumegroup, pv)
|
2021-11-03 12:07:36 +00:00
|
|
|
// Delete the parent pvc before restoring
|
|
|
|
// another one from snapshot.
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = snap.Name
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
// create PVC from the snapshot
|
|
|
|
name := f.UniqueName
|
|
|
|
err = createPVCAndApp(name, f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to create PVC and app (%s): %v", f.UniqueName, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
// delete clone and app
|
|
|
|
err = deletePVCAndApp(name, f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC and app (%s): %v", f.UniqueName, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2021-02-18 08:32:38 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
// delete snapshot
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete snapshot (%s): %v", f.UniqueName, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS snapshotclass: %v", err)
|
2021-02-18 08:32:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create a PVC clone and bind it to an app", func() {
|
2021-11-03 12:07:36 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
totalCount := 3
|
|
|
|
wgErrs := make([]error, totalCount)
|
|
|
|
// totalSubvolumes represents the subvolumes in backend
|
|
|
|
// always totalCount+parentPVC
|
|
|
|
totalSubvolumes := totalCount + 1
|
|
|
|
wg.Add(totalCount)
|
|
|
|
err := createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-06-16 10:56:14 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-06-16 10:56:14 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
label := make(map[string]string)
|
|
|
|
label[appKey] = appLabel
|
|
|
|
app.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
wErr := writeDataInPod(app, &opt, f)
|
|
|
|
if wErr != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to write data : %v", wErr)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, s snapapi.VolumeSnapshot) {
|
|
|
|
s.Name = fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = createSnapshot(&s, deployTimeout)
|
|
|
|
wg.Done()
|
|
|
|
}(i, snap)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
failed := 0
|
|
|
|
for i, err := range wgErrs {
|
2020-06-16 10:56:14 +00:00
|
|
|
if err != nil {
|
2021-11-03 12:07:36 +00:00
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to create snapshot (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-06-16 10:56:14 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating snapshots failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, totalCount, subvolumegroup, pv)
|
2020-06-16 10:56:14 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = fmt.Sprintf("%s%d", f.UniqueName, 0)
|
2020-06-16 10:56:14 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
// create multiple PVC from same snapshot
|
|
|
|
wg.Add(totalCount)
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout)
|
|
|
|
if wgErrs[n] == nil {
|
|
|
|
err = validateSubvolumePath(f, p.Name, p.Namespace, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
|
|
|
wgErrs[n] = err
|
|
|
|
}
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
for i, err := range wgErrs {
|
2020-06-16 10:56:14 +00:00
|
|
|
if err != nil {
|
2021-11-03 12:07:36 +00:00
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to create PVC and app (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-06-16 10:56:14 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-08-03 17:48:24 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
p.Spec.DataSource.Name = name
|
|
|
|
wgErrs[n] = deletePVCAndApp(name, f, &p, &a)
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-09-03 09:34:29 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to delete PVC and app (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
parentPVCCount := totalSubvolumes - totalCount
|
|
|
|
validateSubvolumeCount(f, parentPVCCount, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, parentPVCCount, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
2021-11-03 12:07:36 +00:00
|
|
|
// create clones from different snapshots and bind it to an
|
|
|
|
// app
|
|
|
|
wg.Add(totalCount)
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
p.Spec.DataSource.Name = name
|
|
|
|
wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout)
|
|
|
|
if wgErrs[n] == nil {
|
|
|
|
err = validateSubvolumePath(f, p.Name, p.Namespace, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
|
|
|
wgErrs[n] = err
|
2021-02-09 10:32:40 +00:00
|
|
|
}
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-09-03 09:34:29 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to create PVC and app (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete snapshot
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, s snapapi.VolumeSnapshot) {
|
|
|
|
s.Name = fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = deleteSnapshot(&s, deployTimeout)
|
|
|
|
wg.Done()
|
|
|
|
}(i, snap)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-09-03 09:34:29 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to delete snapshot (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting snapshots failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 0, subvolumegroup, pv)
|
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
p.Spec.DataSource.Name = name
|
|
|
|
wgErrs[n] = deletePVCAndApp(name, f, &p, &a)
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
for i, err := range wgErrs {
|
2020-08-03 17:48:24 +00:00
|
|
|
if err != nil {
|
2021-11-03 12:07:36 +00:00
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to delete PVC and app (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:36 +00:00
|
|
|
failed++
|
2020-08-03 17:48:24 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:36 +00:00
|
|
|
}
|
2020-08-03 17:48:24 +00:00
|
|
|
|
2021-11-03 12:07:36 +00:00
|
|
|
validateSubvolumeCount(f, parentPVCCount, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, parentPVCCount, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, snapsType)
|
2021-11-03 12:07:36 +00:00
|
|
|
// delete parent pvc
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-11-03 12:07:36 +00:00
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, snapsType)
|
2022-04-06 12:05:18 +00:00
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS snapshotclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-09-07 16:30:55 +00:00
|
|
|
if testCephFSFscrypt {
|
|
|
|
for _, kmsID := range []string{"secrets-metadata-test", "vault-test"} {
|
|
|
|
kmsID := kmsID
|
|
|
|
By("checking encrypted snapshot-backed volume with KMS "+kmsID, func() {
|
|
|
|
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scOpts := map[string]string{
|
|
|
|
"encrypted": "true",
|
|
|
|
"encryptionKMSID": kmsID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, true, scOpts)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
appLabels := map[string]string{
|
|
|
|
appKey: appLabel,
|
|
|
|
}
|
|
|
|
app.Labels = appLabels
|
|
|
|
optApp := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appLabels[appKey]),
|
|
|
|
}
|
|
|
|
err = writeDataInPod(app, &optApp, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to write data: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
appTestFilePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create snapshot: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = appendToFileInContainer(f, app, appTestFilePath, "hello", &optApp)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to append data: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parentFileSum, err := calculateSHA512sum(f, app, appTestFilePath, &optApp)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
2023-02-07 09:06:36 +00:00
|
|
|
|
2022-09-07 16:30:55 +00:00
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, map[string]string{
|
|
|
|
"encrypted": "true",
|
|
|
|
"encryptionKMSID": kmsID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
// Snapshot-backed volumes support read-only access modes only.
|
|
|
|
pvcClone.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany}
|
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
appCloneLabels := map[string]string{
|
|
|
|
appKey: appCloneLabel,
|
|
|
|
}
|
|
|
|
appClone.Labels = appCloneLabels
|
|
|
|
optAppClone := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appCloneLabels[appKey]),
|
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndApp("", f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC and app: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Snapshot-backed volume shouldn't contribute to total subvolume count.
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
|
|
|
|
|
|
|
// Deleting snapshot before deleting pvcClone should succeed. It will be
|
|
|
|
// deleted once all volumes that are backed by this snapshot are gone.
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete snapshot: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
appCloneTestFilePath := appClone.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snapFileSum, err := calculateSHA512sum(f, appClone, appCloneTestFilePath, &optAppClone)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if parentFileSum == snapFileSum {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("SHA512 sums of files in parent subvol and snapshot should differ")
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS snapshotclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-09-07 16:30:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 12:05:18 +00:00
|
|
|
By("checking snapshot-backed volume", func() {
|
|
|
|
err := createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-14 10:19:00 +00:00
|
|
|
framework.Failf("failed to create CephFS snapshotclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
2022-11-02 10:50:16 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 12:05:18 +00:00
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
appLabels := map[string]string{
|
|
|
|
appKey: appLabel,
|
|
|
|
}
|
|
|
|
app.Labels = appLabels
|
|
|
|
optApp := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appLabels[appKey]),
|
|
|
|
}
|
|
|
|
err = writeDataInPod(app, &optApp, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to write data: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
appTestFilePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create snapshot: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 1, subvolumegroup, pv)
|
2022-04-06 12:05:18 +00:00
|
|
|
|
|
|
|
err = appendToFileInContainer(f, app, appTestFilePath, "hello", &optApp)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to append data: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parentFileSum, err := calculateSHA512sum(f, app, appTestFilePath, &optApp)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 09:06:36 +00:00
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
|
|
|
}
|
|
|
|
// Snapshot-backed volumes support read-only access modes only.
|
|
|
|
pvcClone.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany}
|
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to load application: %v", err)
|
|
|
|
}
|
|
|
|
appCloneLabels := map[string]string{
|
|
|
|
appKey: appCloneLabel,
|
|
|
|
}
|
|
|
|
appClone.Labels = appCloneLabels
|
|
|
|
optAppClone := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appCloneLabels[appKey]),
|
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndApp("", f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create PVC and app: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snapshot-backed volume shouldn't contribute to total subvolume count.
|
|
|
|
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
|
|
|
|
|
|
|
// Deleting snapshot before deleting pvcClone should succeed. It will be
|
|
|
|
// deleted once all volumes that are backed by this snapshot are gone.
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete snapshot: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
appCloneTestFilePath := appClone.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snapFileSum, err := calculateSHA512sum(f, appClone, appCloneTestFilePath, &optAppClone)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if parentFileSum == snapFileSum {
|
|
|
|
framework.Failf("SHA512 sums of files in parent subvol and snapshot should differ")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
validateCephFSSnapshotCount(f, 0, subvolumegroup, pv)
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("checking snapshot-backed volume by backing snapshot as false", func() {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to get PV object for %s: %v", pvc.Name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to load application: %v", err)
|
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
appLabels := map[string]string{
|
|
|
|
appKey: appLabel,
|
|
|
|
}
|
|
|
|
app.Labels = appLabels
|
|
|
|
optApp := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appLabels[appKey]),
|
|
|
|
}
|
|
|
|
err = writeDataInPod(app, &optApp, f)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to write data: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
appTestFilePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create snapshot: %v", err)
|
|
|
|
}
|
|
|
|
validateCephFSSnapshotCount(f, 1, subvolumegroup, pv)
|
|
|
|
|
|
|
|
err = appendToFileInContainer(f, app, appTestFilePath, "hello", &optApp)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to append data: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parentFileSum, err := calculateSHA512sum(f, app, appTestFilePath, &optApp)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-04-06 12:05:18 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
2023-02-07 09:06:36 +00:00
|
|
|
|
2022-04-06 12:05:18 +00:00
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, map[string]string{
|
2023-02-07 09:06:36 +00:00
|
|
|
"backingSnapshot": "false",
|
2022-04-06 12:05:18 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
// Snapshot-backed volumes support read-only access modes only.
|
|
|
|
pvcClone.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany}
|
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
appCloneLabels := map[string]string{
|
|
|
|
appKey: appCloneLabel,
|
|
|
|
}
|
|
|
|
appClone.Labels = appCloneLabels
|
|
|
|
optAppClone := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appCloneLabels[appKey]),
|
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndApp("", f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC and app: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 09:06:36 +00:00
|
|
|
validateSubvolumeCount(f, 2, fileSystemName, subvolumegroup)
|
2022-04-06 12:05:18 +00:00
|
|
|
|
|
|
|
// Deleting snapshot before deleting pvcClone should succeed. It will be
|
|
|
|
// deleted once all volumes that are backed by this snapshot are gone.
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete snapshot: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
2023-02-07 09:06:36 +00:00
|
|
|
validateCephFSSnapshotCount(f, 0, subvolumegroup, pv)
|
2022-04-06 12:05:18 +00:00
|
|
|
|
|
|
|
appCloneTestFilePath := appClone.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
|
|
|
snapFileSum, err := calculateSHA512sum(f, appClone, appCloneTestFilePath, &optAppClone)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to get SHA512 sum for file: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if parentFileSum == snapFileSum {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("SHA512 sums of files in parent subvol and snapshot should differ")
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 0, subvolumegroup, pv)
|
|
|
|
|
2022-04-06 12:05:18 +00:00
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete CephFS storageclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-04-06 12:05:18 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
})
|
|
|
|
|
2022-08-26 18:18:07 +00:00
|
|
|
if testCephFSFscrypt {
|
|
|
|
kmsToTest := map[string]kmsConfig{
|
|
|
|
"secrets-metadata-test": secretsMetadataKMS,
|
|
|
|
"vault-test": vaultKMS,
|
|
|
|
}
|
|
|
|
for kmsID, kmsConf := range kmsToTest {
|
|
|
|
kmsID := kmsID
|
|
|
|
kmsConf := kmsConf
|
|
|
|
By("create an encrypted PVC-PVC clone and bind it to an app with "+kmsID, func() {
|
|
|
|
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2022-08-26 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scOpts := map[string]string{
|
|
|
|
"encrypted": "true",
|
|
|
|
"encryptionKMSID": kmsID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, true, scOpts)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-08-26 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateFscryptClone(pvcPath, appPath, pvcSmartClonePath, appSmartClonePath, kmsConf, f)
|
|
|
|
|
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2022-08-26 18:18:07 +00:00
|
|
|
}
|
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create CephFS storageclass: %v", err)
|
2022-08-26 18:18:07 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
By("create a PVC-PVC clone and bind it to an app", func() {
|
2021-11-03 12:07:59 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
totalCount := 3
|
|
|
|
wgErrs := make([]error, totalCount)
|
|
|
|
// totalSubvolumes represents the subvolumes in backend
|
|
|
|
// always totalCount+parentPVC
|
|
|
|
totalSubvolumes := totalCount + 1
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
2020-06-16 11:06:15 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
label := make(map[string]string)
|
|
|
|
label[appKey] = appLabel
|
|
|
|
app.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
wErr := writeDataInPod(app, &opt, f)
|
|
|
|
if wErr != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to write data from application %v", wErr)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
2020-06-16 11:06:15 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
pvcClone, err := loadPVC(pvcSmartClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
pvcClone.Spec.DataSource.Name = pvc.Name
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone, err := loadApp(appSmartClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// create clone and bind it to an app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout)
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
failed := 0
|
|
|
|
for i, err := range wgErrs {
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-03 12:07:59 +00:00
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to create PVC or application (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:59 +00:00
|
|
|
failed++
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
2020-11-04 14:45:06 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
2020-06-16 11:06:15 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
// delete parent pvc
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
2020-01-31 08:49:11 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
p.Spec.DataSource.Name = name
|
|
|
|
wgErrs[n] = deletePVCAndApp(name, f, &p, &a)
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-09-03 09:34:29 +00:00
|
|
|
|
2021-11-03 12:07:59 +00:00
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("failed to delete PVC or application (%s%d): %v", f.UniqueName, i, err)
|
2021-11-03 12:07:59 +00:00
|
|
|
failed++
|
2020-11-04 14:45:06 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-11-03 12:07:59 +00:00
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2021-11-03 12:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2020-09-03 09:34:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
By("Create ROX PVC and bind it to an app", func() {
|
|
|
|
// create PVC and bind it to an app
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvc.Namespace = f.UniqueName
|
2020-09-10 09:46:53 +00:00
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
2020-09-10 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvcClone, err := loadPVC(pvcSmartClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load PVC: %v", err)
|
2020-09-10 09:46:53 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = pvc.Name
|
|
|
|
pvcClone.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany}
|
2020-09-03 09:34:29 +00:00
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to load application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
label := map[string]string{
|
|
|
|
"app": app.Name,
|
|
|
|
}
|
|
|
|
app.Labels = label
|
2020-09-10 09:46:53 +00:00
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcClone.Name
|
|
|
|
err = createPVCAndApp("", f, pvcClone, app, deployTimeout)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create PVC or application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("app=%s", app.Name),
|
|
|
|
}
|
|
|
|
|
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
2021-06-25 12:31:28 +00:00
|
|
|
_, stdErr := execCommandInPodAndAllowFail(
|
|
|
|
f,
|
|
|
|
fmt.Sprintf("echo 'Hello World' > %s", filePath),
|
|
|
|
app.Namespace,
|
|
|
|
&opt)
|
2020-09-03 09:34:29 +00:00
|
|
|
readOnlyErr := fmt.Sprintf("cannot create %s: Read-only file system", filePath)
|
|
|
|
if !strings.Contains(stdErr, readOnlyErr) {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf(stdErr)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 09:46:53 +00:00
|
|
|
// delete cloned ROX pvc and app
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, app)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC or application: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-09-10 09:46:53 +00:00
|
|
|
|
|
|
|
// delete parent pvc
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2020-09-10 09:46:53 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
})
|
2022-01-10 05:05:02 +00:00
|
|
|
|
|
|
|
By("restore snapshot to a bigger size PVC", func() {
|
|
|
|
err := validateBiggerPVCFromSnapshot(f,
|
|
|
|
pvcPath,
|
|
|
|
appPath,
|
|
|
|
snapshotPath,
|
|
|
|
pvcClonePath,
|
|
|
|
appClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate restore bigger size clone: %v", err)
|
2022-01-10 05:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2022-01-10 05:05:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
By("clone PVC to a bigger size PVC", func() {
|
|
|
|
err := validateBiggerCloneFromPVC(f,
|
|
|
|
pvcPath,
|
|
|
|
appPath,
|
|
|
|
pvcSmartClonePath,
|
|
|
|
appSmartClonePath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate bigger size clone: %v", err)
|
2022-01-10 05:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
2022-04-25 11:51:05 +00:00
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
2022-01-10 05:05:02 +00:00
|
|
|
})
|
|
|
|
|
2022-04-07 15:48:02 +00:00
|
|
|
// FIXME: in case NFS testing is done, prevent deletion
|
|
|
|
// of the CephFS filesystem and related pool. This can
|
|
|
|
// probably be addressed in a nicer way, making sure
|
|
|
|
// everything is tested, always.
|
|
|
|
if testNFS {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("skipping CephFS destructive tests, allow NFS to run")
|
2022-04-07 15:48:02 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
// Make sure this should be last testcase in this file, because
|
|
|
|
// it deletes pool
|
|
|
|
By("Create a PVC and delete PVC when backend pool deleted", func() {
|
|
|
|
err := pvcDeleteWhenPoolNotFound(pvcPath, true, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
2021-02-22 11:13:40 +00:00
|
|
|
// delete cephFS provisioner secret
|
|
|
|
err := deleteCephUser(f, keyringCephFSProvisionerUsername)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete user %s: %v", keyringCephFSProvisionerUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
// delete cephFS plugin secret
|
|
|
|
err = deleteCephUser(f, keyringCephFSNodePluginUsername)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete user %s: %v", keyringCephFSNodePluginUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|