Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl
}

if err := c.verifyReferencedSecretsImmutable(ctx, cos); err != nil {
var mutErr *mutableSecretError
if errors.As(err, &mutErr) {
if _, ok := errors.AsType[*mutableSecretError](err); ok {
// A confirmed mutable Secret requires user action (replacing the immutable Secret),
// which is not watched, so keep retrying so the revision can recover.
l.Error(err, "referenced Secret is mutable, marking revision not ready")
Expand All @@ -165,17 +164,15 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl

phases, currentPhases, opts, err := c.buildBoxcutterPhases(ctx, cos)
if err != nil {
var contentErr *referencedContentError
if errors.As(err, &contentErr) {
if _, ok := errors.AsType[*referencedContentError](err); ok {
// Invalid referenced Secret content (missing key or malformed manifest). The Secret
// is not watched and the ref is immutable, so keep retrying so the revision can
// recover once the Secret is replaced with valid content.
l.Error(err, "invalid referenced content, marking revision not ready")
markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced content is invalid: %v. Fix the Secret content.", err))
return ctrl.Result{RequeueAfter: validationRetryInterval}, nil
}
var cfgErr *configValidationError
if errors.As(err, &cfgErr) {
if _, ok := errors.AsType[*configValidationError](err); ok {
// Invalid revision spec; a spec edit (or a new revision) re-triggers reconciliation,
// so no periodic retry is needed.
l.Error(err, "invalid configuration, marking revision not ready")
Expand Down
6 changes: 2 additions & 4 deletions internal/operator-controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ func validateConfigWithSchema(configBytes []byte, schema map[string]any, install
// formatSchemaError converts JSON schema validation errors into user-friendly messages.
// If multiple validation errors exist, it combines them into a single error message.
func formatSchemaError(err error) error {
ve := &jsonschema.ValidationError{}
ok := errors.As(err, &ve)
ve, ok := errors.AsType[*jsonschema.ValidationError](err)
if !ok {
// Not a ValidationError, return as-is
// Caller (UnmarshalConfig) will add "invalid configuration:" prefix
Expand Down Expand Up @@ -401,8 +400,7 @@ func buildFieldPath(location string) string {

// formatUnmarshalError makes YAML/JSON parsing errors easier to understand.
func formatUnmarshalError(err error) error {
var typeErr *json.UnmarshalTypeError
if errors.As(err, &typeErr) {
if typeErr, ok := errors.AsType[*json.UnmarshalTypeError](err); ok {
if typeErr.Field == "" {
return errors.New("input is not a valid JSON object")
}
Expand Down
3 changes: 1 addition & 2 deletions internal/shared/util/error/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func ExtractTerminalReason(err error) (string, bool) {
}
// Unwrap the reconcile.TerminalError wrapper first
unwrapped := errors.Unwrap(err)
var terr *terminalErrorWithReason
if errors.As(unwrapped, &terr) {
if terr, ok := errors.AsType[*terminalErrorWithReason](unwrapped); ok {
return terr.reason, true
}
return "", false
Expand Down
3 changes: 1 addition & 2 deletions internal/shared/util/http/certlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func LogDockerCertificates(path string, log logr.Logger) {
// * false if no CertificateVerificationError is found
func LogCertificateVerificationError(err error, log logr.Logger) bool {
for err != nil {
var cvErr *tls.CertificateVerificationError
if errors.As(err, &cvErr) {
if cvErr, ok := errors.AsType[*tls.CertificateVerificationError](err); ok {
n := 1
for _, cert := range cvErr.UnverifiedCertificates {
log.Error(err, "unverified cert", "n", n, "subject", cert.Subject, "issuer", cert.Issuer, "DNSNames", cert.DNSNames, "serial", cert.SerialNumber)
Expand Down
3 changes: 1 addition & 2 deletions test/internal/e2e/platform/steps/demo_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func bash(ctx context.Context, script string) (string, error) {

if err != nil {
shared.Log().V(1).Info("Failed to run", "command", script, "stderr", stderr, "error", err)
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
exitErr.Stderr = stderrBuf.Bytes()
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/internal/e2e/steps/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ func Scenario(ctx context.Context) *World {
}

func stderrOutput(err error) string {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && exitErr != nil {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok && exitErr != nil {
return string(exitErr.Stderr)
}
return ""
Expand Down
6 changes: 2 additions & 4 deletions test/internal/e2e/steps/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ func K8sClient(ctx context.Context, args ...string) (string, error) {
logger.V(1).Info("Failed to run", "command", strings.Join(cmd.Args, " "), "stderr", stderrStr, "error", err)
// Inject stderr into ExitError so stderrOutput() can extract it.
// cmd.Run() with explicit cmd.Stderr does not populate ExitError.Stderr.
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
exitErr.Stderr = []byte(stderrStr)
}
}
Expand Down Expand Up @@ -270,8 +269,7 @@ func K8sCLIWithInput(ctx context.Context, yaml string, args ...string) (string,
stderrStr := stderrBuf.String()

if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
exitErr.Stderr = []byte(stderrStr)
}
}
Expand Down
Loading