@@ -49,6 +49,17 @@ var waitTimeout = getEnvDuration("WAIT_TIMEOUT", 2*time.Minute)
4949// dataMatchPollInterval is how often we retry the full validate flow when polling for data match.
5050const dataMatchPollInterval = 30 * time .Second
5151
52+ const (
53+ busyboxImage = "busybox"
54+ shCmd = "/bin/sh"
55+ volMountName = "vol"
56+ srcVolName = "src-vol"
57+ dstVolName = "dst-vol"
58+ copyMethodSnapshot = "Snapshot"
59+ copyMethodDirect = "Direct"
60+ copyMethodKey = "copyMethod"
61+ )
62+
5263// innerPollInterval is the poll interval for sub-waits inside tryValidateSyncedData.
5364const innerPollInterval = 5 * time .Second
5465
@@ -520,14 +531,14 @@ func runPodWithPVC(ctx context.Context, podName, pvcName string, drv driverConfi
520531 Containers : []corev1.Container {
521532 {
522533 Name : "worker" ,
523- Image : "busybox" ,
534+ Image : busyboxImage ,
524535 ImagePullPolicy : corev1 .PullAlways ,
525- Command : []string {"/bin/sh" , "-c" , command },
536+ Command : []string {shCmd , "-c" , command },
526537 },
527538 },
528539 Volumes : []corev1.Volume {
529540 {
530- Name : "vol" ,
541+ Name : volMountName ,
531542 VolumeSource : corev1.VolumeSource {
532543 PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
533544 ClaimName : pvcName ,
@@ -543,14 +554,14 @@ func runPodWithPVC(ctx context.Context, podName, pvcName string, drv driverConfi
543554 if isBlock {
544555 pod .Spec .Containers [0 ].VolumeDevices = []corev1.VolumeDevice {
545556 {
546- Name : "vol" ,
557+ Name : volMountName ,
547558 DevicePath : "/dev/block" ,
548559 },
549560 }
550561 } else {
551562 pod .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {
552563 {
553- Name : "vol" ,
564+ Name : volMountName ,
554565 MountPath : "/data" ,
555566 },
556567 }
@@ -638,14 +649,14 @@ func compareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, drv d
638649 Containers : []corev1.Container {
639650 {
640651 Name : "compare" ,
641- Image : "busybox" ,
652+ Image : busyboxImage ,
642653 ImagePullPolicy : corev1 .PullAlways ,
643- Command : []string {"/bin/sh" , "-c" , command },
654+ Command : []string {shCmd , "-c" , command },
644655 },
645656 },
646657 Volumes : []corev1.Volume {
647658 {
648- Name : "src-vol" ,
659+ Name : srcVolName ,
649660 VolumeSource : corev1.VolumeSource {
650661 PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
651662 ClaimName : srcPVC ,
@@ -654,7 +665,7 @@ func compareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, drv d
654665 },
655666 },
656667 {
657- Name : "dst-vol" ,
668+ Name : dstVolName ,
658669 VolumeSource : corev1.VolumeSource {
659670 PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
660671 ClaimName : dstPVC ,
@@ -669,23 +680,23 @@ func compareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, drv d
669680 if isBlock {
670681 pod .Spec .Containers [0 ].VolumeDevices = []corev1.VolumeDevice {
671682 {
672- Name : "src-vol" ,
683+ Name : srcVolName ,
673684 DevicePath : "/dev/src-block" ,
674685 },
675686 {
676- Name : "dst-vol" ,
687+ Name : dstVolName ,
677688 DevicePath : "/dev/dst-block" ,
678689 },
679690 }
680691 } else {
681692 pod .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {
682693 {
683- Name : "src-vol" ,
694+ Name : srcVolName ,
684695 MountPath : "/src" ,
685696 ReadOnly : true ,
686697 },
687698 {
688- Name : "dst-vol" ,
699+ Name : dstVolName ,
689700 MountPath : "/dst" ,
690701 ReadOnly : true ,
691702 },
@@ -730,7 +741,7 @@ func validateSyncedData(
730741) {
731742 var snapName string
732743
733- if copyMethod == "Snapshot" {
744+ if copyMethod == copyMethodSnapshot {
734745 By ("getting snapshot from RD latestImage" )
735746
736747 rd := & volsyncv1alpha1.ReplicationDestination {}
@@ -813,7 +824,7 @@ func validateSyncedData(
813824
814825 _ = k8sClientSet .CoreV1 ().PersistentVolumeClaims (namespace ).Delete (ctx , tempPVC , metav1.DeleteOptions {})
815826
816- if copyMethod == "Direct" {
827+ if copyMethod == copyMethodDirect {
817828 By ("cleaning up validation snapshot" )
818829
819830 snap := & snapv1.VolumeSnapshot {
@@ -898,7 +909,7 @@ func cleanupTryResources(ctx context.Context, snapPrefix, copyMethod string) {
898909 },
899910 })
900911
901- if copyMethod == "Direct" {
912+ if copyMethod == copyMethodDirect {
902913 deleteAndWaitFor (ctx , & snapv1.VolumeSnapshot {
903914 ObjectMeta : metav1.ObjectMeta {
904915 Name : snapPrefix + "-validate" ,
@@ -942,14 +953,14 @@ func tryCompareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, dr
942953 Containers : []corev1.Container {
943954 {
944955 Name : "compare" ,
945- Image : "busybox" ,
956+ Image : busyboxImage ,
946957 ImagePullPolicy : corev1 .PullAlways ,
947- Command : []string {"/bin/sh" , "-c" , command },
958+ Command : []string {shCmd , "-c" , command },
948959 },
949960 },
950961 Volumes : []corev1.Volume {
951962 {
952- Name : "src-vol" ,
963+ Name : srcVolName ,
953964 VolumeSource : corev1.VolumeSource {
954965 PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
955966 ClaimName : srcPVC ,
@@ -958,7 +969,7 @@ func tryCompareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, dr
958969 },
959970 },
960971 {
961- Name : "dst-vol" ,
972+ Name : dstVolName ,
962973 VolumeSource : corev1.VolumeSource {
963974 PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
964975 ClaimName : dstPVC ,
@@ -973,23 +984,23 @@ func tryCompareDataInPod(ctx context.Context, podName, srcPVC, dstPVC string, dr
973984 if isBlock {
974985 pod .Spec .Containers [0 ].VolumeDevices = []corev1.VolumeDevice {
975986 {
976- Name : "src-vol" ,
987+ Name : srcVolName ,
977988 DevicePath : "/dev/src-block" ,
978989 },
979990 {
980- Name : "dst-vol" ,
991+ Name : dstVolName ,
981992 DevicePath : "/dev/dst-block" ,
982993 },
983994 }
984995 } else {
985996 pod .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {
986997 {
987- Name : "src-vol" ,
998+ Name : srcVolName ,
988999 MountPath : "/src" ,
9891000 ReadOnly : true ,
9901001 },
9911002 {
992- Name : "dst-vol" ,
1003+ Name : dstVolName ,
9931004 MountPath : "/dst" ,
9941005 ReadOnly : true ,
9951006 },
@@ -1033,7 +1044,7 @@ func tryValidateSyncedData(
10331044
10341045 var snapName string
10351046
1036- if copyMethod == "Snapshot" {
1047+ if copyMethod == copyMethodSnapshot {
10371048 rd := & volsyncv1alpha1.ReplicationDestination {}
10381049
10391050 err := k8sClient .Get (ctx , types.NamespacedName {Name : rdName , Namespace : namespace }, rd )
0 commit comments