@@ -3085,6 +3085,205 @@ func Test_BundleCSVDeploymentGenerator_WithDeploymentConfig(t *testing.T) {
30853085 require .Equal (t , "existing_value" , dep .Spec .Template .Spec .Containers [0 ].Env [0 ].Value )
30863086 },
30873087 },
3088+ {
3089+ name : "merges volumes from deployment config - overrides matching names" ,
3090+ bundle : & bundle.RegistryV1 {
3091+ CSV : clusterserviceversion .Builder ().
3092+ WithStrategyDeploymentSpecs (
3093+ v1alpha1.StrategyDeploymentSpec {
3094+ Name : "test-deployment" ,
3095+ Spec : appsv1.DeploymentSpec {
3096+ Template : corev1.PodTemplateSpec {
3097+ Spec : corev1.PodSpec {
3098+ Containers : []corev1.Container {
3099+ {Name : "manager" },
3100+ },
3101+ Volumes : []corev1.Volume {
3102+ {
3103+ Name : "bundle-emptydir-vol" ,
3104+ VolumeSource : corev1.VolumeSource {
3105+ EmptyDir : & corev1.EmptyDirVolumeSource {},
3106+ },
3107+ },
3108+ {
3109+ Name : "existing-vol" ,
3110+ VolumeSource : corev1.VolumeSource {
3111+ EmptyDir : & corev1.EmptyDirVolumeSource {},
3112+ },
3113+ },
3114+ },
3115+ },
3116+ },
3117+ },
3118+ },
3119+ ).Build (),
3120+ },
3121+ opts : render.Options {
3122+ InstallNamespace : "test-ns" ,
3123+ TargetNamespaces : []string {"test-ns" },
3124+ DeploymentConfig : & config.DeploymentConfig {
3125+ Volumes : []corev1.Volume {
3126+ {
3127+ Name : "bundle-emptydir-vol" ,
3128+ VolumeSource : corev1.VolumeSource {
3129+ ConfigMap : & corev1.ConfigMapVolumeSource {
3130+ LocalObjectReference : corev1.LocalObjectReference {
3131+ Name : "test-cm-vol" ,
3132+ },
3133+ },
3134+ },
3135+ },
3136+ {
3137+ Name : "config-secret-vol" ,
3138+ VolumeSource : corev1.VolumeSource {
3139+ Secret : & corev1.SecretVolumeSource {
3140+ SecretName : "test-secret-vol" ,
3141+ },
3142+ },
3143+ },
3144+ },
3145+ },
3146+ },
3147+ verify : func (t * testing.T , objs []client.Object ) {
3148+ require .Len (t , objs , 1 )
3149+ dep := objs [0 ].(* appsv1.Deployment )
3150+ volumes := dep .Spec .Template .Spec .Volumes
3151+
3152+ // Should have 3 volumes total:
3153+ // - bundle-emptydir-vol (overridden to ConfigMap)
3154+ // - existing-vol (unchanged)
3155+ // - config-secret-vol (new)
3156+ require .Len (t , volumes , 3 )
3157+
3158+ // Verify bundle-emptydir-vol was overridden (now ConfigMap, not EmptyDir)
3159+ var bundleVol * corev1.Volume
3160+ for i := range volumes {
3161+ if volumes [i ].Name == "bundle-emptydir-vol" {
3162+ bundleVol = & volumes [i ]
3163+ break
3164+ }
3165+ }
3166+ require .NotNil (t , bundleVol , "bundle-emptydir-vol should exist" )
3167+ require .NotNil (t , bundleVol .ConfigMap , "bundle-emptydir-vol should be ConfigMap" )
3168+ require .Equal (t , "test-cm-vol" , bundleVol .ConfigMap .Name )
3169+ require .Nil (t , bundleVol .EmptyDir , "bundle-emptydir-vol should not be EmptyDir" )
3170+
3171+ // Verify existing-vol remains unchanged
3172+ var existingVol * corev1.Volume
3173+ for i := range volumes {
3174+ if volumes [i ].Name == "existing-vol" {
3175+ existingVol = & volumes [i ]
3176+ break
3177+ }
3178+ }
3179+ require .NotNil (t , existingVol , "existing-vol should exist" )
3180+ require .NotNil (t , existingVol .EmptyDir , "existing-vol should still be EmptyDir" )
3181+
3182+ // Verify config-secret-vol was added
3183+ var secretVol * corev1.Volume
3184+ for i := range volumes {
3185+ if volumes [i ].Name == "config-secret-vol" {
3186+ secretVol = & volumes [i ]
3187+ break
3188+ }
3189+ }
3190+ require .NotNil (t , secretVol , "config-secret-vol should exist" )
3191+ require .NotNil (t , secretVol .Secret , "config-secret-vol should be Secret" )
3192+ require .Equal (t , "test-secret-vol" , secretVol .Secret .SecretName )
3193+ },
3194+ },
3195+ {
3196+ name : "merges volumeMounts from deployment config - overrides matching names" ,
3197+ bundle : & bundle.RegistryV1 {
3198+ CSV : clusterserviceversion .Builder ().
3199+ WithStrategyDeploymentSpecs (
3200+ v1alpha1.StrategyDeploymentSpec {
3201+ Name : "test-deployment" ,
3202+ Spec : appsv1.DeploymentSpec {
3203+ Template : corev1.PodTemplateSpec {
3204+ Spec : corev1.PodSpec {
3205+ Containers : []corev1.Container {
3206+ {
3207+ Name : "manager" ,
3208+ VolumeMounts : []corev1.VolumeMount {
3209+ {
3210+ Name : "bundle-vol" ,
3211+ MountPath : "/old/path" ,
3212+ },
3213+ {
3214+ Name : "existing-vol" ,
3215+ MountPath : "/existing/path" ,
3216+ },
3217+ },
3218+ },
3219+ },
3220+ },
3221+ },
3222+ },
3223+ },
3224+ ).Build (),
3225+ },
3226+ opts : render.Options {
3227+ InstallNamespace : "test-ns" ,
3228+ TargetNamespaces : []string {"test-ns" },
3229+ DeploymentConfig : & config.DeploymentConfig {
3230+ VolumeMounts : []corev1.VolumeMount {
3231+ {
3232+ Name : "bundle-vol" ,
3233+ MountPath : "/new/path" ,
3234+ },
3235+ {
3236+ Name : "config-vol" ,
3237+ MountPath : "/config/path" ,
3238+ },
3239+ },
3240+ },
3241+ },
3242+ verify : func (t * testing.T , objs []client.Object ) {
3243+ require .Len (t , objs , 1 )
3244+ dep := objs [0 ].(* appsv1.Deployment )
3245+ volumeMounts := dep .Spec .Template .Spec .Containers [0 ].VolumeMounts
3246+
3247+ // Should have 3 volume mounts total:
3248+ // - bundle-vol (overridden to /new/path)
3249+ // - existing-vol (unchanged)
3250+ // - config-vol (new)
3251+ require .Len (t , volumeMounts , 3 )
3252+
3253+ // Verify bundle-vol was overridden
3254+ var bundleMount * corev1.VolumeMount
3255+ for i := range volumeMounts {
3256+ if volumeMounts [i ].Name == "bundle-vol" {
3257+ bundleMount = & volumeMounts [i ]
3258+ break
3259+ }
3260+ }
3261+ require .NotNil (t , bundleMount , "bundle-vol should exist" )
3262+ require .Equal (t , "/new/path" , bundleMount .MountPath , "bundle-vol mount path should be overridden" )
3263+
3264+ // Verify existing-vol remains unchanged
3265+ var existingMount * corev1.VolumeMount
3266+ for i := range volumeMounts {
3267+ if volumeMounts [i ].Name == "existing-vol" {
3268+ existingMount = & volumeMounts [i ]
3269+ break
3270+ }
3271+ }
3272+ require .NotNil (t , existingMount , "existing-vol should exist" )
3273+ require .Equal (t , "/existing/path" , existingMount .MountPath )
3274+
3275+ // Verify config-vol was added
3276+ var configMount * corev1.VolumeMount
3277+ for i := range volumeMounts {
3278+ if volumeMounts [i ].Name == "config-vol" {
3279+ configMount = & volumeMounts [i ]
3280+ break
3281+ }
3282+ }
3283+ require .NotNil (t , configMount , "config-vol should exist" )
3284+ require .Equal (t , "/config/path" , configMount .MountPath )
3285+ },
3286+ },
30883287 } {
30893288 t .Run (tc .name , func (t * testing.T ) {
30903289 objs , err := generators .BundleCSVDeploymentGenerator (tc .bundle , tc .opts )
0 commit comments