Skip to content

Commit 0807bd5

Browse files
committed
Do not rewrite cert-id on service if existing certificate is valid
1 parent 9c8ba31 commit 0807bd5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

cloud-controller-manager/do/certificates_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func Test_LBaaSCertificateScenarios(t *testing.T) {
134134
certService.store[cert.ID] = cert
135135
return service
136136
},
137-
expectedServiceCertID: "lb-cert-id",
138-
expectedLBCertID: "lb-cert-id",
137+
expectedServiceCertID: "service-cert-id",
138+
expectedLBCertID: "service-cert-id",
139139
},
140140
{
141141
name: "[letsencrypt] LB cert ID exists and service cert ID does not",

cloud-controller-manager/do/loadbalancers.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ func getCertificateIDFromLB(lb *godo.LoadBalancer) string {
326326
// Load Balancer.
327327
func (l *loadBalancers) recordUpdatedLetsEncryptCert(ctx context.Context, service *v1.Service, lbCertID, serviceCertID string) error {
328328
if lbCertID != "" && lbCertID != serviceCertID {
329+
svcCert, _, err := l.resources.gclient.Certificates.Get(ctx, serviceCertID)
330+
if err != nil {
331+
respErr, ok := err.(*godo.ErrorResponse)
332+
if !ok || respErr.Response.StatusCode != http.StatusNotFound {
333+
return fmt.Errorf("failed to get DO certificate for service: %s", err)
334+
}
335+
}
336+
337+
// The given certificate on the service exists, pass through so the LB is updated
338+
if svcCert != nil {
339+
return nil
340+
}
341+
329342
lbCert, _, err := l.resources.gclient.Certificates.Get(ctx, lbCertID)
330343
if err != nil {
331344
respErr, ok := err.(*godo.ErrorResponse)

0 commit comments

Comments
 (0)