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

Return api/errors instead of raw etcd errors #10246

Merged
merged 1 commit into from
Jun 30, 2015

Conversation

nikhiljindal
Copy link
Contributor

For #10064

Wrapping etcd errors in errors.NewInternalError(err)

@nikhiljindal
Copy link
Contributor Author

cc @bgrant0607 @lavalamp

@k8s-bot
Copy link

k8s-bot commented Jun 23, 2015

GCE e2e build/test failed for commit d3eca56f71dc15684bce5f3fab767dfd99b8d659.

@k8s-bot
Copy link

k8s-bot commented Jun 23, 2015

GCE e2e build/test passed for commit a43f8b3c68b0bd45551fd40be5d658bcfc040894.

@k8s-bot
Copy link

k8s-bot commented Jun 24, 2015

GCE e2e build/test failed for commit 5a29a715e117630079e90487f7ae5d5e1ded4dd9.

@j3ffml j3ffml added this to the v1.0-candidate milestone Jun 24, 2015
@j3ffml j3ffml added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 24, 2015
@k8s-bot
Copy link

k8s-bot commented Jun 24, 2015

GCE e2e build/test failed for commit fa1f8d7aba7777d5e456af6feed93b77a59b3ca7.

@k8s-bot
Copy link

k8s-bot commented Jun 24, 2015

GCE e2e build/test failed for commit f609e8f6762ca581b6478e6db4dcf5f25166775d.

@nikhiljindal
Copy link
Contributor Author

Adding to v1 since the associated bug is marked v1.

@nikhiljindal nikhiljindal modified the milestones: v1.0, v1.0-candidate Jun 25, 2015
@k8s-bot
Copy link

k8s-bot commented Jun 25, 2015

GCE e2e build/test failed for commit f9eaf959d03e1570ddcc6f95c749bff0bfd063ea.

@@ -31,7 +30,7 @@ import (
)

var (
errorUnableToAllocate = errors.New("unable to allocate")
errorUnableToAllocate = k8serr.NewInternalError(fmt.Errorf("unable to allocate"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer errors.New if you don't have parameters to pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will still be converted to an InternalError, even if we do not generate one here.
The advantage of generating an InternalError here is that we can then compare that the returned error == errorUnableToAllocate.
Otherwise, we will have to do
error.Error() == NewInternalError(errorUnableToAllocate).Error()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that this error shouldn't ever be returned to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@k8s-bot
Copy link

k8s-bot commented Jun 25, 2015

GCE e2e build/test failed for commit f9eaf959d03e1570ddcc6f95c749bff0bfd063ea.

@k8s-bot
Copy link

k8s-bot commented Jun 25, 2015

GCE e2e build/test failed for commit f9eaf959d03e1570ddcc6f95c749bff0bfd063ea.

@nikhiljindal
Copy link
Contributor Author

Rebased and updated code as per comments.

@k8s-bot
Copy link

k8s-bot commented Jun 29, 2015

GCE e2e build/test failed for commit 26d87b37379626554171907c32d53f58ad6aaabc.

@k8s-bot
Copy link

k8s-bot commented Jun 29, 2015

GCE e2e build/test passed for commit 4b7f7ce.

@bgrant0607
Copy link
Member

Good enough for now. LGTM.

@bgrant0607 bgrant0607 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 29, 2015
@bgrant0607 bgrant0607 assigned lavalamp and unassigned bgrant0607 Jun 29, 2015
@bgrant0607
Copy link
Member

Re-assigned to @lavalamp for another LGTM

@lavalamp
Copy link
Member

lgtm

zmerlynn added a commit that referenced this pull request Jun 30, 2015
Return api/errors instead of raw etcd errors
@zmerlynn zmerlynn merged commit a902a2f into kubernetes:master Jun 30, 2015
@smarterclayton
Copy link
Contributor

I missed the review of this but this is a pretty substantial change to the intent of the etcd methods - those were transform only. This change prevents other code from further refining those errors. I would have been a -1 on this - we should be handling non API errors higher in the stack, or via a different method. We use this method to filter out known errors, not wrap all errors.

@nikhiljindal
Copy link
Contributor Author

Sorry about that @smarterclayton I thought that I had cc'd you on this but looks like I didnt.
Does this break Openshift? Do you want me to revert the PR?

Can you give an example where other code wants to refine the etcd error? Are you talking about refining an etcd error into another etcd error?
Since the InterpretError functions were already converting etcd errors to apierrors, it seemed that thats the intent of those functions. If thats not the case, then we can introduce a new EtcdToApiError() function, that should be called just before returning from the registry functions (ex Update function here: https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/registry/generic/etcd/etcd.go#L267). This function will ensure that we are not returning raw etcd errors above the registry.
The etcd errors can be refined before this function is called. Interpret
Error functions will not convert etcd errors to api errors.

Does that sound fine?

@bgrant0607
Copy link
Member

Let's revert and figure out the right solution.

@smarterclayton
Copy link
Contributor

I don't know that we need to revert right now.

Basically, the original idea was that those methods would filter known
errors into a transformed error - otherwise it would leave the error
alone. This would allow you to safely wrap etcd calls with the method, but
if you had a method that called etcd and also returned non etcd errors
(like a typed error from etcd helper that was ErrStopped or
ErrExplicitQuit) you could invoke InterpretError first, then check for
those typed errors. My concern would be any code that made that assumption
in Kube, as well as OpenShift. Let me do a quick scan - in the event that
we were not doing that anymore, I think this change is probably safe - if
in the future, we need to do that, we dan check for typed errors first.

At one point we called this method before a switch somewhere (switch
InterpretEtcdErr(err)) but that may have gone away as we refactored the
etcd libraries.

On Jun 30, 2015, at 9:28 PM, Nikhil Jindal notifications@github.com wrote:

Sorry about that @smarterclayton https://github.com/smarterclayton I
tought that I had cc'd you on this but looks like I didnt.
Does this break Openshift? Do you want me to revert the PR?

Can you give an example where other code wants to refine the etcd error?
Are you talking about refining an etcd error into another etcd error?
Since the Interpret
_Error functions were already converting etcd errors to apierrors, it
seemed that thats the intent of those functions. If thats not the case,
then we can introduce a new EtcdToApiError() function, that should be
called just before returning from the registry functions (ex Update
function here:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/registry/generic/etcd/etcd.go#L267
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/registry/generic/etcd/etcd.go#L267).
This function will ensure that we are not returning raw etcd errors above
the registry. The etcd errors can be refined before this function is
called. Interpret_Error functions will not convert etcd errors to api
errors.

Does that sound fine?


Reply to this email directly or view it on GitHub
#10246 (comment)
.

@bgrant0607
Copy link
Member

We should document that, and ideally test it. It was non-obvious.

@smarterclayton
Copy link
Contributor

It's broken in BindingREST assignPod:

err = etcderr.InterpretGetError(err, "pod", podID)
err = etcderr.InterpretUpdateError(err, "pod", podID)

and in generic/etcd Create():

err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)

On Wed, Jul 1, 2015 at 1:04 AM, Brian Grant notifications@github.com
wrote:

We should document that, and ideally test it. It was non-obvious.


Reply to this email directly or view it on GitHub
#10246 (comment)
.

Clayton Coleman | Lead Engineer, OpenShift

@smarterclayton
Copy link
Contributor

Also in generic/etcd Update():

if creating {
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
} else {
err = etcderr.InterpretUpdateError(err, e.EndpointName, name)
}

On Wed, Jul 1, 2015 at 10:11 AM, Clayton Coleman ccoleman@redhat.com
wrote:

It's broken in BindingREST assignPod:

err = etcderr.InterpretGetError(err, "pod", podID)
err = etcderr.InterpretUpdateError(err, "pod", podID)

and in generic/etcd Create():

err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)

On Wed, Jul 1, 2015 at 1:04 AM, Brian Grant notifications@github.com
wrote:

We should document that, and ideally test it. It was non-obvious.


Reply to this email directly or view it on GitHub
#10246 (comment)
.

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

@smarterclayton
Copy link
Contributor

I don't see any other obvious uses of it in Kube.

On Wed, Jul 1, 2015 at 10:12 AM, Clayton Coleman ccoleman@redhat.com
wrote:

Also in generic/etcd Update():

if creating {
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
} else {
err = etcderr.InterpretUpdateError(err, e.EndpointName, name)
}

On Wed, Jul 1, 2015 at 10:11 AM, Clayton Coleman ccoleman@redhat.com
wrote:

It's broken in BindingREST assignPod:

err = etcderr.InterpretGetError(err, "pod", podID)
err = etcderr.InterpretUpdateError(err, "pod", podID)

and in generic/etcd Create():

err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)

On Wed, Jul 1, 2015 at 1:04 AM, Brian Grant notifications@github.com
wrote:

We should document that, and ideally test it. It was non-obvious.


Reply to this email directly or view it on GitHub
#10246 (comment)
.

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

@smarterclayton
Copy link
Contributor

I do think it's valuable for there to be a "turn etcd error into api error
for the given method type" - I'd like to have it be clear there is a catch
all.

On Wed, Jul 1, 2015 at 10:12 AM, Clayton Coleman ccoleman@redhat.com
wrote:

I don't see any other obvious uses of it in Kube.

On Wed, Jul 1, 2015 at 10:12 AM, Clayton Coleman ccoleman@redhat.com
wrote:

Also in generic/etcd Update():

if creating {
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
} else {
err = etcderr.InterpretUpdateError(err, e.EndpointName, name)
}

On Wed, Jul 1, 2015 at 10:11 AM, Clayton Coleman ccoleman@redhat.com
wrote:

It's broken in BindingREST assignPod:

err = etcderr.InterpretGetError(err, "pod", podID)
err = etcderr.InterpretUpdateError(err, "pod", podID)

and in generic/etcd Create():

err = etcderr.InterpretCreateError(err, e.EndpointName, name)
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)

On Wed, Jul 1, 2015 at 1:04 AM, Brian Grant notifications@github.com
wrote:

We should document that, and ideally test it. It was non-obvious.


Reply to this email directly or view it on GitHub
#10246 (comment)
.

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

nikhiljindal added a commit to nikhiljindal/kubernetes that referenced this pull request Jul 1, 2015
This reverts commit a902a2f, reversing
changes made to 7df8d76.
@nikhiljindal
Copy link
Contributor Author

Thanks for those pointers @smarterclayton.
I am reverting this PR in #10632. Will send another PR with better changes.

zmerlynn added a commit that referenced this pull request Jul 1, 2015
Revert "Merge pull request #10246 from nikhiljindal"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants