@@ -108,28 +108,30 @@ func (t *defaultModelBuildTask) buildSSLNegotiationPolicy(_ context.Context) *st
108
108
return & t .defaultSSLPolicy
109
109
}
110
110
111
- func (t * defaultModelBuildTask ) buildListenerCertificates (ctx context.Context ) []elbv2model.Certificate {
111
+ func (t * defaultModelBuildTask ) buildListenerCertificates (ctx context.Context ) ( []elbv2model.Certificate , error ) {
112
112
var rawCertificateARNs []string
113
113
var rawSSLDomains []string
114
- _ = t .annotationParser .ParseStringSliceAnnotation (annotations .SvcLBSuffixSSLCertificate , & rawCertificateARNs , t .service .Annotations )
115
- _ = t .annotationParser .ParseStringSliceAnnotation (annotations .SvcLBSuffixSSLDomains , & rawSSLDomains , t .service .Annotations )
114
+ sslCertAnnotationExists := t .annotationParser .ParseStringSliceAnnotation (annotations .SvcLBSuffixSSLCertificate , & rawCertificateARNs , t .service .Annotations )
116
115
117
116
var certificates []elbv2model.Certificate
118
117
for _ , cert := range rawCertificateARNs {
119
118
certificates = append (certificates , elbv2model.Certificate {CertificateARN : aws .String (cert )})
120
119
}
121
120
122
- // TODO: Refactoring required
123
- autoDiscoveredCertARNs , err := t .certDiscovery .Discover (ctx , rawSSLDomains )
124
- if err != nil {
125
- return certificates
126
- }
127
- for _ , cert := range autoDiscoveredCertARNs {
128
- certificates = append (certificates , elbv2model.Certificate {
129
- CertificateARN : aws .String (cert ),
130
- })
121
+ // auto-discover ACM certs only if the ssl-domains annotation exists ssl-cert annotations is not present
122
+ // which means ssl-cert takes precedence over the auto-discovered cert/ss-domains annotation
123
+ if ! sslCertAnnotationExists && t .annotationParser .ParseStringSliceAnnotation (annotations .SvcLBSuffixSSLDomains , & rawSSLDomains , t .service .Annotations ) {
124
+ autoDiscoveredCertARNs , err := t .certDiscovery .Discover (ctx , rawSSLDomains )
125
+ if err != nil {
126
+ return certificates , err
127
+ }
128
+ for _ , cert := range autoDiscoveredCertARNs {
129
+ certificates = append (certificates , elbv2model.Certificate {
130
+ CertificateARN : aws .String (cert ),
131
+ })
132
+ }
131
133
}
132
- return certificates
134
+ return certificates , nil
133
135
}
134
136
135
137
func validateTLSPortsSet (rawTLSPorts []string , ports []corev1.ServicePort ) error {
@@ -205,7 +207,11 @@ type listenerConfig struct {
205
207
}
206
208
207
209
func (t * defaultModelBuildTask ) buildListenerConfig (ctx context.Context ) (* listenerConfig , error ) {
208
- certificates := t .buildListenerCertificates (ctx )
210
+ certificates , err := t .buildListenerCertificates (ctx )
211
+ if err != nil {
212
+ return nil , err
213
+ }
214
+
209
215
tlsPortsSet , err := t .buildTLSPortsSet (ctx )
210
216
if err != nil {
211
217
return nil , err
0 commit comments