Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simpliflies handling of k8s not-found errors #898

Merged

Conversation

bartoszmajsak
Copy link
Contributor

@bartoszmajsak bartoszmajsak commented Mar 6, 2024

Instead of

if apierrs.IsNotFound(err) {
	return nil
}
return err

we can use

return client.IgnoreNotFound(err)

@bartoszmajsak bartoszmajsak requested review from zdtsw and VaishnaviHire and removed request for etirelli and andrewballantyne March 6, 2024 18:37
@openshift-ci openshift-ci bot added the lgtm label Mar 7, 2024
Copy link

openshift-ci bot commented Mar 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zdtsw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Mar 7, 2024
@zdtsw
Copy link
Member

zdtsw commented Mar 7, 2024

we have a bunch of in the upgrade.go,
intended to keep them?

also some are actually done as
if k8serrors.IsNotFound(err) { ... }
should be converted too?

@bartoszmajsak
Copy link
Contributor Author

bartoszmajsak commented Mar 7, 2024

we have a bunch of in the upgrade.go, intended to keep them?

also some are actually done as if k8serrors.IsNotFound(err) { ... } should be converted too?

I looked at those too, but they're are a bit different

Multierrors

if apierrs.IsNotFound(err) {
fmt.Printf("Could not find %s in namespace %s\n", item.GetName(), namespace)
} else {
multiErr = multierror.Append(multiErr, err)
}

I can change this as part of this PR. Append(err error, errs ...error) ignores any nils passed as errs, so that's easy. But we still might want to log it? Or should I skip log message for this? What is the value of this information @zdtsw?

Wrapping errors

if apierrs.IsNotFound(err) {
// If no Crd found, return, since its a new Installation
// return empty list
return nil
}
return fmt.Errorf("error retrieving kfdef CRD : %w", err)

This needs some wrapper func as fmt.Errorf does not seem to ignore nil errors - it's simply constructing the message with nil struct used for %w substitution.

We are using github.com/pkg/errors in a few places and errors.Wrap could handle that, but I think we should first discuss how to uniformly handle errors across the entire code base.

@VaishnaviHire VaishnaviHire merged commit a5e512a into opendatahub-io:incubation Mar 8, 2024
6 of 7 checks passed
zdtsw pushed a commit to zdtsw-forking/rhods-operator that referenced this pull request Mar 15, 2024
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants