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

Usage of client-go's discovery.ErrGroupDiscoveryFailed breaks apimachinery errors.IsNotFound #2354

Closed
saschagrunert opened this issue May 26, 2023 · 5 comments · Fixed by #2472
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release.

Comments

@saschagrunert
Copy link
Member

The introduction of the error conversion in controller-runtime v0.15.0:

for _, version := range versions {
groupVersion := schema.GroupVersion{Group: groupName, Version: version}
apiResourceList, err := m.client.ServerResourcesForGroupVersion(groupVersion.String())
if err != nil {
failedGroups[groupVersion] = err
}
if apiResourceList != nil {
// even in case of error, some fallback might have been returned.
groupVersionResources[groupVersion] = apiResourceList
}
}
if len(failedGroups) > 0 {
return nil, &discovery.ErrGroupDiscoveryFailed{Groups: failedGroups}
}

breaks the use case of checking available APIs via k8s.io/apimachinery/pkg/api/errors.IsNotFound:

https://github.com/kubernetes/kubernetes/blob/2e306e9632b13a3c1530a7e7ddf52a50f4741523/staging/src/k8s.io/apimachinery/pkg/api/errors/errors.go#L525-L536

Reason is the error conversion, which now needs a workaround like this:
https://github.com/kubernetes-sigs/security-profiles-operator/pull/1710/files#diff-fb01936f787b03e615f35a185799e91ec41896c1fcae0991db3a24137f21cf54R78-R87

Do we want to provide an additional API or something similar to make availability checks simpler?

@alvaroaleman
Copy link
Member

@Fedosin What is the reason for using discovery.ErrGroupDiscoveryFailed rather than just passing on the error we got from ServerResourcesForGroupVersion?

@ebensh
Copy link

ebensh commented Aug 22, 2023

@Fedosin What is the reason for using discovery.ErrGroupDiscoveryFailed rather than just passing on the error we got from ServerResourcesForGroupVersion?

Is this an approach we can take as a fix / patch? I understand that the v0.15.0 contained several changes that had the potential to break us, but detecting whether resources exist is a common operation for controllers to perform, and breaking the pattern of detecting whether a resource exists or not is a problem.

@dmitri-d
Copy link

Just encountered this issue as well.

@porridge
Copy link
Contributor

porridge commented Sep 6, 2023

Note that this also breaks use of k8s.io/apimachinery/pkg/api/meta.IsNoMatchError on the resulting error.

I wonder if this will work:
/kind bug
/kind regression

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. labels Sep 6, 2023
@porridge
Copy link
Contributor

porridge commented Sep 6, 2023

I've taken a stab at fixing this in #2472
Please take a look @alvaroaleman @Fedosin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release.
Projects
None yet
6 participants