@@ -3644,6 +3644,77 @@ func TestReconcile_TLSAndCertSecretVolumeNameSanitization(t *testing.T) {
36443644 }
36453645}
36463646
3647+ func TestReconcile_CertSecretsWithSharedSecretNameReuseVolume (t * testing.T ) {
3648+ ensureGatewaySchemeRegistered (t )
3649+ ctx := context .Background ()
3650+
3651+ cp := & coderv1alpha1.CoderControlPlane {
3652+ ObjectMeta : metav1.ObjectMeta {Name : "test-cert-secret-shared-volume" , Namespace : "default" },
3653+ Spec : coderv1alpha1.CoderControlPlaneSpec {
3654+ Image : "test-certs-shared-volume:latest" ,
3655+ Certs : coderv1alpha1.CertsSpec {
3656+ Secrets : []coderv1alpha1.CertSecretSelector {
3657+ {Name : "shared.ca.secret" , Key : "ca.crt" },
3658+ {Name : "shared.ca.secret" , Key : "alt.crt" },
3659+ },
3660+ },
3661+ },
3662+ }
3663+ if err := k8sClient .Create (ctx , cp ); err != nil {
3664+ t .Fatalf ("create control plane: %v" , err )
3665+ }
3666+ t .Cleanup (func () {
3667+ _ = k8sClient .Delete (ctx , cp )
3668+ })
3669+
3670+ r := & controller.CoderControlPlaneReconciler {Client : k8sClient , Scheme : scheme }
3671+ if _ , err := r .Reconcile (ctx , ctrl.Request {NamespacedName : types.NamespacedName {Name : cp .Name , Namespace : cp .Namespace }}); err != nil {
3672+ t .Fatalf ("reconcile control plane: %v" , err )
3673+ }
3674+
3675+ deployment := & appsv1.Deployment {}
3676+ if err := k8sClient .Get (ctx , types.NamespacedName {Name : cp .Name , Namespace : cp .Namespace }, deployment ); err != nil {
3677+ t .Fatalf ("get deployment: %v" , err )
3678+ }
3679+ podSpec := deployment .Spec .Template .Spec
3680+ container := podSpec .Containers [0 ]
3681+
3682+ certVolumeName := ""
3683+ certVolumeCount := 0
3684+ for _ , volume := range podSpec .Volumes {
3685+ if volume .Secret == nil || volume .Secret .SecretName != "shared.ca.secret" {
3686+ continue
3687+ }
3688+ certVolumeCount ++
3689+ certVolumeName = volume .Name
3690+ }
3691+ if certVolumeCount != 1 {
3692+ t .Fatalf ("expected exactly one cert volume for shared secret, got %d volumes: %+v" , certVolumeCount , podSpec .Volumes )
3693+ }
3694+
3695+ expectedMountBySubPath := map [string ]string {
3696+ "ca.crt" : "/etc/ssl/certs/shared.ca.secret-ca.crt" ,
3697+ "alt.crt" : "/etc/ssl/certs/shared.ca.secret-alt.crt" ,
3698+ }
3699+ mountCount := 0
3700+ for _ , mount := range container .VolumeMounts {
3701+ if mount .Name != certVolumeName {
3702+ continue
3703+ }
3704+ expectedPath , ok := expectedMountBySubPath [mount .SubPath ]
3705+ if ! ok {
3706+ t .Fatalf ("unexpected cert subPath %q for mount %#v" , mount .SubPath , mount )
3707+ }
3708+ if mount .MountPath != expectedPath {
3709+ t .Fatalf ("expected mount path %q for subPath %q, got %q" , expectedPath , mount .SubPath , mount .MountPath )
3710+ }
3711+ mountCount ++
3712+ }
3713+ if mountCount != len (expectedMountBySubPath ) {
3714+ t .Fatalf ("expected %d cert volume mounts for shared secret, got %d mounts: %+v" , len (expectedMountBySubPath ), mountCount , container .VolumeMounts )
3715+ }
3716+ }
3717+
36473718func TestReconcile_PassThroughConfiguration (t * testing.T ) {
36483719 ensureGatewaySchemeRegistered (t )
36493720 ctx := context .Background ()
0 commit comments