Skip to content

Commit bc35536

Browse files
committed
fix(http-boot): stop requeue loop on UKI resolution failure
When constructUKIURL fails with a non-retryable error (e.g. image has no UKI layer, registry validation error), the controller was returning the error directly, causing controller-runtime to immediately requeue the object. This produced a tight loop hammering the container registry. Two changes: - HTTP 429 responses from the registry are detected via isRegistryRateLimited and retried with a 30s backoff instead of immediately. - All other hard errors (no UKI layer, unknown image format, etc.) are recorded in the ServerBootConfiguration status via PatchServerBootConfigWithError and then return nil so no requeue occurs. Reconciliation resumes only when the object is updated (e.g. the image field changes). Signed-off-by: Andrew Dodds <andrew.dodds@sap.com>
1 parent 62fbee9 commit bc35536

1 file changed

Lines changed: 56 additions & 2 deletions

File tree

‎internal/controller/serverbootconfiguration_http_controller.go‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ package controller
66
import (
77
"context"
88
"encoding/json"
9+
"errors"
910
"fmt"
11+
"io"
12+
"net"
1013
"strings"
14+
"time"
15+
16+
remoteerrors "github.com/containerd/containerd/remotes/errors"
1117

1218
apimeta "k8s.io/apimachinery/pkg/api/meta"
1319

@@ -89,12 +95,26 @@ func (r *ServerBootConfigurationHTTPReconciler) reconcile(ctx context.Context, l
8995

9096
ukiURL, err := r.constructUKIURL(ctx, config.Spec.Image)
9197
if err != nil {
92-
log.Error(err, "Failed to construct UKI URL")
9398
if patchErr := PatchServerBootConfigWithError(ctx, r.Client,
9499
types.NamespacedName{Name: config.Name, Namespace: config.Namespace}, err); patchErr != nil {
95100
return ctrl.Result{}, fmt.Errorf("failed to patch state to error: %w (original error: %w)", patchErr, err)
96101
}
97-
return ctrl.Result{}, err
102+
if code, ok := registryHTTPStatusCode(err); ok && (code == 429 || code >= 500) {
103+
log.V(1).Info("Registry HTTP error, requeueing after backoff", "statusCode", code, "error", err)
104+
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
105+
}
106+
if isTransientNetworkError(err) {
107+
log.V(1).Info("Transient network error contacting registry, requeueing after backoff", "error", err)
108+
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
109+
}
110+
if isTransientIOError(err) {
111+
log.V(1).Info("Transient IO error reading from registry, requeueing after backoff", "error", err)
112+
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
113+
}
114+
log.Error(err, "Failed to construct UKI URL")
115+
// Don't requeue — the error is recorded in the status. A future update to
116+
// the ServerBootConfiguration (e.g. image field change) will re-trigger reconciliation.
117+
return ctrl.Result{}, nil
98118
}
99119
log.V(1).Info("Extracted UKI URL for boot")
100120

@@ -233,6 +253,40 @@ func (r *ServerBootConfigurationHTTPReconciler) enqueueServerBootConfigReferenci
233253
return EnqueueServerBootConfigsReferencingSecret(ctx, r.Client, secret)
234254
}
235255

256+
// registryHTTPStatusCode returns the HTTP status code from a containerd
257+
// remoteerrors.ErrUnexpectedStatus, and true if err is (or wraps) one.
258+
func registryHTTPStatusCode(err error) (int, bool) {
259+
var e remoteerrors.ErrUnexpectedStatus
260+
if errors.As(err, &e) {
261+
return e.StatusCode, true
262+
}
263+
return 0, false
264+
}
265+
266+
// isTransientNetworkError reports whether err is a transient network condition
267+
// worth retrying. Permanent DNS failures (NXDOMAIN) are excluded — those will
268+
// not resolve on retry and should be treated as hard errors.
269+
func isTransientNetworkError(err error) bool {
270+
if err == nil {
271+
return false
272+
}
273+
var dnsErr *net.DNSError
274+
if errors.As(err, &dnsErr) && dnsErr.IsNotFound {
275+
return false
276+
}
277+
var netErr net.Error
278+
if errors.As(err, &netErr) {
279+
return true
280+
}
281+
return errors.As(err, &dnsErr)
282+
}
283+
284+
// isTransientIOError reports whether err is a transient IO condition from a
285+
// registry read (connection closed mid-stream) that is worth retrying.
286+
func isTransientIOError(err error) bool {
287+
return errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF)
288+
}
289+
236290
// SetupWithManager sets up the controller with the Manager.
237291
func (r *ServerBootConfigurationHTTPReconciler) SetupWithManager(mgr ctrl.Manager) error {
238292
return ctrl.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)