Skip to content

Commit bc3ec8f

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

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,21 @@ 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+
if serviceCertID != "" {
330+
svcCert, _, err := l.resources.gclient.Certificates.Get(ctx, serviceCertID)
331+
if err != nil {
332+
respErr, ok := err.(*godo.ErrorResponse)
333+
if !ok || respErr.Response.StatusCode != http.StatusNotFound {
334+
return fmt.Errorf("failed to get DO certificate for service: %s", err)
335+
}
336+
}
337+
338+
// The given certificate on the service exists, pass through so the LB is updated
339+
if svcCert != nil {
340+
return nil
341+
}
342+
}
343+
329344
lbCert, _, err := l.resources.gclient.Certificates.Get(ctx, lbCertID)
330345
if err != nil {
331346
respErr, ok := err.(*godo.ErrorResponse)

0 commit comments

Comments
 (0)