2021-12-21 14:23:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-01-20 07:11:21 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2020-04-14 06:59:04 +00:00
|
|
|
"context"
|
2020-01-20 07:11:21 +00:00
|
|
|
"fmt"
|
2021-08-02 11:12:05 +00:00
|
|
|
"strconv"
|
2020-01-20 07:11:21 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2021-10-01 04:15:45 +00:00
|
|
|
const (
|
|
|
|
staticPVSize = "4Gi"
|
2021-10-05 10:01:35 +00:00
|
|
|
staticPVNewSize = "8Gi"
|
2021-10-01 04:15:45 +00:00
|
|
|
staticPVImageFeature = "layering"
|
|
|
|
monsPrefix = "mons-"
|
|
|
|
imagePrefix = "image-"
|
|
|
|
migIdentifier = "mig"
|
|
|
|
intreeVolPrefix = "kubernetes-dynamic-pvc-"
|
|
|
|
)
|
|
|
|
|
2021-06-25 13:02:50 +00:00
|
|
|
func getStaticPV(
|
|
|
|
name, volName, size, secretName, secretNS, sc, driverName string,
|
|
|
|
blockPV bool,
|
2022-06-01 10:17:19 +00:00
|
|
|
options, annotations map[string]string, policy v1.PersistentVolumeReclaimPolicy,
|
|
|
|
) *v1.PersistentVolume {
|
2020-01-20 07:11:21 +00:00
|
|
|
pv := &v1.PersistentVolume{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: v1.PersistentVolumeSpec{
|
2021-10-01 04:15:45 +00:00
|
|
|
PersistentVolumeReclaimPolicy: policy,
|
2020-01-20 07:11:21 +00:00
|
|
|
Capacity: v1.ResourceList{
|
|
|
|
v1.ResourceStorage: resource.MustParse(size),
|
|
|
|
},
|
|
|
|
PersistentVolumeSource: v1.PersistentVolumeSource{
|
|
|
|
CSI: &v1.CSIPersistentVolumeSource{
|
|
|
|
Driver: driverName,
|
|
|
|
VolumeHandle: volName,
|
|
|
|
ReadOnly: false,
|
|
|
|
VolumeAttributes: options,
|
|
|
|
NodeStageSecretRef: &v1.SecretReference{
|
|
|
|
Name: secretName,
|
|
|
|
Namespace: secretNS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
StorageClassName: sc,
|
|
|
|
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if blockPV {
|
|
|
|
volumeMode := v1.PersistentVolumeBlock
|
|
|
|
pv.Spec.VolumeMode = &volumeMode
|
|
|
|
} else {
|
|
|
|
volumeMode := v1.PersistentVolumeFilesystem
|
|
|
|
pv.Spec.VolumeMode = &volumeMode
|
|
|
|
}
|
2021-10-01 04:15:45 +00:00
|
|
|
if len(annotations) > 0 {
|
|
|
|
pv.Annotations = make(map[string]string)
|
|
|
|
for k, v := range annotations {
|
|
|
|
pv.Annotations[k] = v
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 07:11:21 +00:00
|
|
|
|
|
|
|
return pv
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStaticPVC(name, pvName, size, ns, sc string, blockPVC bool) *v1.PersistentVolumeClaim {
|
|
|
|
pvc := &v1.PersistentVolumeClaim{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Namespace: ns,
|
|
|
|
},
|
|
|
|
Spec: v1.PersistentVolumeClaimSpec{
|
2023-12-20 18:24:07 +00:00
|
|
|
Resources: v1.VolumeResourceRequirements{
|
2020-01-20 07:11:21 +00:00
|
|
|
Requests: v1.ResourceList{
|
|
|
|
v1.ResourceStorage: resource.MustParse(size),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
|
|
|
|
VolumeName: pvName,
|
|
|
|
StorageClassName: &sc,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if blockPVC {
|
|
|
|
volumeMode := v1.PersistentVolumeBlock
|
|
|
|
pvc.Spec.VolumeMode = &volumeMode
|
|
|
|
} else {
|
|
|
|
volumeMode := v1.PersistentVolumeFilesystem
|
|
|
|
pvc.Spec.VolumeMode = &volumeMode
|
|
|
|
}
|
|
|
|
|
|
|
|
return pvc
|
|
|
|
}
|
|
|
|
|
2021-06-15 10:08:51 +00:00
|
|
|
func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock, checkImgFeat bool) error {
|
2020-01-20 07:11:21 +00:00
|
|
|
opt := make(map[string]string)
|
|
|
|
var (
|
|
|
|
rbdImageName = "test-static-pv"
|
|
|
|
pvName = "pv-name"
|
|
|
|
pvcName = "pvc-name"
|
2020-07-12 13:26:35 +00:00
|
|
|
namespace = f.UniqueName
|
2020-01-20 07:11:21 +00:00
|
|
|
// minikube creates default class in cluster, we need to set dummy
|
2020-11-24 11:54:29 +00:00
|
|
|
// storageclass on PV and PVC to avoid storageclass name mismatch
|
2020-01-20 07:11:21 +00:00
|
|
|
sc = "storage-class"
|
|
|
|
)
|
|
|
|
|
|
|
|
c := f.ClientSet
|
|
|
|
|
2022-04-08 11:08:32 +00:00
|
|
|
fsID, err := getClusterID(f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2022-04-08 11:08:32 +00:00
|
|
|
return fmt.Errorf("failed to get clusterID: %w", err)
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
2022-04-08 11:08:32 +00:00
|
|
|
|
2021-10-01 04:15:45 +00:00
|
|
|
size := staticPVSize
|
2020-01-20 07:11:21 +00:00
|
|
|
// create rbd image
|
2021-06-25 13:02:50 +00:00
|
|
|
cmd := fmt.Sprintf(
|
2021-10-01 04:15:45 +00:00
|
|
|
"rbd create %s --size=%s --image-feature=layering %s",
|
2021-06-25 13:02:50 +00:00
|
|
|
rbdImageName,
|
2021-10-01 04:15:45 +00:00
|
|
|
staticPVSize,
|
2021-06-25 13:02:50 +00:00
|
|
|
rbdOptions(defaultRBDPool))
|
2020-01-20 07:11:21 +00:00
|
|
|
|
2022-04-08 11:08:32 +00:00
|
|
|
_, e, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-20 07:11:21 +00:00
|
|
|
if e != "" {
|
|
|
|
return fmt.Errorf("failed to create rbd image %s", e)
|
|
|
|
}
|
|
|
|
opt["clusterID"] = fsID
|
2021-06-15 10:08:51 +00:00
|
|
|
if !checkImgFeat {
|
2021-10-01 04:15:45 +00:00
|
|
|
opt["imageFeatures"] = staticPVImageFeature
|
2021-06-15 10:08:51 +00:00
|
|
|
}
|
2020-05-05 03:53:24 +00:00
|
|
|
opt["pool"] = defaultRBDPool
|
2021-08-02 11:12:05 +00:00
|
|
|
opt["staticVolume"] = strconv.FormatBool(true)
|
2020-06-02 19:19:57 +00:00
|
|
|
if radosNamespace != "" {
|
|
|
|
opt["radosNamespace"] = radosNamespace
|
|
|
|
}
|
2020-01-20 07:11:21 +00:00
|
|
|
|
2021-06-25 13:02:50 +00:00
|
|
|
pv := getStaticPV(
|
|
|
|
pvName,
|
|
|
|
rbdImageName,
|
|
|
|
size,
|
|
|
|
rbdNodePluginSecretName,
|
|
|
|
cephCSINamespace,
|
|
|
|
sc,
|
|
|
|
"rbd.csi.ceph.com",
|
|
|
|
isBlock,
|
2021-10-01 04:15:45 +00:00
|
|
|
opt,
|
|
|
|
nil, retainPolicy)
|
2020-01-20 07:11:21 +00:00
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
|
2020-01-20 07:11:21 +00:00
|
|
|
if err != nil {
|
2020-07-13 03:56:51 +00:00
|
|
|
return fmt.Errorf("PV Create API error: %w", err)
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 13:26:35 +00:00
|
|
|
pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, isBlock)
|
2020-01-20 07:11:21 +00:00
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
|
2020-01-20 07:11:21 +00:00
|
|
|
if err != nil {
|
2020-07-13 03:56:51 +00:00
|
|
|
return fmt.Errorf("PVC Create API error: %w", err)
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
|
|
|
// bind pvc to app
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-05 10:01:35 +00:00
|
|
|
app.Labels = make(map[string]string)
|
|
|
|
app.Labels[appKey] = appLabel
|
|
|
|
appOpt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, appLabel),
|
|
|
|
}
|
2020-07-12 13:26:35 +00:00
|
|
|
app.Namespace = namespace
|
2020-01-20 07:11:21 +00:00
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
|
2021-06-15 10:08:51 +00:00
|
|
|
if checkImgFeat {
|
|
|
|
err = createAppErr(f.ClientSet, app, deployTimeout, "missing required parameter imageFeatures")
|
|
|
|
} else {
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
}
|
2020-01-20 07:11:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-05 10:01:35 +00:00
|
|
|
// resize image only if the image is already mounted and formatted
|
|
|
|
if !checkImgFeat {
|
|
|
|
err = validateRBDStaticResize(f, app, &appOpt, pvc, rbdImageName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{})
|
2020-01-20 07:11:21 +00:00
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to delete pvc: %w", err)
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{})
|
2021-09-16 13:46:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to delete pv: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = fmt.Sprintf("rbd rm %s %s", rbdImageName, rbdOptions(defaultRBDPool))
|
|
|
|
_, _, err = execCommandInToolBoxPod(f, cmd, rookNamespace)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-19 04:50:27 +00:00
|
|
|
func validateRBDStaticMigrationPVC(f *framework.Framework, appPath, scName string, isBlock bool) error {
|
2021-09-16 13:46:15 +00:00
|
|
|
opt := make(map[string]string)
|
|
|
|
var (
|
2021-11-19 04:50:27 +00:00
|
|
|
rbdImageName = "kubernetes-dynamic-pvc-e0b45b52-7e09-47d3-8f1b-806995fa4412"
|
|
|
|
pvName = "pv-name"
|
|
|
|
pvcName = "pvc-name"
|
|
|
|
namespace = f.UniqueName
|
|
|
|
sc = scName
|
|
|
|
provisionerAnnKey = "pv.kubernetes.io/provisioned-by"
|
|
|
|
provisionerAnnValue = "rbd.csi.ceph.com"
|
2021-09-16 13:46:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
c := f.ClientSet
|
2021-11-19 04:50:27 +00:00
|
|
|
PVAnnMap := make(map[string]string)
|
|
|
|
PVAnnMap[provisionerAnnKey] = provisionerAnnValue
|
2021-09-16 13:46:15 +00:00
|
|
|
mons, err := getMons(rookNamespace, c)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to get mons: %w", err)
|
|
|
|
}
|
|
|
|
mon := strings.Join(mons, ",")
|
2021-10-01 04:15:45 +00:00
|
|
|
size := staticPVSize
|
2021-09-16 13:46:15 +00:00
|
|
|
// create rbd image
|
|
|
|
cmd := fmt.Sprintf(
|
2021-11-19 04:50:27 +00:00
|
|
|
"rbd create %s --size=%s --image-feature=layering %s",
|
2021-09-16 13:46:15 +00:00
|
|
|
rbdImageName,
|
2021-11-19 04:50:27 +00:00
|
|
|
staticPVSize,
|
2021-09-16 13:46:15 +00:00
|
|
|
rbdOptions(defaultRBDPool))
|
|
|
|
|
2021-11-19 04:50:27 +00:00
|
|
|
_, stdErr, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
2021-09-16 13:46:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-19 04:50:27 +00:00
|
|
|
if stdErr != "" {
|
|
|
|
return fmt.Errorf("failed to create rbd image %s", stdErr)
|
2021-10-15 06:44:10 +00:00
|
|
|
}
|
2021-09-16 13:46:15 +00:00
|
|
|
|
|
|
|
opt["migration"] = "true"
|
2021-10-08 08:31:33 +00:00
|
|
|
opt["clusterID"] = getMonsHash(mon)
|
2021-10-01 04:15:45 +00:00
|
|
|
opt["imageFeatures"] = staticPVImageFeature
|
2021-09-16 13:46:15 +00:00
|
|
|
opt["pool"] = defaultRBDPool
|
|
|
|
opt["staticVolume"] = strconv.FormatBool(true)
|
|
|
|
opt["imageName"] = rbdImageName
|
2021-11-19 04:50:27 +00:00
|
|
|
|
|
|
|
// Make volumeID similar to the migration volumeID
|
|
|
|
volID := composeIntreeMigVolID(mon, rbdImageName)
|
2021-09-16 13:46:15 +00:00
|
|
|
pv := getStaticPV(
|
|
|
|
pvName,
|
2021-11-19 04:50:27 +00:00
|
|
|
volID,
|
2021-09-16 13:46:15 +00:00
|
|
|
size,
|
2021-11-19 04:50:27 +00:00
|
|
|
rbdNodePluginSecretName,
|
2021-09-16 13:46:15 +00:00
|
|
|
cephCSINamespace,
|
|
|
|
sc,
|
2021-11-19 04:50:27 +00:00
|
|
|
provisionerAnnValue,
|
2021-09-16 13:46:15 +00:00
|
|
|
isBlock,
|
2021-11-19 04:50:27 +00:00
|
|
|
opt,
|
|
|
|
PVAnnMap,
|
|
|
|
deletePolicy)
|
2021-09-16 13:46:15 +00:00
|
|
|
|
|
|
|
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("PV Create API error: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, isBlock)
|
|
|
|
|
|
|
|
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("PVC Create API error: %w", err)
|
|
|
|
}
|
|
|
|
// bind pvc to app
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Namespace = namespace
|
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-19 04:50:27 +00:00
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
2020-01-20 07:11:21 +00:00
|
|
|
if err != nil {
|
2021-11-19 04:50:27 +00:00
|
|
|
return fmt.Errorf("failed to delete PVC and application: %w", err)
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 09:34:29 +00:00
|
|
|
return err
|
2020-01-20 07:11:21 +00:00
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
|
2023-06-02 08:59:52 +00:00
|
|
|
//nolint:gocyclo,cyclop // reduce complexity
|
2020-05-14 01:48:09 +00:00
|
|
|
func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) error {
|
|
|
|
opt := make(map[string]string)
|
|
|
|
var (
|
|
|
|
cephFsVolName = "testSubVol"
|
|
|
|
groupName = "testGroup"
|
|
|
|
pvName = "pv-name"
|
|
|
|
pvcName = "pvc-name"
|
2020-07-12 13:26:35 +00:00
|
|
|
namespace = f.UniqueName
|
2020-05-14 01:48:09 +00:00
|
|
|
// minikube creates default storage class in cluster, we need to set dummy
|
2020-11-24 11:54:29 +00:00
|
|
|
// storageclass on PV and PVC to avoid storageclass name mismatch
|
2020-05-14 01:48:09 +00:00
|
|
|
sc = "storage-class"
|
|
|
|
secretName = "cephfs-static-pv-sc" // #nosec
|
|
|
|
)
|
|
|
|
|
|
|
|
c := f.ClientSet
|
|
|
|
|
|
|
|
listOpt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=rook-ceph-tools",
|
|
|
|
}
|
|
|
|
|
2022-04-08 11:08:32 +00:00
|
|
|
fsID, err := getClusterID(f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2022-04-08 11:08:32 +00:00
|
|
|
return fmt.Errorf("failed to get clusterID: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4GiB in bytes
|
|
|
|
size := "4294967296"
|
|
|
|
|
|
|
|
// create subvolumegroup, command will work even if group is already present.
|
2022-04-07 15:36:45 +00:00
|
|
|
cmd := fmt.Sprintf("ceph fs subvolumegroup create %s %s", fileSystemName, groupName)
|
2020-05-14 01:48:09 +00:00
|
|
|
|
2022-04-08 11:08:32 +00:00
|
|
|
_, e, err := execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create subvolumegroup: %s", e)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create subvolume
|
2022-04-07 15:36:45 +00:00
|
|
|
cmd = fmt.Sprintf("ceph fs subvolume create %s %s %s --size %s", fileSystemName, cephFsVolName, groupName, size)
|
2020-09-03 09:34:29 +00:00
|
|
|
_, e, err = execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create subvolume: %s", e)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get rootpath
|
2022-04-07 15:36:45 +00:00
|
|
|
cmd = fmt.Sprintf("ceph fs subvolume getpath %s %s %s", fileSystemName, cephFsVolName, groupName)
|
2020-09-03 09:34:29 +00:00
|
|
|
rootPath, e, err := execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
|
|
|
return fmt.Errorf("failed to get rootpath %s", e)
|
|
|
|
}
|
|
|
|
// remove new line present in rootPath
|
|
|
|
rootPath = strings.Trim(rootPath, "\n")
|
|
|
|
|
|
|
|
// create secret
|
2020-09-03 09:34:29 +00:00
|
|
|
secret, err := getSecret(scPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
adminKey, e, err := execCommandInPod(f, "ceph auth get-key client.admin", rookNamespace, &listOpt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
|
|
|
return fmt.Errorf("failed to get adminKey %s", e)
|
|
|
|
}
|
2020-09-03 09:34:29 +00:00
|
|
|
secret.StringData["userID"] = adminUser
|
2020-05-14 01:48:09 +00:00
|
|
|
secret.StringData["userKey"] = adminKey
|
|
|
|
secret.Name = secretName
|
|
|
|
secret.Namespace = cephCSINamespace
|
2020-09-03 09:34:29 +00:00
|
|
|
_, err = c.CoreV1().Secrets(cephCSINamespace).Create(context.TODO(), &secret, metav1.CreateOptions{})
|
2020-05-14 01:48:09 +00:00
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create secret: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opt["clusterID"] = fsID
|
2022-04-07 15:36:45 +00:00
|
|
|
opt["fsName"] = fileSystemName
|
2021-08-02 11:12:05 +00:00
|
|
|
opt["staticVolume"] = strconv.FormatBool(true)
|
2020-05-14 01:48:09 +00:00
|
|
|
opt["rootPath"] = rootPath
|
2021-10-01 04:15:45 +00:00
|
|
|
pv := getStaticPV(
|
|
|
|
pvName,
|
|
|
|
pvName,
|
|
|
|
staticPVSize,
|
|
|
|
secretName,
|
|
|
|
cephCSINamespace,
|
|
|
|
sc,
|
|
|
|
"cephfs.csi.ceph.com",
|
|
|
|
false,
|
|
|
|
opt,
|
|
|
|
nil,
|
|
|
|
retainPolicy)
|
2020-05-14 01:48:09 +00:00
|
|
|
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create PV: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 13:26:35 +00:00
|
|
|
pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, false)
|
2020-05-14 01:48:09 +00:00
|
|
|
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create PVC: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
// bind pvc to app
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to load app: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 13:26:35 +00:00
|
|
|
app.Namespace = namespace
|
2020-05-14 01:48:09 +00:00
|
|
|
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to create pod: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 13:26:35 +00:00
|
|
|
err = deletePod(app.Name, namespace, f.ClientSet, deployTimeout)
|
2020-05-14 01:48:09 +00:00
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to delete pod: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to delete pvc: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to delete pv: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.CoreV1().Secrets(cephCSINamespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
|
|
|
|
if err != nil {
|
2021-05-11 09:28:56 +00:00
|
|
|
return fmt.Errorf("failed to delete secret: %w", err)
|
2020-05-14 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete subvolume
|
2022-04-07 15:36:45 +00:00
|
|
|
cmd = fmt.Sprintf("ceph fs subvolume rm %s %s %s", fileSystemName, cephFsVolName, groupName)
|
2020-09-03 09:34:29 +00:00
|
|
|
_, e, err = execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
|
|
|
return fmt.Errorf("failed to remove sub-volume %s", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete subvolume group
|
2022-04-07 15:36:45 +00:00
|
|
|
cmd = fmt.Sprintf("ceph fs subvolumegroup rm %s %s", fileSystemName, groupName)
|
2020-09-03 09:34:29 +00:00
|
|
|
_, e, err = execCommandInPod(f, cmd, rookNamespace, &listOpt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-14 01:48:09 +00:00
|
|
|
if e != "" {
|
|
|
|
return fmt.Errorf("failed to remove subvolume group %s", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-05 10:01:35 +00:00
|
|
|
|
|
|
|
func validateRBDStaticResize(
|
|
|
|
f *framework.Framework,
|
|
|
|
app *v1.Pod,
|
|
|
|
appOpt *metav1.ListOptions,
|
|
|
|
pvc *v1.PersistentVolumeClaim,
|
2022-06-01 10:17:19 +00:00
|
|
|
rbdImageName string,
|
|
|
|
) error {
|
2021-10-05 10:01:35 +00:00
|
|
|
// resize rbd image
|
|
|
|
size := staticPVNewSize
|
|
|
|
cmd := fmt.Sprintf(
|
|
|
|
"rbd resize %s --size=%s %s",
|
|
|
|
rbdImageName,
|
|
|
|
size,
|
|
|
|
rbdOptions(defaultRBDPool))
|
|
|
|
|
|
|
|
_, _, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// check size for the filesystem type PVC
|
|
|
|
if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem {
|
|
|
|
err = checkDirSize(app, f, appOpt, size)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
}
|