@@ -173,35 +173,27 @@ func (s *LBSpec) Certificates() (map[string]loadbalancer.CertificateDetails, err
173
173
if s .SSLConfig == nil {
174
174
return certs , nil
175
175
}
176
- //Read listener Kubernetes Secret
177
- sslSecret , err := s .SSLConfig .readSSLSecret (s .service .Namespace , s .SSLConfig .ListenerSSLSecretName )
178
- if err != nil {
179
- return nil , errors .Wrap (err , "reading SSL Listener Secret" )
176
+ secrets := make ([]string , 0 , 2 )
177
+ if s .SSLConfig .ListenerSSLSecretName != "" {
178
+ secrets = append (secrets , s .SSLConfig .ListenerSSLSecretName )
180
179
}
181
- if len ( sslSecret . PublicCert ) == 0 || len ( sslSecret . PrivateKey ) == 0 {
182
- return certs , nil
180
+ if s . SSLConfig . BackendSetSSLSecretName != "" {
181
+ secrets = append ( secrets , s . SSLConfig . BackendSetSSLSecretName )
183
182
}
184
183
185
- certs [s .SSLConfig .ListenerSSLSecretName ] = loadbalancer.CertificateDetails {
186
- CertificateName : & s .SSLConfig .ListenerSSLSecretName ,
187
- PublicCertificate : common .String (string (sslSecret .PublicCert )),
188
- PrivateKey : common .String (string (sslSecret .PrivateKey )),
189
- }
190
- // Read backendSet Kubernetes Secret
191
- sslSecret , err = s .SSLConfig .readSSLSecret (s .service .Namespace , s .SSLConfig .BackendSetSSLSecretName )
192
- if err != nil {
193
- return nil , errors .Wrap (err , "reading SSL BackendSet Secret" )
194
- }
195
- if len (sslSecret .PublicCert ) == 0 || len (sslSecret .PrivateKey ) == 0 {
196
- return certs , nil
197
- }
184
+ for _ , name := range secrets {
185
+ cert , err := s .SSLConfig .readSSLSecret (s .service .Namespace , name )
186
+ if err != nil {
187
+ return nil , errors .Wrap (err , "reading SSL BackendSet Secret" )
188
+ }
198
189
199
- certs [s .SSLConfig .BackendSetSSLSecretName ] = loadbalancer.CertificateDetails {
200
- CertificateName : & s .SSLConfig .BackendSetSSLSecretName ,
201
- CaCertificate : common .String (string (sslSecret .CACert )),
202
- PublicCertificate : common .String (string (sslSecret .PublicCert )),
203
- PrivateKey : common .String (string (sslSecret .PrivateKey )),
204
- Passphrase : common .String (string (sslSecret .Passphrase )),
190
+ certs [name ] = loadbalancer.CertificateDetails {
191
+ CertificateName : & name ,
192
+ CaCertificate : common .String (string (cert .CACert )),
193
+ PublicCertificate : common .String (string (cert .PublicCert )),
194
+ PrivateKey : common .String (string (cert .PrivateKey )),
195
+ Passphrase : common .String (string (cert .Passphrase )),
196
+ }
205
197
}
206
198
return certs , nil
207
199
}
@@ -277,23 +269,14 @@ func getBackendSets(svc *v1.Service, nodes []*v1.Node, sslCfg *SSLConfig) map[st
277
269
name := getBackendSetName (string (servicePort .Protocol ), int (servicePort .Port ))
278
270
port := int (servicePort .Port )
279
271
var secretName string
280
- if sslCfg != nil {
272
+ if sslCfg != nil && len ( sslCfg . BackendSetSSLSecretName ) != 0 {
281
273
secretName = sslCfg .BackendSetSSLSecretName
282
274
}
283
- sslConfig := getSSLConfiguration (sslCfg , secretName , port )
284
- if sslConfig != nil {
285
- backendSets [name ] = loadbalancer.BackendSetDetails {
286
- Policy : common .String (DefaultLoadBalancerPolicy ),
287
- Backends : getBackends (nodes , servicePort .NodePort ),
288
- HealthChecker : getHealthChecker (sslCfg , port , svc ),
289
- SslConfiguration : sslConfig ,
290
- }
291
- } else {
292
- backendSets [name ] = loadbalancer.BackendSetDetails {
293
- Policy : common .String (DefaultLoadBalancerPolicy ),
294
- Backends : getBackends (nodes , servicePort .NodePort ),
295
- HealthChecker : getHealthChecker (sslCfg , port , svc ),
296
- }
275
+ backendSets [name ] = loadbalancer.BackendSetDetails {
276
+ Policy : common .String (DefaultLoadBalancerPolicy ),
277
+ Backends : getBackends (nodes , servicePort .NodePort ),
278
+ HealthChecker : getHealthChecker (sslCfg , port , svc ),
279
+ SslConfiguration : getSSLConfiguration (sslCfg , secretName , port ),
297
280
}
298
281
}
299
282
return backendSets
@@ -322,7 +305,7 @@ func getHealthChecker(cfg *SSLConfig, port int, svc *v1.Service) *loadbalancer.H
322
305
}
323
306
324
307
func getSSLConfiguration (cfg * SSLConfig , name string , port int ) * loadbalancer.SslConfigurationDetails {
325
- if cfg == nil || ! cfg .Ports .Has (port ) {
308
+ if cfg == nil || ! cfg .Ports .Has (port ) || len ( name ) == 0 {
326
309
return nil
327
310
}
328
311
return & loadbalancer.SslConfigurationDetails {
@@ -365,7 +348,7 @@ func getListeners(svc *v1.Service, sslCfg *SSLConfig) (map[string]loadbalancer.L
365
348
}
366
349
port := int (servicePort .Port )
367
350
var secretName string
368
- if sslCfg != nil {
351
+ if sslCfg != nil && len ( sslCfg . ListenerSSLSecretName ) != 0 {
369
352
secretName = sslCfg .ListenerSSLSecretName
370
353
}
371
354
sslConfiguration := getSSLConfiguration (sslCfg , secretName , port )
0 commit comments