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"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
scv1 "k8s.io/api/storage/v1"
|
|
|
|
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 (
|
2020-02-25 11:45:54 +00:00
|
|
|
defaultNs = "default"
|
2020-07-20 12:49:05 +00:00
|
|
|
vaultSecretNs = "/secret/ceph-csi/"
|
2020-04-07 08:35:05 +00:00
|
|
|
|
|
|
|
// rook created cephfs user
|
2020-07-20 12:49:05 +00:00
|
|
|
cephfsNodePluginSecretName = "rook-csi-cephfs-node"
|
|
|
|
cephfsProvisionerSecretName = "rook-csi-cephfs-provisioner"
|
2020-04-07 08:35:05 +00:00
|
|
|
|
|
|
|
// rook created rbd user
|
2020-07-20 12:49:05 +00:00
|
|
|
rbdNodePluginSecretName = "rook-csi-rbd-node"
|
|
|
|
rbdProvisionerSecretName = "rook-csi-rbd-provisioner"
|
2020-05-15 08:49:38 +00:00
|
|
|
|
|
|
|
rookTolBoxPodLabel = "app=rook-ceph-tools"
|
2020-05-18 13:07:17 +00:00
|
|
|
rbdmountOptions = "mountOptions"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// updateSecretForEncryption is an hack to update the secrets created by rook to
|
|
|
|
// include the encyption key
|
2020-07-19 12:21:03 +00:00
|
|
|
// TODO in cephcsi we need to create own users in ceph cluster and use it for E2E.
|
2020-04-09 05:48:09 +00:00
|
|
|
func updateSecretForEncryption(c kubernetes.Interface) error {
|
2020-04-14 06:59:04 +00:00
|
|
|
secrets, err := c.CoreV1().Secrets(rookNamespace).Get(context.TODO(), rbdProvisionerSecretName, metav1.GetOptions{})
|
2020-04-09 05:48:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
secrets.Data["encryptionPassphrase"] = []byte("test_passphrase")
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = c.CoreV1().Secrets(rookNamespace).Update(context.TODO(), secrets, metav1.UpdateOptions{})
|
2020-04-09 05:48:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
secrets, err = c.CoreV1().Secrets(rookNamespace).Get(context.TODO(), rbdNodePluginSecretName, metav1.GetOptions{})
|
2020-04-09 05:48:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
secrets.Data["encryptionPassphrase"] = []byte("test_passphrase")
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = c.CoreV1().Secrets(rookNamespace).Update(context.TODO(), secrets, metav1.UpdateOptions{})
|
2020-04-09 05:48:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2019-05-31 09:34:04 +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)
|
|
|
|
if pvc == 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.
|
2020-01-29 11:44:45 +00:00
|
|
|
func readVaultSecret(key string, f *framework.Framework) (string, string) {
|
|
|
|
loginCmd := fmt.Sprintf("vault login -address=%s sample_root_token_id > /dev/null", vaultAddr)
|
|
|
|
readSecret := fmt.Sprintf("vault kv get -address=%s %s%s", vaultAddr, vaultSecretNs, key)
|
|
|
|
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",
|
|
|
|
Image: "alpine",
|
|
|
|
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.
|
|
|
|
func writeDataInPod(app *v1.Pod, f *framework.Framework) error {
|
|
|
|
app.Labels = map[string]string{"app": "write-data-in-pod"}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
err := createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=write-data-in-pod",
|
|
|
|
}
|
|
|
|
// 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-09-03 09:34:29 +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)
|
|
|
|
if pvc == nil {
|
|
|
|
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)
|
|
|
|
if pvc == nil {
|
|
|
|
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+"\"")
|
|
|
|
}
|