2019-05-31 09:34:04 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2020-04-14 06:59:04 +00:00
|
|
|
"context"
|
2019-05-31 09:34:04 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
2020-06-11 08:04:32 +00:00
|
|
|
"errors"
|
2019-05-31 09:34:04 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2020-09-20 00:43:26 +00:00
|
|
|
"regexp"
|
2019-05-31 09:34:04 +00:00
|
|
|
"strings"
|
2020-10-15 13:53:55 +00:00
|
|
|
"sync"
|
2019-05-31 09:34:04 +00:00
|
|
|
"time"
|
|
|
|
|
2021-04-08 15:46:11 +00:00
|
|
|
"github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
|
2019-05-31 09:34:04 +00:00
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
scv1 "k8s.io/api/storage/v1"
|
2020-10-28 07:43:52 +00:00
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
2019-05-31 09:34:04 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2019-12-13 11:41:32 +00:00
|
|
|
"k8s.io/apimachinery/pkg/fields"
|
2019-05-31 09:34:04 +00:00
|
|
|
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2019-06-24 07:58:39 +00:00
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
2020-07-20 12:49:05 +00:00
|
|
|
/* #nosec:G101, values not credententials, just a reference to the location.*/
|
2019-12-03 12:36:15 +00:00
|
|
|
const (
|
2021-03-23 07:56:35 +00:00
|
|
|
defaultNs = "default"
|
|
|
|
|
|
|
|
// vaultBackendPath is the default VAULT_BACKEND_PATH for secrets
|
|
|
|
vaultBackendPath = "secret/"
|
|
|
|
// vaultPassphrasePath is an advanced configuration option, only
|
|
|
|
// available for the VaultKMS (not VaultTokensKMS) provider.
|
|
|
|
vaultPassphrasePath = "ceph-csi/"
|
2020-04-07 08:35:05 +00:00
|
|
|
|
2021-03-18 10:01:16 +00:00
|
|
|
rookToolBoxPodLabel = "app=rook-ceph-tools"
|
|
|
|
rbdmountOptions = "mountOptions"
|
2020-10-28 06:08:11 +00:00
|
|
|
|
|
|
|
retainPolicy = v1.PersistentVolumeReclaimRetain
|
2020-10-28 07:43:52 +00:00
|
|
|
// deletePolicy is the default policy in E2E.
|
2020-10-28 06:08:11 +00:00
|
|
|
deletePolicy = v1.PersistentVolumeReclaimDelete
|
2020-10-13 05:34:55 +00:00
|
|
|
// Default key and label for Listoptions
|
|
|
|
appKey = "app"
|
|
|
|
appLabel = "write-data-in-pod"
|
2019-12-03 12:36:15 +00:00
|
|
|
)
|
|
|
|
|
2020-02-25 11:45:54 +00:00
|
|
|
var (
|
2020-02-25 11:57:12 +00:00
|
|
|
// cli flags
|
|
|
|
deployTimeout int
|
|
|
|
deployCephFS bool
|
|
|
|
deployRBD bool
|
2020-07-08 11:46:31 +00:00
|
|
|
testCephFS bool
|
|
|
|
testRBD bool
|
2020-07-25 16:39:50 +00:00
|
|
|
upgradeTesting bool
|
|
|
|
upgradeVersion string
|
2020-02-25 11:57:12 +00:00
|
|
|
cephCSINamespace string
|
|
|
|
rookNamespace string
|
2020-06-02 19:19:57 +00:00
|
|
|
radosNamespace string
|
2020-02-26 08:11:05 +00:00
|
|
|
ns string
|
|
|
|
vaultAddr string
|
|
|
|
poll = 2 * time.Second
|
|
|
|
)
|
2020-02-25 11:57:12 +00:00
|
|
|
|
2020-02-26 08:11:05 +00:00
|
|
|
func initResouces() {
|
|
|
|
ns = fmt.Sprintf("--namespace=%v", cephCSINamespace)
|
2020-02-25 11:45:54 +00:00
|
|
|
vaultAddr = fmt.Sprintf("http://vault.%s.svc.cluster.local:8200", cephCSINamespace)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func getMons(ns string, c kubernetes.Interface) ([]string, error) {
|
2019-05-31 09:34:04 +00:00
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=rook-ceph-mon",
|
|
|
|
}
|
|
|
|
services := make([]string, 0)
|
2020-09-03 09:34:29 +00:00
|
|
|
|
|
|
|
svcList, err := c.CoreV1().Services(ns).List(context.TODO(), opt)
|
|
|
|
if err != nil {
|
|
|
|
return services, err
|
|
|
|
}
|
2019-06-10 06:48:41 +00:00
|
|
|
for i := range svcList.Items {
|
|
|
|
s := fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcList.Items[i].Name, svcList.Items[i].Namespace, svcList.Items[i].Spec.Ports[0].Port)
|
2019-05-31 09:34:04 +00:00
|
|
|
services = append(services, s)
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
return services, nil
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func getStorageClass(path string) (scv1.StorageClass, error) {
|
2019-05-31 09:34:04 +00:00
|
|
|
sc := scv1.StorageClass{}
|
|
|
|
err := unmarshal(path, &sc)
|
2020-09-03 09:34:29 +00:00
|
|
|
return sc, err
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func getSecret(path string) (v1.Secret, error) {
|
2019-05-31 09:34:04 +00:00
|
|
|
sc := v1.Secret{}
|
|
|
|
err := unmarshal(path, &sc)
|
2019-06-10 06:48:41 +00:00
|
|
|
// discard corruptInputError
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
2020-06-25 08:35:19 +00:00
|
|
|
var b64cie base64.CorruptInputError
|
|
|
|
if !errors.As(err, &b64cie) {
|
2020-09-03 09:34:29 +00:00
|
|
|
return sc, err
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
return sc, nil
|
2020-04-09 05:48:09 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func deleteResource(scPath string) error {
|
2020-02-26 08:11:05 +00:00
|
|
|
data, err := replaceNamespaceInTemplate(scPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to read content from %s %v", scPath, err)
|
|
|
|
}
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = framework.RunKubectlInput(cephCSINamespace, data, ns, "delete", "-f", "-")
|
2020-02-26 08:11:05 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete %s %v", scPath, err)
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func unmarshal(fileName string, obj interface{}) error {
|
|
|
|
f, err := ioutil.ReadFile(fileName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
data, err := utilyaml.ToJSON(f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(data, obj)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-18 07:07:11 +00:00
|
|
|
// createPVCAndApp creates pvc and pod
|
2020-07-19 12:21:03 +00:00
|
|
|
// if name is not empty same will be set as pvc and app name.
|
2020-03-27 18:21:18 +00:00
|
|
|
func createPVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod, pvcTimeout int) error {
|
2019-06-18 07:07:11 +00:00
|
|
|
if name != "" {
|
|
|
|
pvc.Name = name
|
|
|
|
app.Name = name
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = name
|
|
|
|
}
|
2020-03-27 18:21:18 +00:00
|
|
|
err := createPVCAndvalidatePV(f.ClientSet, pvc, pvcTimeout)
|
2019-06-18 07:07:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// deletePVCAndApp delete pvc and pod
|
2020-07-19 12:21:03 +00:00
|
|
|
// if name is not empty same will be set as pvc and app name.
|
2019-06-18 07:07:11 +00:00
|
|
|
func deletePVCAndApp(name string, f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error {
|
|
|
|
if name != "" {
|
|
|
|
pvc.Name = name
|
|
|
|
app.Name = name
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = name
|
|
|
|
}
|
|
|
|
|
|
|
|
err := deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func createPVCAndAppBinding(pvcPath, appPath string, f *framework.Framework, pvcTimeout int) (*v1.PersistentVolumeClaim, *v1.Pod, error) {
|
2019-06-14 09:26:17 +00:00
|
|
|
pvc, err := loadPVC(pvcPath)
|
2020-10-20 09:55:09 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return nil, nil, err
|
2019-06-14 09:26:17 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
2019-06-14 09:26:17 +00:00
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return nil, nil, err
|
2019-06-14 09:26:17 +00:00
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
|
2020-03-27 18:21:18 +00:00
|
|
|
err = createPVCAndApp("", f, pvc, app, pvcTimeout)
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return nil, nil, err
|
2019-12-13 11:41:32 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
return pvc, app, nil
|
2020-03-27 18:21:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func validatePVCAndAppBinding(pvcPath, appPath string, f *framework.Framework) error {
|
|
|
|
pvc, app, err := createPVCAndAppBinding(pvcPath, appPath, f, deployTimeout)
|
2019-12-13 11:41:32 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2019-12-13 11:41:32 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
return err
|
2019-12-13 11:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getMountType(appName, appNamespace, mountPath string, f *framework.Framework) (string, error) {
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
FieldSelector: fields.OneTermEqualSelector("metadata.name", appName).String(),
|
|
|
|
}
|
|
|
|
cmd := fmt.Sprintf("lsblk -o TYPE,MOUNTPOINT | grep '%s' | awk '{print $1}'", mountPath)
|
2020-09-03 09:34:29 +00:00
|
|
|
stdOut, stdErr, err := execCommandInPod(f, cmd, appNamespace, &opt)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2019-12-13 11:41:32 +00:00
|
|
|
if stdErr != "" {
|
|
|
|
return strings.TrimSpace(stdOut), fmt.Errorf(stdErr)
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(stdOut), nil
|
|
|
|
}
|
|
|
|
|
2020-01-29 11:44:45 +00:00
|
|
|
// readVaultSecret method will execute few commands to try read the secret for
|
|
|
|
// specified key from inside the vault container:
|
|
|
|
// * authenticate with vault and ignore any stdout (we do not need output)
|
|
|
|
// * issue get request for particular key
|
|
|
|
// resulting in stdOut (first entry in tuple) - output that contains the key
|
2020-07-19 12:21:03 +00:00
|
|
|
// or stdErr (second entry in tuple) - error getting the key.
|
2021-03-23 07:56:35 +00:00
|
|
|
func readVaultSecret(key string, usePassphrasePath bool, f *framework.Framework) (string, string) {
|
|
|
|
extraPath := vaultPassphrasePath
|
|
|
|
if !usePassphrasePath {
|
|
|
|
extraPath = ""
|
|
|
|
}
|
|
|
|
|
2020-01-29 11:44:45 +00:00
|
|
|
loginCmd := fmt.Sprintf("vault login -address=%s sample_root_token_id > /dev/null", vaultAddr)
|
2021-03-23 07:56:35 +00:00
|
|
|
readSecret := fmt.Sprintf("vault kv get -address=%s -field=data %s%s%s",
|
|
|
|
vaultAddr, vaultBackendPath, extraPath, key)
|
2020-01-29 11:44:45 +00:00
|
|
|
cmd := fmt.Sprintf("%s && %s", loginCmd, readSecret)
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=vault",
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
stdOut, stdErr := execCommandInPodAndAllowFail(f, cmd, cephCSINamespace, &opt)
|
2020-01-29 11:44:45 +00:00
|
|
|
return strings.TrimSpace(stdOut), strings.TrimSpace(stdErr)
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
func validateNormalUserPVCAccess(pvcPath string, f *framework.Framework) error {
|
2019-06-14 09:26:17 +00:00
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2019-06-14 09:26:17 +00:00
|
|
|
}
|
2019-06-11 12:40:31 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
pvc.Name = f.UniqueName
|
2019-06-14 09:26:17 +00:00
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
2019-06-11 12:40:31 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2019-06-11 12:40:31 +00:00
|
|
|
}
|
|
|
|
var user int64 = 2000
|
|
|
|
app := &v1.Pod{
|
|
|
|
TypeMeta: metav1.TypeMeta{
|
|
|
|
Kind: "Pod",
|
|
|
|
APIVersion: "v1",
|
|
|
|
},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "pod-run-as-non-root",
|
|
|
|
Namespace: f.UniqueName,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"app": "pod-run-as-non-root",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
|
|
|
{
|
|
|
|
Name: "write-pod",
|
2020-11-19 09:19:59 +00:00
|
|
|
Image: "registry.centos.org/centos:latest",
|
2019-06-11 12:40:31 +00:00
|
|
|
Command: []string{"/bin/sleep", "999999"},
|
|
|
|
SecurityContext: &v1.SecurityContext{
|
|
|
|
RunAsUser: &user,
|
|
|
|
},
|
|
|
|
VolumeMounts: []v1.VolumeMount{
|
|
|
|
{
|
|
|
|
MountPath: "/target",
|
|
|
|
Name: "target",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Volumes: []v1.Volume{
|
|
|
|
{
|
|
|
|
Name: "target",
|
|
|
|
VolumeSource: v1.VolumeSource{
|
|
|
|
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
|
|
|
ClaimName: pvc.Name,
|
|
|
|
ReadOnly: false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2019-06-11 12:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=pod-run-as-non-root",
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
_, stdErr, err := execCommandInPod(f, "echo testing > /target/testing", app.Namespace, &opt)
|
2019-06-11 12:40:31 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return nil
|
2019-06-11 12:40:31 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
if stdErr != "" {
|
|
|
|
return fmt.Errorf("failed to touch a file as non-root user %v", stdErr)
|
2019-06-11 12:40:31 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
2020-01-23 01:47:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
return err
|
2019-06-18 07:07:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-03 16:55:44 +00:00
|
|
|
// writeDataInPod fill zero content to a file in the provided POD volume.
|
2020-10-13 05:34:55 +00:00
|
|
|
func writeDataInPod(app *v1.Pod, opt *metav1.ListOptions, f *framework.Framework) error {
|
2020-08-03 16:55:44 +00:00
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
err := createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-13 05:34:55 +00:00
|
|
|
|
2020-08-03 16:55:44 +00:00
|
|
|
// write data to PVC. The idea here is to fill some content in the file
|
|
|
|
// instead of filling and reverifying the md5sum/data integrity
|
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
// While writing more data we are encountering issues in E2E timeout, so keeping it low for now
|
2020-10-13 05:34:55 +00:00
|
|
|
_, writeErr, err := execCommandInPod(f, fmt.Sprintf("dd if=/dev/zero of=%s bs=1M count=10 status=none", filePath), app.Namespace, opt)
|
2020-08-05 07:35:56 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if writeErr != "" {
|
|
|
|
err = fmt.Errorf("failed to write data %v", writeErr)
|
2020-08-05 07:35:56 +00:00
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
|
|
|
|
return err
|
2020-08-05 07:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
func checkDataPersist(pvcPath, appPath string, f *framework.Framework) error {
|
|
|
|
data := "checking data persist"
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
2020-10-20 09:55:09 +00:00
|
|
|
if err != nil {
|
2019-07-03 10:02:36 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-11-25 11:09:24 +00:00
|
|
|
|
2019-07-03 10:02:36 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
app.Labels = map[string]string{"app": "validate-data"}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
|
2020-03-27 18:21:18 +00:00
|
|
|
err = createPVCAndApp("", f, pvc, app, deployTimeout)
|
2019-07-03 10:02:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=validate-data",
|
|
|
|
}
|
|
|
|
// write data to PVC
|
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
_, stdErr, err := execCommandInPod(f, fmt.Sprintf("echo %s > %s", data, filePath), app.Namespace, &opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if stdErr != "" {
|
|
|
|
return fmt.Errorf("failed to write data to a file %v", stdErr)
|
|
|
|
}
|
2019-07-03 10:02:36 +00:00
|
|
|
// delete app
|
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// recreate app and check data persist
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
persistData, stdErr, err := execCommandInPod(f, fmt.Sprintf("cat %s", filePath), app.Namespace, &opt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if stdErr != "" {
|
|
|
|
return fmt.Errorf("failed to get file content %v", stdErr)
|
|
|
|
}
|
2019-07-03 10:02:36 +00:00
|
|
|
if !strings.Contains(persistData, data) {
|
|
|
|
return fmt.Errorf("data not persistent expected data %s received data %s ", data, persistData)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
return err
|
|
|
|
}
|
2020-01-31 08:49:11 +00:00
|
|
|
|
|
|
|
func pvcDeleteWhenPoolNotFound(pvcPath string, cephfs bool, f *framework.Framework) error {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if cephfs {
|
|
|
|
err = deleteBackingCephFSVolume(f, pvc)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// delete cephfs filesystem
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePool("myfs", cephfs, f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-31 08:49:11 +00:00
|
|
|
} else {
|
|
|
|
err = deleteBackingRBDImage(f, pvc)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// delete rbd pool
|
2020-09-03 09:34:29 +00:00
|
|
|
err = deletePool(defaultRBDPool, cephfs, f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-31 08:49:11 +00:00
|
|
|
}
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
return err
|
|
|
|
}
|
2020-03-02 08:31:44 +00:00
|
|
|
|
|
|
|
func checkMountOptions(pvcPath, appPath string, f *framework.Framework, mountFlags []string) error {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
2020-10-20 09:55:09 +00:00
|
|
|
if err != nil {
|
2020-03-02 08:31:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
app.Labels = map[string]string{"app": "validate-mount-opt"}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
|
2020-03-27 18:21:18 +00:00
|
|
|
err = createPVCAndApp("", f, pvc, app, deployTimeout)
|
2020-03-02 08:31:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=validate-mount-opt",
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := fmt.Sprintf("mount |grep %s", app.Spec.Containers[0].VolumeMounts[0].MountPath)
|
2020-09-03 09:34:29 +00:00
|
|
|
data, stdErr, err := execCommandInPod(f, cmd, app.Namespace, &opt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if stdErr != "" {
|
|
|
|
return fmt.Errorf("failed to get mount point %v", stdErr)
|
|
|
|
}
|
2020-03-02 08:31:44 +00:00
|
|
|
for _, f := range mountFlags {
|
|
|
|
if !strings.Contains(data, f) {
|
|
|
|
return fmt.Errorf("mount option %s not found in %s", f, data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
return err
|
|
|
|
}
|
2020-03-27 18:21:18 +00:00
|
|
|
|
|
|
|
func addTopologyDomainsToDSYaml(template, labels string) string {
|
|
|
|
return strings.ReplaceAll(template, "# - \"--domainlabels=failure-domain/region,failure-domain/zone\"",
|
|
|
|
"- \"--domainlabels="+labels+"\"")
|
|
|
|
}
|
2020-09-20 00:43:26 +00:00
|
|
|
|
|
|
|
func oneReplicaDeployYaml(template string) string {
|
|
|
|
var re = regexp.MustCompile(`(\s+replicas:) \d+`)
|
|
|
|
return re.ReplaceAllString(template, `$1 1`)
|
|
|
|
}
|
2020-10-15 13:53:55 +00:00
|
|
|
|
2020-12-08 10:42:31 +00:00
|
|
|
func enableTopologyInTemplate(data string) string {
|
|
|
|
return strings.ReplaceAll(data, "--feature-gates=Topology=false", "--feature-gates=Topology=true")
|
|
|
|
}
|
|
|
|
|
2020-10-13 05:34:55 +00:00
|
|
|
func writeDataAndCalChecksum(app *v1.Pod, opt *metav1.ListOptions, f *framework.Framework) (string, error) {
|
|
|
|
filePath := app.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
// write data in PVC
|
|
|
|
err := writeDataInPod(app, opt, f)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to write data in the pod with error %v", err)
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSum, err := calculateSHA512sum(f, app, filePath, opt)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to calculate checksum with error %v", err)
|
|
|
|
return checkSum, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to delete pod with error %v", err)
|
|
|
|
}
|
|
|
|
return checkSum, nil
|
|
|
|
}
|
|
|
|
|
2021-03-12 15:42:31 +00:00
|
|
|
// nolint:gocyclo,gocognit // reduce complexity
|
2021-04-09 08:58:59 +00:00
|
|
|
func validatePVCClone(totalCount int, sourcePvcPath, sourceAppPath, clonePvcPath, clonePvcAppPath string, validateEncryption bool, f *framework.Framework) {
|
2020-10-15 13:53:55 +00:00
|
|
|
var wg sync.WaitGroup
|
2020-11-04 14:45:06 +00:00
|
|
|
wgErrs := make([]error, totalCount)
|
2020-10-13 05:34:55 +00:00
|
|
|
chErrs := make([]error, totalCount)
|
2020-10-15 13:53:55 +00:00
|
|
|
pvc, err := loadPVC(sourcePvcPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
|
2020-10-13 05:34:55 +00:00
|
|
|
label := make(map[string]string)
|
2020-10-15 13:53:55 +00:00
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to create PVC with error %v", err)
|
|
|
|
}
|
2020-10-13 05:34:55 +00:00
|
|
|
app, err := loadApp(sourceAppPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load app with error %v", err)
|
|
|
|
}
|
|
|
|
label[appKey] = appLabel
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
app.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSum := ""
|
|
|
|
pvc, err = f.ClientSet.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to get pvc %v", err)
|
|
|
|
}
|
|
|
|
if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem {
|
|
|
|
checkSum, err = writeDataAndCalChecksum(app, &opt, f)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to calculate checksum with error %v", err)
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 13:53:55 +00:00
|
|
|
// validate created backend rbd images
|
|
|
|
validateRBDImageCount(f, 1)
|
|
|
|
pvcClone, err := loadPVC(clonePvcPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
pvcClone.Spec.DataSource.Name = pvc.Name
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone, err := loadApp(clonePvcAppPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load application with error %v", err)
|
|
|
|
}
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// create clone and bind it to an app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
2020-10-13 05:34:55 +00:00
|
|
|
label := make(map[string]string)
|
|
|
|
label[appKey] = name
|
|
|
|
a.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
2020-11-04 14:45:06 +00:00
|
|
|
wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout)
|
2020-10-13 05:34:55 +00:00
|
|
|
if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem && wgErrs[n] == nil {
|
|
|
|
filePath := a.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
checkSumClone := ""
|
|
|
|
e2elog.Logf("Calculating checksum clone for filepath %s", filePath)
|
|
|
|
checkSumClone, chErrs[n] = calculateSHA512sum(f, &a, filePath, &opt)
|
|
|
|
e2elog.Logf("checksum for clone is %s", checkSumClone)
|
|
|
|
if chErrs[n] != nil {
|
|
|
|
e2elog.Logf("Failed calculating checksum clone %s", chErrs[n])
|
|
|
|
}
|
|
|
|
if checkSumClone != checkSum {
|
|
|
|
e2elog.Logf("checksum didn't match. checksum=%s and checksumclone=%s", checkSum, checkSumClone)
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 15:42:31 +00:00
|
|
|
if wgErrs[n] == nil && validateEncryption {
|
|
|
|
wgErrs[n] = validateEncryptedPVC(f, &p, &a)
|
|
|
|
}
|
2020-10-15 13:53:55 +00:00
|
|
|
w.Done()
|
|
|
|
}(&wg, i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2020-11-04 14:45:06 +00:00
|
|
|
failed := 0
|
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
|
|
|
e2elog.Logf("failed to create PVC (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("creating PVCs failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
2020-10-13 05:34:55 +00:00
|
|
|
for i, err := range chErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
|
|
|
e2elog.Logf("failed to calculate checksum (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("calculating checksum failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
2020-10-15 13:53:55 +00:00
|
|
|
// total images in cluster is 1 parent rbd image+ total
|
|
|
|
// temporary clone+ total clones
|
|
|
|
totalCloneCount := totalCount + totalCount + 1
|
|
|
|
validateRBDImageCount(f, totalCloneCount)
|
|
|
|
// delete parent pvc
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to delete PVC with error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
totalCloneCount = totalCount + totalCount
|
|
|
|
validateRBDImageCount(f, totalCloneCount)
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
p.Spec.DataSource.Name = name
|
2020-11-04 14:45:06 +00:00
|
|
|
wgErrs[n] = deletePVCAndApp(name, f, &p, &a)
|
2020-10-15 13:53:55 +00:00
|
|
|
w.Done()
|
|
|
|
}(&wg, i, *pvcClone, *appClone)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-11-04 14:45:06 +00:00
|
|
|
|
|
|
|
for i, err := range wgErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
|
|
|
e2elog.Logf("failed to delete PVC and application (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("deleting PVCs and applications failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
2020-10-15 13:53:55 +00:00
|
|
|
validateRBDImageCount(f, 0)
|
|
|
|
}
|
2020-10-14 07:35:58 +00:00
|
|
|
|
2021-04-08 15:46:11 +00:00
|
|
|
// nolint:gocyclo,gocognit // reduce complexity
|
2021-04-09 08:58:59 +00:00
|
|
|
func validatePVCSnapshot(totalCount int, pvcPath, appPath, snapshotPath, pvcClonePath, appClonePath string, validateEncryption bool, f *framework.Framework) {
|
2021-04-08 15:46:11 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
wgErrs := make([]error, totalCount)
|
|
|
|
chErrs := make([]error, totalCount)
|
|
|
|
wg.Add(totalCount)
|
|
|
|
|
|
|
|
err := createRBDSnapshotClass(f)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to create storageclass with error %v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = deleteRBDSnapshotClass()
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to delete VolumeSnapshotClass: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
label := make(map[string]string)
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to create PVC with error %v", err)
|
|
|
|
}
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load app with error %v", err)
|
|
|
|
}
|
|
|
|
// write data in PVC
|
|
|
|
label[appKey] = appLabel
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
app.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvc.Name
|
|
|
|
checkSum, err := writeDataAndCalChecksum(app, &opt, f)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to calculate checksum with error %v", err)
|
|
|
|
}
|
|
|
|
validateRBDImageCount(f, 1)
|
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
// create snapshot
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, n int, s v1beta1.VolumeSnapshot) {
|
|
|
|
s.Name = fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = createSnapshot(&s, deployTimeout)
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to create snapshot (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("creating snapshots failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// total images in cluster is 1 parent rbd image+ total snaps
|
|
|
|
validateRBDImageCount(f, totalCount+1)
|
|
|
|
pvcClone, err := loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
appClone, err := loadApp(appClonePath)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to load application with error %v", err)
|
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.DataSource.Name = fmt.Sprintf("%s%d", f.UniqueName, 0)
|
|
|
|
|
|
|
|
// create multiple PVC from same snapshot
|
|
|
|
wg.Add(totalCount)
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, n int, p v1.PersistentVolumeClaim, a v1.Pod) {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
label := make(map[string]string)
|
|
|
|
label[appKey] = name
|
|
|
|
a.Labels = label
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
wgErrs[n] = createPVCAndApp(name, f, &p, &a, deployTimeout)
|
|
|
|
if wgErrs[n] == nil {
|
|
|
|
filePath := a.Spec.Containers[0].VolumeMounts[0].MountPath + "/test"
|
|
|
|
checkSumClone := ""
|
|
|
|
e2elog.Logf("calculating checksum clone for filepath %s", filePath)
|
|
|
|
checkSumClone, chErrs[n] = calculateSHA512sum(f, &a, filePath, &opt)
|
|
|
|
e2elog.Logf("checksum value for the clone is %s with pod name %s", checkSumClone, name)
|
|
|
|
if chErrs[n] != nil {
|
|
|
|
e2elog.Logf("failed to calculte checksum for clone with error %s", chErrs[n])
|
|
|
|
}
|
|
|
|
if checkSumClone != checkSum {
|
|
|
|
e2elog.Logf("checksum value didn't match. checksum=%s and checksumclone=%s", checkSum, checkSumClone)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if wgErrs[n] == nil && validateEncryption {
|
|
|
|
wgErrs[n] = validateEncryptedPVC(f, &p, &a)
|
|
|
|
}
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to create PVC and application (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("creating PVCs and applications failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, err := range chErrs {
|
|
|
|
if err != nil {
|
|
|
|
// not using Failf() as it aborts the test and does not log other errors
|
|
|
|
e2elog.Logf("failed to calculate checksum (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("calculating checksum failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
// total images in cluster is 1 parent rbd image+ total
|
|
|
|
// snaps+ total clones
|
|
|
|
totalCloneCount := totalCount + totalCount + 1
|
|
|
|
validateRBDImageCount(f, totalCloneCount)
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, 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)
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to delete PVC and application (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("deleting PVCs and applications failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// total images in cluster is 1 parent rbd image+ total
|
|
|
|
// snaps
|
|
|
|
validateRBDImageCount(f, totalCount+1)
|
|
|
|
// create clones from different snapshots and bind it to an
|
|
|
|
// app
|
|
|
|
wg.Add(totalCount)
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, 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)
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to create PVC and application (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("creating PVCs and applications failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// total images in cluster is 1 parent rbd image+ total
|
|
|
|
// snaps+ total clones
|
|
|
|
totalCloneCount = totalCount + totalCount + 1
|
|
|
|
validateRBDImageCount(f, totalCloneCount)
|
|
|
|
// delete parent pvc
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to delete PVC with error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// total images in cluster is total snaps+ total clones
|
|
|
|
totalSnapCount := totalCount + totalCount
|
|
|
|
validateRBDImageCount(f, totalSnapCount)
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete snapshot
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, n int, s v1beta1.VolumeSnapshot) {
|
|
|
|
s.Name = fmt.Sprintf("%s%d", f.UniqueName, n)
|
|
|
|
wgErrs[n] = deleteSnapshot(&s, deployTimeout)
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to delete snapshot (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("deleting snapshots failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
validateRBDImageCount(f, totalCount)
|
|
|
|
wg.Add(totalCount)
|
|
|
|
// delete clone and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
go func(w *sync.WaitGroup, 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)
|
|
|
|
w.Done()
|
|
|
|
}(&wg, 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
|
|
|
|
e2elog.Logf("failed to delete PVC and application (%s%d): %v", f.UniqueName, i, err)
|
|
|
|
failed++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed != 0 {
|
|
|
|
e2elog.Failf("deleting PVCs and applications failed, %d errors were logged", failed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate created backend rbd images
|
|
|
|
validateRBDImageCount(f, 0)
|
|
|
|
}
|
|
|
|
|
2020-10-28 07:43:52 +00:00
|
|
|
// validateController simulates the required operations to validate the
|
|
|
|
// controller.
|
|
|
|
// Controller will generates the omap data when the PV is created.
|
|
|
|
// for that we need to do below operations
|
|
|
|
// Create PVC with Retain policy
|
|
|
|
// Store the PVC and PV kubernetes objects so that we can create static
|
|
|
|
// binding between PVC-PV
|
|
|
|
// Delete the omap data created for PVC
|
|
|
|
// Create the static PVC and PV and let controller regenerate the omap
|
|
|
|
// Mount the PVC to application (NodeStage/NodePublish should work)
|
|
|
|
// Resize the PVC
|
|
|
|
// Delete the Application and PVC.
|
|
|
|
func validateController(f *framework.Framework, pvcPath, appPath, scPath string) error {
|
|
|
|
size := "1Gi"
|
|
|
|
poolName := defaultRBDPool
|
|
|
|
expandSize := "10Gi"
|
|
|
|
var err error
|
|
|
|
// create storageclass with retain
|
|
|
|
err = createRBDStorageClass(f.ClientSet, f, nil, nil, retainPolicy)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create storageclass with error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// create pvc
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
resizePvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to load PVC with error %v", err)
|
|
|
|
}
|
|
|
|
resizePvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
pvc.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(size)
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create PVC with error %v", err)
|
|
|
|
}
|
|
|
|
// get pvc and pv object
|
|
|
|
pvc, pv, err := getPVCAndPV(f.ClientSet, pvc.Name, pvc.Namespace)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to get PVC with error %v", err)
|
|
|
|
}
|
|
|
|
// Recreate storageclass with delete policy
|
|
|
|
err = deleteResource(scPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to delete storageclass with error %v", err)
|
|
|
|
}
|
|
|
|
err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to create storageclass with error %v", err)
|
|
|
|
}
|
|
|
|
// delete omap data
|
|
|
|
err = deletePVCImageJournalInPool(f, pvc, poolName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = deletePVCCSIJournalInPool(f, pvc, poolName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// delete pvc and pv
|
|
|
|
err = deletePVCAndPV(f.ClientSet, pvc, pv, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to delete PVC or PV with error %v", err)
|
|
|
|
}
|
|
|
|
// create pvc and pv with application
|
|
|
|
pv.Spec.ClaimRef = nil
|
|
|
|
pv.Spec.PersistentVolumeReclaimPolicy = deletePolicy
|
|
|
|
// unset the resource version as should not be set on objects to be created
|
|
|
|
pvc.ResourceVersion = ""
|
|
|
|
pv.ResourceVersion = ""
|
|
|
|
err = createPVCAndPV(f.ClientSet, pvc, pv)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to create PVC or PV with error %v", err)
|
|
|
|
}
|
|
|
|
// bind PVC to application
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
app.Labels = map[string]string{"app": "resize-pvc"}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=resize-pvc",
|
|
|
|
}
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// resize PVC
|
|
|
|
err = expandPVCSize(f.ClientSet, resizePvc, expandSize, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem {
|
|
|
|
err = checkDirSize(app, f, &opt, expandSize)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if *pvc.Spec.VolumeMode == v1.PersistentVolumeBlock {
|
|
|
|
err = checkDeviceSize(app, f, &opt, expandSize)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete pvc and storageclass
|
|
|
|
err = deletePVCAndApp("", f, resizePvc, app)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return deleteResource(rbdExamplePath + "storageclass.yaml")
|
|
|
|
}
|
|
|
|
|
2020-10-14 07:35:58 +00:00
|
|
|
// k8sVersionGreaterEquals checks the ServerVersion of the Kubernetes cluster
|
|
|
|
// and compares it to the major.minor version passed. In case the version of
|
|
|
|
// the cluster is equal or higher to major.minor, `true` is returned, `false`
|
|
|
|
// otherwise.
|
|
|
|
//
|
|
|
|
// If fetching the ServerVersion of the Kubernetes cluster fails, the calling
|
|
|
|
// test case is marked as `FAILED` and gets aborted.
|
|
|
|
//
|
|
|
|
// nolint:unparam // currently major is always 1, this can change in the future
|
|
|
|
func k8sVersionGreaterEquals(c kubernetes.Interface, major, minor int) bool {
|
|
|
|
v, err := c.Discovery().ServerVersion()
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to get server version with error %v", err)
|
|
|
|
// Failf() marks the case as failure, and returns from the
|
|
|
|
// Go-routine that runs the case. This function will not have a
|
|
|
|
// return value.
|
|
|
|
}
|
|
|
|
|
|
|
|
maj := fmt.Sprintf("%d", major)
|
|
|
|
min := fmt.Sprintf("%d", minor)
|
|
|
|
|
|
|
|
return (v.Major > maj) || (v.Major == maj && v.Minor >= min)
|
|
|
|
}
|