Skip to content

Commit

Permalink
fix(api/types): merge cert-manager request w/ same issuer name
Browse files Browse the repository at this point in the history
  • Loading branch information
nettoclaudio committed Oct 22, 2021
1 parent 1c9e654 commit a98bebb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/v1alpha1/rpaasinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package v1alpha1

import "sort"

const (
teamOwnerLabel = "rpaas.extensions.tsuru.io/team-owner"
clusterNameLabel = "rpaas.extensions.tsuru.io/cluster-name"
Expand All @@ -14,11 +16,27 @@ func (i *RpaasInstance) CertManagerRequests() (reqs []CertManager) {
return
}

uniqueCerts := make(map[string]CertManager)
if req := i.Spec.DynamicCertificates.CertManager; req != nil {
reqs = append(reqs, *req)
uniqueCerts[req.Issuer] = *req
}

for _, req := range i.Spec.DynamicCertificates.CertManagerRequests {
r, found := uniqueCerts[req.Issuer]
if found {
r.DNSNames = append(r.DNSNames, req.DNSNames...)
r.IPAddresses = append(r.IPAddresses, req.IPAddresses...)
continue
}

uniqueCerts[req.Issuer] = req
}

for _, v := range uniqueCerts {
reqs = append(reqs, v)
}

reqs = append(reqs, i.Spec.DynamicCertificates.CertManagerRequests...)
sort.Slice(reqs, func(i, j int) bool { return reqs[i].Issuer < reqs[j].Issuer })

return
}
Expand Down

0 comments on commit a98bebb

Please sign in to comment.