Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Sort the Certificates by the secret name
Browse files Browse the repository at this point in the history
Certificates for ingress rules are stored in
Kubernetes secrets. This change sorts the certs
based on the secret name they are stored in. When
selecting a certificate for a hostname the first
secret found is used.
  • Loading branch information
cloudnautique committed May 26, 2022
1 parent a2eb1da commit ec1d0d5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/appdefinition/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package appdefinition
import (
"crypto/x509"
"encoding/pem"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -84,15 +85,21 @@ func getCerts(namespace string, req router.Request) ([]*TLSCert, error) {
result = append(result, cert)
}

sort.Slice(result, func(i, j int) bool {
return result[i].SecretName < result[j].SecretName
})

return result, nil
}

func getCertsForPublishedHosts(rules []networkingv1.IngressRule, certs []*TLSCert) (ingressTLS []networkingv1.IngressTLS) {
certSecretToHostMapping := map[string][]string{}
for _, rule := range rules {
for _, cert := range certs {
// Find the first cert and stop looking
if cert.certForThisDomain(rule.Host) {
certSecretToHostMapping[cert.SecretName] = append(certSecretToHostMapping[cert.SecretName], rule.Host)
break
}
}
}
Expand Down

0 comments on commit ec1d0d5

Please sign in to comment.