@@ -108,8 +108,10 @@ func TestDeploymentBuilder(t *testing.T) {
108108 Spec : corev1.PodSpec {
109109 Volumes : []corev1.Volume {
110110 {
111- // NOTE: we need to provide the existing entry in the slice
111+ // NOTE: we can provide the existing entry in the slice
112112 // to prevent merging the provided new entry with existing entries.
113+ // Next test case shows that we can also not provide it and it will
114+ // still work as expected (although the order may change).
113115 Name : consts .ClusterCertificateVolume ,
114116 },
115117 {
@@ -207,6 +209,111 @@ func TestDeploymentBuilder(t *testing.T) {
207209 )
208210 },
209211 },
212+ {
213+ name : "new DataPlane with custom secret (without specifying the base certificate volume or volume mount)" ,
214+ dataPlane : & operatorv1beta1.DataPlane {
215+ ObjectMeta : metav1.ObjectMeta {
216+ Name : "test-secret-volume" ,
217+ Namespace : "default" ,
218+ },
219+ Spec : operatorv1beta1.DataPlaneSpec {
220+ DataPlaneOptions : operatorv1beta1.DataPlaneOptions {
221+ Deployment : operatorv1beta1.DataPlaneDeploymentOptions {
222+ DeploymentOptions : operatorv1beta1.DeploymentOptions {
223+ PodTemplateSpec : & corev1.PodTemplateSpec {
224+ Spec : corev1.PodSpec {
225+ Volumes : []corev1.Volume {
226+ {
227+ Name : "test-volume" ,
228+ VolumeSource : corev1.VolumeSource {
229+ Secret : & corev1.SecretVolumeSource {
230+ SecretName : "test-secret" ,
231+ },
232+ },
233+ },
234+ },
235+ Containers : []corev1.Container {
236+ {
237+ Name : consts .DataPlaneProxyContainerName ,
238+ VolumeMounts : []corev1.VolumeMount {
239+ {
240+ Name : "test-volume" ,
241+ MountPath : "/var/test/" ,
242+ ReadOnly : true ,
243+ },
244+ },
245+ },
246+ },
247+ },
248+ },
249+ },
250+ },
251+ },
252+ },
253+ },
254+ certSecretName : "certificate" ,
255+ testBody : func (t * testing.T , reconciler Reconciler , dataPlane * operatorv1beta1.DataPlane , certSecretName string ) {
256+ ctx := t .Context ()
257+
258+ deploymentBuilder := NewDeploymentBuilder (logr .Discard (), reconciler .Client ).
259+ WithClusterCertificate (certSecretName ).
260+ WithAdditionalLabels (deploymentLiveLabels )
261+
262+ deployment , res , err := deploymentBuilder .BuildAndDeploy (ctx , dataPlane , enforceConfig , validateDataPlaneImage )
263+ require .NoError (t , err )
264+ require .Equal (t , op .Created , res )
265+ require .Len (t , deployment .Spec .Template .Spec .Volumes , 2 )
266+ require .Len (t , deployment .Spec .Template .Spec .Containers , 1 )
267+ require .Len (t , deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts , 2 )
268+
269+ certificateVolume := corev1.Volume {}
270+ certificateVolume .Secret = & corev1.SecretVolumeSource {}
271+ // Fill in the defaults for the volume after setting the secret volume source
272+ // field. This prevents setting the empty dir volume source field which
273+ // would conflict with the secret volume source field.
274+ k8sresources .SetDefaultsVolume (& certificateVolume )
275+ certificateVolume .Name = consts .ClusterCertificateVolume
276+ certificateVolume .Secret .SecretName = "certificate"
277+ certificateVolume .Secret .Items = []corev1.KeyToPath {
278+ {
279+ Key : "tls.crt" ,
280+ Path : "tls.crt" ,
281+ },
282+ {
283+ Key : "tls.key" ,
284+ Path : "tls.key" ,
285+ },
286+ {
287+ Key : "ca.crt" ,
288+ Path : "ca.crt" ,
289+ },
290+ }
291+
292+ testVolume := corev1.Volume {}
293+ testVolume .Secret = & corev1.SecretVolumeSource {}
294+ // Fill in the defaults for the volume after setting the secret volume source
295+ // field. This prevents setting the empty dir volume source field which
296+ // would conflict with the secret volume source field.
297+ k8sresources .SetDefaultsVolume (& testVolume )
298+ testVolume .Name = "test-volume"
299+ testVolume .Secret .SecretName = "test-secret"
300+
301+ require .Equal (t , []corev1.VolumeMount {
302+ {
303+ Name : "test-volume" ,
304+ MountPath : "/var/test/" ,
305+ ReadOnly : true ,
306+ },
307+ {
308+ Name : consts .ClusterCertificateVolume ,
309+ MountPath : consts .ClusterCertificateVolumeMountPath ,
310+ ReadOnly : true ,
311+ },
312+ },
313+ deployment .Spec .Template .Spec .Containers [0 ].VolumeMounts ,
314+ )
315+ },
316+ },
210317 {
211318 name : "existing DataPlane deployment gets updated with expected spec.Strategy" ,
212319 dataPlane : & operatorv1beta1.DataPlane {
0 commit comments