@@ -20,23 +20,24 @@ import (
2020)
2121
2222const (
23- certBackendDirectory = configDirectory + "/~postgres-operator-backend"
24- certFrontendDirectory = configDirectory + "/~postgres-operator-frontend"
23+ tlsAuthoritySecretKey = "ca.crt"
24+ tlsCertificateSecretKey = corev1 .TLSCertKey
25+ tlsPrivateKeySecretKey = corev1 .TLSPrivateKeyKey
2526
26- certBackendAuthorityAbsolutePath = certBackendDirectory + "/" + certBackendAuthorityProjectionPath
27- certBackendAuthorityProjectionPath = "ca.crt"
27+ certBackendAuthorityAbsolutePath = configDirectory + "/" + certBackendAuthorityProjectionPath
28+ certBackendAuthorityProjectionPath = "~postgres-operator/backend- ca.crt"
2829
29- certFrontendAuthorityAbsolutePath = certFrontendDirectory + "/" + certFrontendAuthorityProjectionPath
30- certFrontendPrivateKeyAbsolutePath = certFrontendDirectory + "/" + certFrontendPrivateKeyProjectionPath
31- certFrontendAbsolutePath = certFrontendDirectory + "/" + certFrontendProjectionPath
30+ certFrontendAuthorityAbsolutePath = configDirectory + "/" + certFrontendAuthorityProjectionPath
31+ certFrontendPrivateKeyAbsolutePath = configDirectory + "/" + certFrontendPrivateKeyProjectionPath
32+ certFrontendAbsolutePath = configDirectory + "/" + certFrontendProjectionPath
3233
33- certFrontendAuthorityProjectionPath = "ca.crt"
34- certFrontendPrivateKeyProjectionPath = "tls.key"
35- certFrontendProjectionPath = "tls.crt"
34+ certFrontendAuthorityProjectionPath = "~postgres-operator/frontend- ca.crt"
35+ certFrontendPrivateKeyProjectionPath = "~postgres-operator/frontend- tls.key"
36+ certFrontendProjectionPath = "~postgres-operator/frontend- tls.crt"
3637
37- certFrontendAuthoritySecretKey = "pgbouncer-frontend.ca-roots" // #nosec G101 this is a name, not a credential
38- certFrontendPrivateKeySecretKey = "pgbouncer-frontend.key" // #nosec G101 this is a name, not a credential
39- certFrontendSecretKey = "pgbouncer-frontend.crt" // #nosec G101 this is a name, not a credential
38+ certFrontendAuthoritySecretKey = "pgbouncer-frontend.ca-roots"
39+ certFrontendPrivateKeySecretKey = "pgbouncer-frontend.key"
40+ certFrontendSecretKey = "pgbouncer-frontend.crt"
4041)
4142
4243// backendAuthority creates a volume projection of the PostgreSQL server
@@ -46,11 +47,20 @@ func backendAuthority(postgres *corev1.SecretProjection) corev1.VolumeProjection
4647 result := postgres .DeepCopy ()
4748
4849 for i := range result .Items {
49- if result .Items [i ].Path == certBackendAuthorityProjectionPath {
50+ // The PostgreSQL server projection expects Path to match typical Keys.
51+ if result .Items [i ].Path == tlsAuthoritySecretKey {
52+ result .Items [i ].Path = certBackendAuthorityProjectionPath
5053 items = append (items , result .Items [i ])
5154 }
5255 }
5356
57+ if len (items ) == 0 {
58+ items = []corev1.KeyToPath {{
59+ Key : tlsAuthoritySecretKey ,
60+ Path : certBackendAuthorityProjectionPath ,
61+ }}
62+ }
63+
5464 result .Items = items
5565 return corev1.VolumeProjection {Secret : result }
5666}
@@ -59,10 +69,8 @@ func backendAuthority(postgres *corev1.SecretProjection) corev1.VolumeProjection
5969func frontendCertificate (
6070 custom * corev1.SecretProjection , secret * corev1.Secret ,
6171) corev1.VolumeProjection {
62- result := custom
63-
64- if result == nil {
65- result = & corev1.SecretProjection {
72+ if custom == nil {
73+ return corev1.VolumeProjection {Secret : & corev1.SecretProjection {
6674 LocalObjectReference : corev1.LocalObjectReference {
6775 Name : secret .Name ,
6876 },
@@ -80,8 +88,53 @@ func frontendCertificate(
8088 Path : certFrontendProjectionPath ,
8189 },
8290 },
91+ }}
92+ }
93+
94+ // The custom projection may have more or less than the three items we need
95+ // to mount. Search for items that have the Path we expect and mount them at
96+ // the path we need. When no items are specified, the Key serves as the Path.
97+
98+ // TODO(cbandy): A more structured field or validating webhook would ensure
99+ // that the necessary values are specified.
100+
101+ var items []corev1.KeyToPath
102+ result := custom .DeepCopy ()
103+
104+ for i := range result .Items {
105+ // The custom projection expects Path to match typical Keys.
106+ switch result .Items [i ].Path {
107+ case tlsAuthoritySecretKey :
108+ result .Items [i ].Path = certFrontendAuthorityProjectionPath
109+ items = append (items , result .Items [i ])
110+
111+ case tlsCertificateSecretKey :
112+ result .Items [i ].Path = certFrontendProjectionPath
113+ items = append (items , result .Items [i ])
114+
115+ case tlsPrivateKeySecretKey :
116+ result .Items [i ].Path = certFrontendPrivateKeyProjectionPath
117+ items = append (items , result .Items [i ])
118+ }
119+ }
120+
121+ if len (items ) == 0 {
122+ items = []corev1.KeyToPath {
123+ {
124+ Key : tlsAuthoritySecretKey ,
125+ Path : certFrontendAuthorityProjectionPath ,
126+ },
127+ {
128+ Key : tlsPrivateKeySecretKey ,
129+ Path : certFrontendPrivateKeyProjectionPath ,
130+ },
131+ {
132+ Key : tlsCertificateSecretKey ,
133+ Path : certFrontendProjectionPath ,
134+ },
83135 }
84136 }
85137
138+ result .Items = items
86139 return corev1.VolumeProjection {Secret : result }
87140}
0 commit comments