Add internal/apistatus package with typed terminal errors#325
Open
felix-kaestner wants to merge 4 commits intomainfrom
Open
Add internal/apistatus package with typed terminal errors#325felix-kaestner wants to merge 4 commits intomainfrom
internal/apistatus package with typed terminal errors#325felix-kaestner wants to merge 4 commits intomainfrom
Conversation
internal/apistatus package with typed terminal errors
f21b349 to
8f3ca56
Compare
Introduces internal/apistatus, a leaf package that gives provider implementations a structured way to return non-retryable errors to controllers without coupling directly to reconcile.TerminalError. The package defines a Code enum (CodeInvalidArgument, CodeUnsupportedField, CodeFailedPrecondition) with String() and Valid() methods, a StatusError struct carrying a Code, an optional Message, and optional FieldViolations, and constructor functions for each code. StatusError implements Is() so that errors.Is can be used for type detection across error chains. WrapTerminalError wraps any error containing a *StatusError as a reconcile.TerminalError, leaving all other errors unchanged. conditions.FromError is extended to detect *StatusError before the existing gRPC status path, mapping the code to the condition Reason and the formatted message to the condition Message field. The stub internal/controllerutil package, which this supersedes, has been removed as no code imported it.
Each controller's Reconcile method now passes provider errors through apistatus.WrapTerminalError before returning them to controller-runtime. This ensures that any *StatusError returned by a provider implementation — signalling an unsupported field, an invalid argument, or an unmet precondition — suppresses retry backoff and is treated as a terminal error by the reconciler. Transient errors and Kubernetes-level precondition failures are returned unchanged, preserving existing retry behaviour for those cases.
Replace plain fmt.Errorf/errors.New calls in the NX-OS provider and name.go with typed apistatus errors so non-retryable failures surface as structured Kubernetes status conditions with a stable Reason field.
WrapTerminalError now only promotes CodeInvalidArgument and CodeUnsupportedField to reconcile.TerminalError. CodeFailedPrecondition errors pass through unchanged so controller-runtime exponential backoff can requeue them — the precondition (e.g. a BGP process) may become true on a future attempt. Update docs and tests to reflect the new behaviour.
8f3ca56 to
d9139f1
Compare
Merging this branch changes the coverage (2 decrease, 2 increase)
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces internal/apistatus, a package that gives provider implementations a structured way to return non-retryable errors to controllers without coupling directly to reconcile.TerminalError.
The package defines a Code enum (CodeInvalidArgument, CodeUnsupportedField, CodeFailedPrecondition) with String() and Valid() methods, a StatusError struct carrying a Code, an optional Message, and optional FieldViolations, and constructor functions for each code. StatusError implements Is() so that errors.Is can be used for type detection across error chains. WrapTerminalError wraps any error containing a *StatusError as a reconcile.TerminalError, leaving all other errors unchanged.
conditions.FromError is extended to detect *StatusError before the existing gRPC status path, mapping the code to the condition Reason and the formatted message to the condition Message field.
The stub internal/controllerutil package, which this supersedes, has been removed as no code imported it.