2022-04-07 15:48:02 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2022-05-16 09:15:24 +00:00
|
|
|
"sync"
|
2022-04-07 15:48:02 +00:00
|
|
|
"time"
|
|
|
|
|
2024-09-09 13:11:01 +00:00
|
|
|
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
2024-04-04 08:49:32 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2022-05-16 09:15:24 +00:00
|
|
|
v1 "k8s.io/api/core/v1"
|
2022-04-07 15:48:02 +00:00
|
|
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
|
|
|
"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"
|
2022-04-07 15:48:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
nfsProvisioner = "csi-nfsplugin-provisioner.yaml"
|
|
|
|
nfsProvisionerRBAC = "csi-provisioner-rbac.yaml"
|
|
|
|
nfsNodePlugin = "csi-nfsplugin.yaml"
|
|
|
|
nfsNodePluginRBAC = "csi-nodeplugin-rbac.yaml"
|
|
|
|
nfsRookCephNFS = "rook-nfs.yaml"
|
|
|
|
nfsDeploymentName = "csi-nfsplugin-provisioner"
|
2022-07-26 10:32:40 +00:00
|
|
|
nfsDeamonSetName = "csi-nfsplugin"
|
2023-06-13 09:49:01 +00:00
|
|
|
nfsContainerName = "csi-nfsplugin"
|
2022-04-07 15:48:02 +00:00
|
|
|
nfsDirPath = "../deploy/nfs/kubernetes/"
|
|
|
|
nfsExamplePath = examplePath + "nfs/"
|
|
|
|
nfsPoolName = ".nfs"
|
|
|
|
|
|
|
|
// FIXME: some tests change the subvolumegroup to "e2e".
|
|
|
|
defaultSubvolumegroup = "csi"
|
|
|
|
)
|
|
|
|
|
|
|
|
func deployNFSPlugin(f *framework.Framework) {
|
|
|
|
// delete objects deployed by rook
|
|
|
|
|
|
|
|
err := deleteResource(nfsDirPath + nfsProvisionerRBAC)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete provisioner rbac %s: %v", nfsDirPath+nfsProvisionerRBAC, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(nfsDirPath + nfsNodePluginRBAC)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete nodeplugin rbac %s: %v", nfsDirPath+nfsNodePluginRBAC, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the pool should not be deleted, as it may contain configurations
|
|
|
|
// from non-e2e related CephNFS objects
|
|
|
|
err = createPool(f, nfsPoolName)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create pool for NFS config %q: %v", nfsPoolName, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 09:28:32 +00:00
|
|
|
createORDeleteNFSResources(kubectlCreate)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func deleteNFSPlugin() {
|
2023-08-21 09:28:32 +00:00
|
|
|
createORDeleteNFSResources(kubectlDelete)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 09:28:32 +00:00
|
|
|
func createORDeleteNFSResources(action kubectlAction) {
|
2023-06-06 13:16:27 +00:00
|
|
|
cephConfigFile := getConfigFile(cephConfconfigMap, deployPath, examplePath)
|
2022-04-07 15:48:02 +00:00
|
|
|
resources := []ResourceDeployer{
|
2022-05-11 10:06:40 +00:00
|
|
|
// shared resources
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResource{
|
|
|
|
filename: nfsDirPath + csiDriverObject,
|
|
|
|
allowMissing: true,
|
|
|
|
},
|
|
|
|
&yamlResource{
|
2023-05-30 15:17:51 +00:00
|
|
|
filename: cephConfigFile,
|
2022-04-07 15:48:02 +00:00
|
|
|
allowMissing: true,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// dependencies for provisioner
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: nfsDirPath + nfsProvisionerRBAC,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// the provisioner itself
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: nfsDirPath + nfsProvisioner,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
oneReplica: true,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// dependencies for the node-plugin
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: nfsDirPath + nfsNodePluginRBAC,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2022-05-11 10:06:40 +00:00
|
|
|
// the node-plugin itself
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: nfsDirPath + nfsNodePlugin,
|
|
|
|
namespace: cephCSINamespace,
|
|
|
|
},
|
2023-08-21 09:28:32 +00:00
|
|
|
// NFS server deployment
|
2022-04-07 15:48:02 +00:00
|
|
|
&yamlResourceNamespaced{
|
|
|
|
filename: nfsExamplePath + nfsRookCephNFS,
|
|
|
|
namespace: rookNamespace,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, r := range resources {
|
|
|
|
err := r.Do(action)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to %s resource: %v", action, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createNFSStorageClass(
|
|
|
|
c clientset.Interface,
|
|
|
|
f *framework.Framework,
|
|
|
|
enablePool bool,
|
2022-06-01 10:17:19 +00:00
|
|
|
params map[string]string,
|
|
|
|
) error {
|
2022-04-07 15:48:02 +00:00
|
|
|
scPath := fmt.Sprintf("%s/%s", nfsExamplePath, "storageclass.yaml")
|
|
|
|
sc, err := getStorageClass(scPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sc.Parameters["nfsCluster"] = "my-nfs"
|
|
|
|
sc.Parameters["server"] = "rook-ceph-nfs-my-nfs-a." + rookNamespace + ".svc.cluster.local"
|
|
|
|
|
|
|
|
// standard CephFS parameters
|
|
|
|
sc.Parameters["fsName"] = fileSystemName
|
|
|
|
sc.Parameters["csi.storage.k8s.io/provisioner-secret-namespace"] = cephCSINamespace
|
|
|
|
sc.Parameters["csi.storage.k8s.io/provisioner-secret-name"] = cephFSProvisionerSecretName
|
|
|
|
|
|
|
|
sc.Parameters["csi.storage.k8s.io/controller-expand-secret-namespace"] = cephCSINamespace
|
|
|
|
sc.Parameters["csi.storage.k8s.io/controller-expand-secret-name"] = cephFSProvisionerSecretName
|
|
|
|
|
|
|
|
sc.Parameters["csi.storage.k8s.io/node-stage-secret-namespace"] = cephCSINamespace
|
|
|
|
sc.Parameters["csi.storage.k8s.io/node-stage-secret-name"] = cephFSNodePluginSecretName
|
|
|
|
|
|
|
|
if enablePool {
|
|
|
|
sc.Parameters["pool"] = "myfs-replicated"
|
|
|
|
}
|
|
|
|
|
|
|
|
// overload any parameters that were passed
|
|
|
|
if params == nil {
|
|
|
|
// create an empty params, so that params["clusterID"] below
|
|
|
|
// does not panic
|
|
|
|
params = map[string]string{}
|
|
|
|
}
|
|
|
|
for param, value := range params {
|
|
|
|
sc.Parameters[param] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch and set fsID from the cluster if not set in params
|
|
|
|
if _, found := params["clusterID"]; !found {
|
|
|
|
var fsID string
|
|
|
|
fsID, err = getClusterID(f)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to get clusterID: %w", err)
|
|
|
|
}
|
|
|
|
sc.Parameters["clusterID"] = fsID
|
|
|
|
}
|
|
|
|
|
|
|
|
sc.Provisioner = nfsDriverName
|
|
|
|
|
|
|
|
timeout := time.Duration(deployTimeout) * time.Minute
|
|
|
|
|
2023-06-05 14:41:04 +00:00
|
|
|
return wait.PollUntilContextTimeout(context.TODO(), poll, timeout, true, func(ctx context.Context) (bool, error) {
|
|
|
|
_, err = c.StorageV1().StorageClasses().Create(ctx, &sc, metav1.CreateOptions{})
|
2022-04-07 15:48:02 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("error creating StorageClass %q: %v", sc.Name, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
if apierrs.IsAlreadyExists(err) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if isRetryableAPIError(err) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, fmt.Errorf("failed to create StorageClass %q: %w", sc.Name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmountNFSVolume unmounts a NFS volume mounted on a pod.
|
|
|
|
func unmountNFSVolume(f *framework.Framework, appName, pvcName string) error {
|
|
|
|
pod, err := f.ClientSet.CoreV1().Pods(f.UniqueName).Get(context.TODO(), appName, metav1.GetOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Error occurred getting pod %s in namespace %s", appName, f.UniqueName)
|
2022-04-07 15:48:02 +00:00
|
|
|
|
|
|
|
return fmt.Errorf("failed to get pod: %w", err)
|
|
|
|
}
|
|
|
|
pvc, err := f.ClientSet.CoreV1().
|
|
|
|
PersistentVolumeClaims(f.UniqueName).
|
|
|
|
Get(context.TODO(), pvcName, metav1.GetOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName)
|
2022-04-07 15:48:02 +00:00
|
|
|
|
|
|
|
return fmt.Errorf("failed to get pvc: %w", err)
|
|
|
|
}
|
|
|
|
cmd := fmt.Sprintf(
|
|
|
|
"umount /var/lib/kubelet/pods/%s/volumes/kubernetes.io~csi/%s/mount",
|
|
|
|
pod.UID,
|
|
|
|
pvc.Spec.VolumeName)
|
|
|
|
stdErr, err := execCommandInDaemonsetPod(
|
|
|
|
f,
|
|
|
|
cmd,
|
|
|
|
nfsDeamonSetName,
|
|
|
|
pod.Spec.NodeName,
|
2022-07-26 10:32:40 +00:00
|
|
|
"csi-nfsplugin", // name of the container
|
2022-04-07 15:48:02 +00:00
|
|
|
cephCSINamespace)
|
|
|
|
if stdErr != "" {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("StdErr occurred: %s", stdErr)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = Describe("nfs", func() {
|
|
|
|
f := framework.NewDefaultFramework("nfs")
|
2022-09-02 05:03:48 +00:00
|
|
|
f.NamespacePodSecurityEnforceLevel = api.LevelPrivileged
|
2022-04-07 15:48:02 +00:00
|
|
|
var c clientset.Interface
|
|
|
|
// deploy CephFS CSI
|
|
|
|
BeforeEach(func() {
|
2022-04-11 15:00:25 +00:00
|
|
|
if !testNFS || upgradeTesting || helmTest {
|
2022-04-07 15:48:02 +00:00
|
|
|
Skip("Skipping NFS E2E")
|
|
|
|
}
|
|
|
|
c = f.ClientSet
|
|
|
|
if deployNFS {
|
|
|
|
if cephCSINamespace != defaultNs {
|
|
|
|
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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
deployNFSPlugin(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
// cephfs testing might have changed the default subvolumegroup
|
|
|
|
subvolumegroup = defaultSubvolumegroup
|
|
|
|
err := createConfigMap(nfsDirPath, f.ClientSet, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create configmap: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
// create nfs provisioner secret
|
|
|
|
key, err := createCephUser(f, keyringCephFSProvisionerUsername, cephFSProvisionerCaps())
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create user %s: %v", keyringCephFSProvisionerUsername, err)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
// create nfs 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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
2023-10-16 08:14:44 +00:00
|
|
|
|
|
|
|
err = createSubvolumegroup(f, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("%v", err)
|
|
|
|
}
|
2022-04-07 15:48:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
if !testNFS || upgradeTesting {
|
|
|
|
Skip("Skipping NFS E2E")
|
|
|
|
}
|
2022-11-09 05:02:09 +00:00
|
|
|
if CurrentSpecReport().Failed() {
|
2022-04-07 15:48:02 +00:00
|
|
|
// log pods created by helm chart
|
|
|
|
logsCSIPods("app=ceph-csi-nfs", c)
|
|
|
|
// log provisioner
|
|
|
|
logsCSIPods("app=csi-nfsplugin-provisioner", c)
|
|
|
|
// log node plugin
|
2022-07-26 10:32:40 +00:00
|
|
|
logsCSIPods("app=csi-nfsplugin", c)
|
2022-04-07 15:48:02 +00:00
|
|
|
|
|
|
|
// log all details from the namespace where Ceph-CSI is deployed
|
2023-06-02 15:25:01 +00:00
|
|
|
e2edebug.DumpAllNamespaceInfo(context.TODO(), c, cephCSINamespace)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err := deleteConfigMap(nfsDirPath)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete configmap: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSProvisionerSecretName, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete provisioner secret: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSNodePluginSecretName, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete node secret: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete storageclass: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
2023-10-16 08:14:44 +00:00
|
|
|
err = deleteSubvolumegroup(f, fileSystemName, subvolumegroup)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("%v", err)
|
|
|
|
}
|
|
|
|
|
2022-04-07 15:48:02 +00:00
|
|
|
if deployNFS {
|
|
|
|
deleteNFSPlugin()
|
|
|
|
if cephCSINamespace != defaultNs {
|
2023-10-16 08:14:44 +00:00
|
|
|
err = deleteNamespace(c, cephCSINamespace)
|
2022-04-07 15:48:02 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete namespace %s: %v", cephCSINamespace, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("Test NFS CSI", func() {
|
|
|
|
if !testNFS {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
It("Test NFS CSI", func() {
|
|
|
|
pvcPath := nfsExamplePath + "pvc.yaml"
|
|
|
|
appPath := nfsExamplePath + "pod.yaml"
|
|
|
|
appRWOPPath := nfsExamplePath + "pod-rwop.yaml"
|
|
|
|
pvcRWOPPath := nfsExamplePath + "pvc-rwop.yaml"
|
2022-05-16 09:15:24 +00:00
|
|
|
pvcSmartClonePath := nfsExamplePath + "pvc-clone.yaml"
|
|
|
|
appSmartClonePath := nfsExamplePath + "pod-clone.yaml"
|
2022-05-16 09:38:35 +00:00
|
|
|
pvcClonePath := nfsExamplePath + "pvc-restore.yaml"
|
|
|
|
appClonePath := nfsExamplePath + "pod-restore.yaml"
|
|
|
|
snapshotPath := nfsExamplePath + "snapshot.yaml"
|
2022-05-16 09:15:24 +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-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 15:48:02 +00:00
|
|
|
By("checking provisioner deployment is running", func() {
|
|
|
|
err := waitForDeploymentComplete(f.ClientSet, nfsDeploymentName, cephCSINamespace, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("timeout waiting for deployment %s: %v", nfsDeploymentName, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("checking nodeplugin deamonset pods are running", func() {
|
|
|
|
err := waitForDaemonSets(nfsDeamonSetName, cephCSINamespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("timeout waiting for daemonset %s: %v", nfsDeamonSetName, err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-06-13 09:49:01 +00:00
|
|
|
By("verify mountOptions support", func() {
|
|
|
|
err := createNFSStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create NFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = verifySeLinuxMountOption(f, pvcPath, appPath,
|
|
|
|
nfsDeamonSetName, nfsContainerName, cephCSINamespace)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to verify mount options: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete NFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-04-07 15:48:02 +00:00
|
|
|
By("verify RWOP volume support", func() {
|
2022-07-25 04:40:20 +00:00
|
|
|
err := createNFSStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create NFS 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-04-07 15:48:02 +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-04-07 15:48:02 +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-07 15:48:02 +00:00
|
|
|
|
2022-07-25 04:40:20 +00:00
|
|
|
return
|
2022-04-07 15:48:02 +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, defaultSubvolumegroup)
|
2022-04-07 15:48:02 +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, defaultSubvolumegroup)
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete NFS storageclass: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("create a storageclass with pool and a PVC then bind it to an app", func() {
|
2022-10-13 14:05:08 +00:00
|
|
|
err := createNFSStorageClass(f.ClientSet, f, true, nil)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create NFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to validate NFS pvc and application binding: %v", err)
|
|
|
|
}
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete NFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("create a storageclass with sys,krb5i security and a PVC then bind it to an app", func() {
|
|
|
|
err := createNFSStorageClass(f.ClientSet, f, false, map[string]string{
|
|
|
|
"secTypes": "sys,krb5i",
|
|
|
|
})
|
2022-04-07 15:48:02 +00:00
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create NFS storageclass: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate NFS pvc and application binding: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete NFS storageclass: %v", err)
|
2023-06-08 15:23:41 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("create a storageclass with a restricted set of clients allowed to mount it", func() {
|
|
|
|
clientExample := "192.168.49.29"
|
|
|
|
err := createNFSStorageClass(f.ClientSet, f, false, map[string]string{
|
|
|
|
"clients": clientExample,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create NFS storageclass: %v", err)
|
|
|
|
}
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("Could not create PVC: 1 %v", err)
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to create PVC: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !checkExports(f, "my-nfs", clientExample) {
|
|
|
|
framework.Failf("failed in testing exports")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete PVC: %v", err)
|
|
|
|
}
|
|
|
|
err = deleteResource(nfsExamplePath + "storageclass.yaml")
|
|
|
|
if err != nil {
|
|
|
|
framework.Failf("failed to delete NFS storageclass: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("create a PVC and bind it to an app", func() {
|
|
|
|
err := createNFSStorageClass(f.ClientSet, f, false, nil)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to create NFS storageclass: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate NFS pvc and application binding: %v", err)
|
2022-04-07 15:48:02 +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 NFS pvc and application binding: %v", err)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
// create PVC and app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-04-07 15:48:02 +00:00
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err = createPVCAndApp(name, 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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
err = validateSubvolumePath(f, pvc.Name, pvc.Namespace, fileSystemName, defaultSubvolumegroup)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to validate subvolumePath: %v", err)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, totalCount, fileSystemName, defaultSubvolumegroup)
|
|
|
|
// delete PVC and app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-04-07 15:48:02 +00:00
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err = deletePVCAndApp(name, 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-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, defaultSubvolumegroup)
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = unmountNFSVolume(f, app.Name, pvc.Name)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to unmount volume: %v", err)
|
2022-04-07 15:48:02 +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-07 15:48:02 +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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
2024-04-04 08:49:32 +00:00
|
|
|
LabelSelector: "app=" + app.Name,
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
_, stdErr := execCommandInPodAndAllowFail(
|
|
|
|
f,
|
2024-04-04 08:49:32 +00:00
|
|
|
"echo 'Hello World' > "+filePath,
|
2022-04-07 15:48:02 +00:00
|
|
|
app.Namespace,
|
|
|
|
&opt)
|
|
|
|
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)
|
2022-04-07 15:48:02 +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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// delete nfs 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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
|
|
|
// delete nfs 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)
|
2022-04-07 15:48:02 +00:00
|
|
|
}
|
2022-05-02 08:28:58 +00:00
|
|
|
|
|
|
|
By("Resize PVC and check application directory size", func() {
|
|
|
|
err := resizePVCAndValidateSize(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to resize PVC: %v", err)
|
2022-05-02 08:28:58 +00:00
|
|
|
}
|
|
|
|
})
|
2022-05-16 09:15:24 +00:00
|
|
|
|
2022-05-16 09:38:35 +00:00
|
|
|
By("create a PVC clone and bind it to an app", func() {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
totalCount := 3
|
|
|
|
wgErrs := make([]error, totalCount)
|
|
|
|
chErrs := make([]error, totalCount)
|
|
|
|
// totalSubvolumes represents the subvolumes in backend
|
|
|
|
// always totalCount+parentPVC
|
|
|
|
totalSubvolumes := totalCount + 1
|
|
|
|
wg.Add(totalCount)
|
|
|
|
err := createNFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete NFS snapshotclass: %v", err)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = deleteNFSSnapshotClass()
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to delete VolumeSnapshotClass: %v", err)
|
2022-05-16 09:38:35 +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-16 09:38:35 +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-16 09:38:35 +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-05-16 09:38:35 +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]),
|
|
|
|
}
|
|
|
|
checkSum, err := writeDataAndCalChecksum(app, &opt, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to calculate checksum: %v", err)
|
2022-05-16 09:38:35 +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-05-16 09:38:35 +00:00
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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 {
|
|
|
|
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 snapshot (%s%d): %v", f.UniqueName, i, err)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating snapshots failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, totalCount, defaultSubvolumegroup, pv)
|
2022-05-16 09:38:35 +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-05-16 09:38:35 +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)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = fmt.Sprintf("%s%d", f.UniqueName, 0)
|
|
|
|
appClone.Labels = label
|
|
|
|
|
|
|
|
// create multiple PVC from same snapshot
|
|
|
|
wg.Add(totalCount)
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
filePath := a.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
var checkSumClone string
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Calculating checksum clone for filepath %s", filePath)
|
2022-05-16 09:38:35 +00:00
|
|
|
checkSumClone, chErrs[n] = calculateSHA512sum(f, &a, filePath, &opt)
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum for clone is %s", checkSumClone)
|
2022-05-16 09:38:35 +00:00
|
|
|
if chErrs[n] != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Failed calculating checksum clone %s", chErrs[n])
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
if checkSumClone != checkSum {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum didn't match. checksum=%s and checksumclone=%s", checkSum, checkSumClone)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, err := range chErrs {
|
|
|
|
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 calculate checksum (%s%d): %v", f.UniqueName, i, err)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("calculating checksum failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
|
|
|
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parentPVCCount := totalSubvolumes - totalCount
|
|
|
|
validateSubvolumeCount(f, parentPVCCount, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, parentPVCCount, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
|
|
|
// create clones from different snapshots and bind it to an app
|
|
|
|
wg.Add(totalCount)
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
filePath := a.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
var checkSumClone string
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Calculating checksum clone for filepath %s", filePath)
|
2022-05-16 09:38:35 +00:00
|
|
|
checkSumClone, chErrs[n] = calculateSHA512sum(f, &a, filePath, &opt)
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum for clone is %s", checkSumClone)
|
2022-05-16 09:38:35 +00:00
|
|
|
if chErrs[n] != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Failed calculating checksum clone %s", chErrs[n])
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
if checkSumClone != checkSum {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum didn't match. checksum=%s and checksumclone=%s", checkSum, checkSumClone)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("creating PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, err := range chErrs {
|
|
|
|
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 calculate checksum (%s%d): %v", f.UniqueName, i, err)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("calculating checksum failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, totalCount, cephfsType, metadataPool, snapsType)
|
|
|
|
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete snapshot
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting snapshots failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 10:50:16 +00:00
|
|
|
validateCephFSSnapshotCount(f, 0, defaultSubvolumegroup, pv)
|
|
|
|
|
2022-05-16 09:38:35 +00:00
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:38:35 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:38:35 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, parentPVCCount, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, parentPVCCount, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, snapsType)
|
|
|
|
// 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 or application: %v", err)
|
2022-05-16 09:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, snapsType)
|
|
|
|
})
|
|
|
|
|
2022-05-16 09:15:24 +00:00
|
|
|
By("create a PVC-PVC clone and bind it to an app", func() {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
totalCount := 3
|
|
|
|
wgErrs := make([]error, totalCount)
|
|
|
|
chErrs := 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)
|
2022-05-16 09:15:24 +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-16 09:15:24 +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-05-16 09:15:24 +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]),
|
|
|
|
}
|
|
|
|
checkSum, err := writeDataAndCalChecksum(app, &opt, f)
|
|
|
|
if err != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("failed to calculate checksum: %v", err)
|
2022-05-16 09:15:24 +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-05-16 09:15:24 +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)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
appClone.Labels = label
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// create clone and bind it to an app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:15:24 +00:00
|
|
|
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 {
|
|
|
|
filePath := a.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
var checkSumClone string
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Calculating checksum clone for filepath %s", filePath)
|
2022-05-16 09:15:24 +00:00
|
|
|
checkSumClone, chErrs[n] = calculateSHA512sum(f, &a, filePath, &opt)
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum for clone is %s", checkSumClone)
|
2022-05-16 09:15:24 +00:00
|
|
|
if chErrs[n] != nil {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("Failed calculating checksum clone %s", chErrs[n])
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
if checkSumClone != checkSum {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Logf("checksum didn't match. checksum=%s and checksumclone=%s", checkSum, checkSumClone)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wg.Done()
|
|
|
|
}(i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
failed := 0
|
|
|
|
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 or application (%s%d): %v", f.UniqueName, i, err)
|
2022-05-16 09:15:24 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, err := range chErrs {
|
|
|
|
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 calculate checksum (%s%d): %v", f.UniqueName, i, err)
|
2022-05-16 09:15:24 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("calculating checksum failed, %d errors were logged", failed)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, totalSubvolumes, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, totalSubvolumes, cephfsType, metadataPool, volumesType)
|
|
|
|
|
|
|
|
// 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 or application: %v", err)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
2024-04-26 08:49:26 +00:00
|
|
|
for i := range totalCount {
|
2022-05-16 09:15:24 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
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)
|
2022-05-16 09:15:24 +00:00
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
2023-02-01 17:06:36 +00:00
|
|
|
framework.Failf("deleting PVCs and apps failed, %d errors were logged", failed)
|
2022-05-16 09:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
|
|
|
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
|
|
|
})
|
2022-04-07 15:48:02 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|