@@ -71,7 +71,7 @@ func (r *IngressClassReconciler) albSpecFromIngress( //nolint:funlen,gocyclo //
7171 networkID * string ,
7272 nodes []corev1.Node ,
7373 services map [string ]corev1.Service ,
74- ) (* albsdk.CreateLoadBalancerPayload , error ) {
74+ ) (bool , * albsdk.CreateLoadBalancerPayload , error ) {
7575 targetPools := []albsdk.TargetPool {}
7676 targetPoolSeen := map [string ]bool {}
7777 allCertificateIDs := []string {}
@@ -111,7 +111,7 @@ func (r *IngressClassReconciler) albSpecFromIngress( //nolint:funlen,gocyclo //
111111 for j , path := range rule .HTTP .Paths {
112112 nodePort , err := getNodePort (services , path )
113113 if err != nil {
114- return nil , err
114+ return false , nil , err
115115 }
116116
117117 targetPoolName := fmt .Sprintf ("pool-%d" , nodePort )
@@ -140,12 +140,13 @@ func (r *IngressClassReconciler) albSpecFromIngress( //nolint:funlen,gocyclo //
140140 }
141141
142142 // Apend certificates from the current Ingress to the combined certificates
143- certificateIDs , err := r .loadCerts (ctx , ingressClass , ingress )
144- if err != nil {
145- log .Printf ("failed to load tls certificates: %v" , err )
146- //nolint:gocritic // TODO: Rework error handling.
147- // return nil, fmt.Errorf("failed to load tls certificates: %w", err)
148- }
143+ requeueNeeded , certificateIDs , err := r .loadCerts (ctx , ingressClass , ingress )
144+ if requeueNeeded {
145+ return true , nil , nil
146+ }
147+ if err != nil {
148+ return false , nil , fmt .Errorf ("failed to load tls certificates: %w" , err )
149+ }
149150 allCertificateIDs = append (allCertificateIDs , certificateIDs ... )
150151 }
151152
@@ -245,45 +246,41 @@ func (r *IngressClassReconciler) albSpecFromIngress( //nolint:funlen,gocyclo //
245246 // Set the IP address of the ALB
246247 err := setIPAddresses (ingressClass , alb )
247248 if err != nil {
248- return nil , fmt .Errorf ("failed to set IP address: %w" , err )
249+ return false , nil , fmt .Errorf ("failed to set IP address: %w" , err )
249250 }
250251
251252 alb .Name = ptr .To (getAlbName (ingressClass ))
252253 alb .Listeners = listeners
253254 alb .TargetPools = targetPools
254255
255- return alb , nil
256+ return false , alb , nil
256257}
257258
258259// laodCerts loads the tls certificates from Ingress to the Certificates API
259260func (r * IngressClassReconciler ) loadCerts (
260261 ctx context.Context ,
261262 ingressClass * networkingv1.IngressClass ,
262263 ingress * networkingv1.Ingress ,
263- ) ([]string , error ) {
264+ ) (bool , []string , error ) {
264265 certificateIDs := []string {}
265266
266267 for _ , tls := range ingress .Spec .TLS {
267- if tls .SecretName ! = "" {
268+ if tls .SecretName = = "" {
268269 continue
269270 }
270271
271272 secret := & corev1.Secret {}
272273 if err := r .Client .Get (ctx , types.NamespacedName {Namespace : ingress .Namespace , Name : tls .SecretName }, secret ); err != nil {
273- return nil , fmt .Errorf ("failed to get TLS secret: %w" , err )
274+ return false , nil , fmt .Errorf ("failed to get TLS secret: %w" , err )
274275 }
275276
276- // The tls.crt should contain both the leaf certificate and the intermediate CA certificates.
277- // If it contains only the leaf certificate, the ACME challenge likely hasn't finished.
278- // Therefore the incomplete certificate shouldn't be loaded as the updates upon them are impossible.
279277 complete , err := isCertReady (secret )
280278 if err != nil {
281- return nil , fmt .Errorf ("failed to check if certificate is ready: %w" , err )
279+ return false , nil , fmt .Errorf ("failed to check if certificate is ready: %w" , err )
282280 }
283281 if ! complete {
284- // TODO: Requeue, instead of returning error - the ACME challenge hasn't finished yet
285- // return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
286- return nil , fmt .Errorf ("certificate is not complete: %w" , err )
282+ // Requeue: The ACME challenge is still in progress and the certificate is not yet fully issued.
283+ return true , nil , fmt .Errorf ("certificate is not complete: %w" , err )
287284 }
288285
289286 createCertificatePayload := & certsdk.CreateCertificatePayload {
@@ -294,12 +291,12 @@ func (r *IngressClassReconciler) loadCerts(
294291 }
295292 res , err := r .CertificateClient .CreateCertificate (ctx , r .ProjectID , r .Region , createCertificatePayload )
296293 if err != nil {
297- return nil , fmt .Errorf ("failed to create certificate: %w" , err )
294+ return false , nil , fmt .Errorf ("failed to create certificate: %w" , err )
298295 }
299296
300297 certificateIDs = append (certificateIDs , * res .Id )
301298 }
302- return certificateIDs , nil
299+ return false , certificateIDs , nil
303300}
304301
305302// cleanupCerts deletes the certificates from the Certificates API that are no longer associated with any Ingress in the IngressClass
0 commit comments