mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 22:44:21 +00:00
Replace pod with deployment in E2E test
Signed-off-by: danfengl <danfengl@vmware.com>
This commit is contained in:
@@ -129,7 +129,7 @@ func GetCsiSnapshotHandleV1(client TestClient, backupName string) ([]string, err
|
||||
return snapshotHandleList, nil
|
||||
}
|
||||
func GetVolumeSnapshotContentNameByPod(client TestClient, podName, namespace, backupName string) (string, error) {
|
||||
pvcList, err := GetPvcByPodName(context.Background(), namespace, podName)
|
||||
pvcList, err := GetPvcByPVCName(context.Background(), namespace, podName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
+22
-6
@@ -81,7 +81,7 @@ func WaitForPods(ctx context.Context, client TestClient, namespace string, pods
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetPvcByPodName(ctx context.Context, namespace, podName string) ([]string, error) {
|
||||
func GetPvcByPVCName(ctx context.Context, namespace, pvcName string) ([]string, error) {
|
||||
// Example:
|
||||
// NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
|
||||
// kibishii-data-kibishii-deployment-0 Bound pvc-94b9fdf2-c30f-4a7b-87bf-06eadca0d5b6 1Gi RWO kibishii-storage-class 115s
|
||||
@@ -94,7 +94,7 @@ func GetPvcByPodName(ctx context.Context, namespace, podName string) ([]string,
|
||||
|
||||
cmd = &common.OsCommandLine{
|
||||
Cmd: "grep",
|
||||
Args: []string{podName},
|
||||
Args: []string{pvcName},
|
||||
}
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
@@ -233,20 +233,20 @@ func GetAPIVersions(client *TestClient, name string) ([]string, error) {
|
||||
return nil, errors.New("Server API groups is empty")
|
||||
}
|
||||
|
||||
func GetPVByPodName(client TestClient, namespace, podName string) (string, error) {
|
||||
pvcList, err := GetPvcByPodName(context.Background(), namespace, podName)
|
||||
func GetPVByPVCName(client TestClient, namespace, pvcName string) (string, error) {
|
||||
pvcList, err := GetPvcByPVCName(context.Background(), namespace, pvcName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(pvcList) != 1 {
|
||||
return "", errors.New(fmt.Sprintf("Only 1 PVC of pod %s should be found under namespace %s but got %v", podName, namespace, pvcList))
|
||||
return "", errors.New(fmt.Sprintf("Only 1 PVC of pod %s should be found under namespace %s but got %v", pvcName, namespace, pvcList))
|
||||
}
|
||||
pvList, err := GetPvByPvc(context.Background(), namespace, pvcList[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(pvList) != 1 {
|
||||
return "", errors.New(fmt.Sprintf("Only 1 PV of PVC %s pod %s should be found under namespace %s", pvcList[0], podName, namespace))
|
||||
return "", errors.New(fmt.Sprintf("Only 1 PV of PVC %s pod %s should be found under namespace %s", pvcList[0], pvcName, namespace))
|
||||
}
|
||||
pv_value, err := GetPersistentVolume(context.Background(), client, "", pvList[0])
|
||||
fmt.Println(pv_value.Annotations["pv.kubernetes.io/provisioned-by"])
|
||||
@@ -347,3 +347,19 @@ func GetAllService(ctx context.Context) (string, error) {
|
||||
}
|
||||
return stdout, nil
|
||||
}
|
||||
|
||||
func CreateVolumes(pvcName string, volumeNameList []string) (vols []*corev1.Volume) {
|
||||
vols = []*corev1.Volume{}
|
||||
for _, volume := range volumeNameList {
|
||||
vols = append(vols, &corev1.Volume{
|
||||
Name: volume,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: pvcName,
|
||||
ReadOnly: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -105,19 +105,19 @@ func NewDeployment(name, ns string, replicas int32, labels map[string]string, co
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DeploymentBuilder) WithVolume(vols []*v1.Volume) *DeploymentBuilder {
|
||||
func (d *DeploymentBuilder) WithVolume(volumes []*v1.Volume) *DeploymentBuilder {
|
||||
vmList := []v1.VolumeMount{}
|
||||
for i, v := range vols {
|
||||
for _, v := range volumes {
|
||||
vmList = append(vmList, v1.VolumeMount{
|
||||
Name: v.Name,
|
||||
MountPath: "/" + v.Name,
|
||||
})
|
||||
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, *vols[i])
|
||||
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, *v)
|
||||
|
||||
}
|
||||
|
||||
// NOTE here just mount volumes to the first container
|
||||
d.Spec.Template.Spec.Containers[0].VolumeMounts = vmList
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user