@@ -31,6 +31,7 @@ import (
3131 "k8s.io/apimachinery/pkg/api/errors"
3232 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333 "k8s.io/apimachinery/pkg/runtime"
34+ "k8s.io/apimachinery/pkg/runtime/schema"
3435 "k8s.io/apimachinery/pkg/types"
3536 kvalidation "k8s.io/apimachinery/pkg/util/validation"
3637 "k8s.io/client-go/kubernetes/scheme"
@@ -907,6 +908,64 @@ var _ = Describe("Create Importer Pod", func() {
907908 Entry ("should create pod with block volume mode and scratchspace" , createBlockPvc ("testBlockPvc1" , "default" , map [string ]string {cc .AnnEndpoint : testEndPoint , cc .AnnPodPhase : string (corev1 .PodPending ), cc .AnnImportPod : "podName" , cc .AnnPriorityClassName : "p0" , cc .AnnPodServiceAccount : "my-sa" }, nil ), & scratchPvcName ),
908909 )
909910
911+ DescribeTable ("should copy labels from target PVC when creating pod" , func (isPopulator bool ) {
912+ targetPvc := cc .CreatePvc ("targetPvc" , "default" ,
913+ map [string ]string {
914+ cc .AnnEndpoint : testEndPoint ,
915+ cc .AnnImportPod : "podName" ,
916+ },
917+ map [string ]string {
918+ "custom-label" : "value" ,
919+ },
920+ )
921+
922+ objects := []runtime.Object {targetPvc }
923+ podArgs := & importerPodArgs {
924+ image : testImage ,
925+ verbose : "5" ,
926+ pullPolicy : testPullPolicy ,
927+ podEnvVar : & importPodEnvVar {},
928+ pvc : targetPvc ,
929+ }
930+
931+ if isPopulator {
932+ primePvc := cc .CreatePvc ("primePvc" , "default" ,
933+ map [string ]string {
934+ cc .AnnEndpoint : testEndPoint ,
935+ cc .AnnImportPod : "podName" ,
936+ cc .AnnPopulatorKind : cdiv1 .VolumeImportSourceRef ,
937+ },
938+ map [string ]string {
939+ "prime-label" : "prime-value" ,
940+ },
941+ )
942+ primePvc .OwnerReferences = []metav1.OwnerReference {
943+ * metav1 .NewControllerRef (targetPvc , schema.GroupVersionKind {
944+ Group : "" ,
945+ Version : "v1" ,
946+ Kind : "PersistentVolumeClaim" ,
947+ }),
948+ }
949+ objects = append (objects , primePvc )
950+ podArgs .pvc = primePvc
951+ }
952+
953+ reconciler := createImportReconciler (objects ... )
954+
955+ pod , err := createImporterPod (context .TODO (), reconciler .log , reconciler .client , podArgs , map [string ]string {})
956+ Expect (err ).ToNot (HaveOccurred ())
957+
958+ By ("Verifying pod has labels from target PVC" )
959+ Expect (pod .Labels ).To (HaveKeyWithValue ("custom-label" , "value" ))
960+ if isPopulator {
961+ By ("Verifying pod does not have labels from prime PVC" )
962+ Expect (pod .Labels ).ToNot (HaveKey ("prime-label" ))
963+ }
964+ },
965+ Entry ("using populator" , true ),
966+ Entry ("using non-populator" , false ),
967+ )
968+
910969 DescribeTable ("should append current checkpoint name to importer pod" , func (pvcName , checkpointID string ) {
911970 pvc := cc .CreatePvc (pvcName , "default" , map [string ]string {cc .AnnCurrentCheckpoint : checkpointID , cc .AnnEndpoint : testEndPoint }, nil )
912971 pvc .Status .Phase = v1 .ClaimBound
0 commit comments