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

errors.IsNotFound not working correctly with client-go #89

Closed
krmayankk opened this issue Feb 3, 2017 · 8 comments
Closed

errors.IsNotFound not working correctly with client-go #89

krmayankk opened this issue Feb 3, 2017 · 8 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@krmayankk
Copy link

I am using client-go by doing the following imports:-

"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/client-go/pkg/api/v1"

When i query a deployment which doesn't exist, i see the following in the logs:-

I0202 10:13:25.598285       1 round_trippers.go:417] GET https://<some ip>/apis/extensions/v1beta1/namespaces/e2e-mayank-kumar-csc-sam/deployments/default 404 Not Found in 109 milliseconds

404 tells me its not found

I0202 10:13:25.598981       1 rollout.go:138] error found deployments.extensions "default" not found
I0202 10:13:25.599018       1 rollout.go:141] not not found deployments.extensions "default" not found

where the exact err i get from the client-go api is deployments.extensions "default" not found

When i use errors.IsNotFound(err) from the apimachinery, the check fails and it doesn't identify this error as not found error.
Am i missing anything ?

@ericchiang
Copy link
Contributor

@krmayankk this is likely due to version skew between your version of apimachinery and client-go. Please take a look at this comment here: #83 (comment)

We strongly recommend using a tool like glide to manage your dependencies: https://github.com/Masterminds/glide

Does this code if you do that?

@krmayankk
Copy link
Author

krmayankk commented Feb 15, 2017

I am doing a go get, and using glide to get dependencies for my app. But i am not using a specific branch of client-go. Should i be using a specific branch of client-go @ericchiang ?

@ericchiang
Copy link
Contributor

@krmayankk you should be using glide to manage client-go. client-go is sensitive to the versions of the packages it imports. However client-go only recently started pinning k8s.io/apimachinery #83 (comment) so you'll need to use a recent SHA.

@WilliamDenniss WilliamDenniss added the kind/support Categorizes issue or PR as a support question. label Mar 15, 2017
@danielwhatmuff
Copy link

danielwhatmuff commented Mar 26, 2019

I am using go deps and have the same issue. All expected errors such as AlreadyExists and NotFound don't get detected by the functions which should return true.

My imports...

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
v1 "k8s.io/client-go/pkg/api/v1"

Example...

	namespace, err := clientset.CoreV1().Namespaces().Create(&v1.Namespace{
		ObjectMeta: v1.ObjectMeta{
			Name: namespaceName,
		},
	})
	if errors.IsAlreadyExists(err) {
                // This doesnt ever happen even if it does already exist
		log.Printf("Already exists")
	}

@Asgoret
Copy link

Asgoret commented Jul 16, 2020

errors.IsAlreadyExists(err) doesn't work at all. Is there any abstract workaround hot to check is object exist or not?

@franpog859
Copy link

Is there any issue regarding the errors.IsAlreadyExists(err) mentioned by @Asgoret ? Does anyone work on that?

@scbizu
Copy link

scbizu commented Feb 25, 2022

For those who encounter with this issue , you can check whether your k8s version is equal to your client-go's version .

synarete added a commit to synarete/samba-operator that referenced this issue May 18, 2023
When doing reconcile logic of Get-or-Create for OpenShift's elements,
treat AlreadyExists error as transient error and just Get the element
once again from the API server. This may happen in cases where there is
a skew between your apimachinery and client-go versions[1].

[1] kubernetes/client-go#89

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
anoopcs9 pushed a commit to synarete/samba-operator that referenced this issue May 23, 2023
When doing reconcile logic of Get-or-Create for OpenShift's elements,
treat AlreadyExists error as transient error and just Get the element
once again from the API server. This may happen in cases where there is
a skew between your apimachinery and client-go versions[1].

[1] kubernetes/client-go#89

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
mergify bot pushed a commit to samba-in-kubernetes/samba-operator that referenced this issue May 23, 2023
When doing reconcile logic of Get-or-Create for OpenShift's elements,
treat AlreadyExists error as transient error and just Get the element
once again from the API server. This may happen in cases where there is
a skew between your apimachinery and client-go versions[1].

[1] kubernetes/client-go#89

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
@vsoch
Copy link

vsoch commented Sep 23, 2023

For those who encounter with this issue , you can check whether your k8s version is equal to your client-go's version .

Can you give an example of what you mean? I'm running into this issue (still haven't fixed it) and it's not clear if you mean the Kubernetes cluster version (which I largely can't control which version someone is using for my operator) or a package I'm using. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

8 participants