-
Notifications
You must be signed in to change notification settings - Fork 39.4k
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
Fix incorrectly set resource version in List #64150
Fix incorrectly set resource version in List #64150
Conversation
[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete Action required: This pull request requires label changes. If the required changes are not made within 3 days, the pull request will be moved out of the v1.11 milestone. kind: Must specify exactly one of |
if err != nil { | ||
return err | ||
} | ||
if len(getResp.Kvs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning early with return s.versioner.UpdateList(listObj, uint64(getResp.Header.Revision), "")
means a smaller diff and makes it clearer the exceptional case is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this comment - our goal shouldn't be having as small diff as possible.
I really think that with this change the code is much more understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our goal shouldn't be having as small diff as possible
I assume we want to backport this... that was my thought about minimizing diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - I think we want to backport it.
but, it won't generate conflict on 1.10 and 1.9 and I think it's more important to have this code cleaner than to avoid conflict in 1.8. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaner is in the eye of the beholder, but I don't feel that strongly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - that's true.
But if you don't feel very strongly about this, I would prefer leaving as is.
what did the v2 store do? would like to see a test for this against the etcd3, etcd2, and cacher store impls |
872296b
to
6b9383d
Compare
I added tests. @liggitt - PTAL |
@@ -347,6 +347,7 @@ func (h *etcdHelper) GetToList(ctx context.Context, key string, resourceVersion | |||
metrics.RecordEtcdRequestLatency("get", getTypeName(listPtr), startTime) | |||
if err != nil { | |||
if etcdutil.IsEtcdNotFound(err) { | |||
// TODO: ResourceVersion should be set here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a not found case, the current index comes back with the error:
kubernetes/vendor/github.com/coreos/etcd/client/keys.go
Lines 57 to 62 in e85b81b
type Error struct { | |
Code int `json:"errorCode"` | |
Message string `json:"message"` | |
Cause string `json:"cause"` | |
Index uint64 `json:"index"` | |
} |
$ curl http://localhost:2379/v2/keys/foo -v
* Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 2379 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 2379 (#0)
> GET /v2/keys/foo HTTP/1.1
> Host: localhost:2379
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< X-Etcd-Cluster-Id: cdf818194e3a8c32
< X-Etcd-Index: 11
< Date: Tue, 22 May 2018 15:08:02 GMT
< Content-Length: 70
<
{"errorCode":100,"message":"Key not found","cause":"/foo","index":11}
note the index matches the X-Etcd-Index
header, which is what is hoisted into response.Index in success cases:
kubernetes/vendor/github.com/coreos/etcd/client/keys.go
Lines 660 to 674 in e85b81b
func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) { | |
var res Response | |
err := codec.NewDecoderBytes(body, new(codec.JsonHandle)).Decode(&res) | |
if err != nil { | |
return nil, ErrInvalidJSON | |
} | |
if header.Get("X-Etcd-Index") != "" { | |
res.Index, err = strconv.ParseUint(header.Get("X-Etcd-Index"), 10, 64) | |
if err != nil { | |
return nil, err | |
} | |
} | |
res.ClusterID = header.Get("X-Etcd-Cluster-ID") | |
return &res, nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's a test issue, but in the test that I added, I'm getting "response=nil" in this case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt - what etcd version you used in your experiment? Maybe that matters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually - this seem to be an issue of etcd client library:
https://github.com/kubernetes/kubernetes/blob/master/vendor/github.com/coreos/etcd/client/keys.go#L654
In case of status different than OK and Created (so 200 and 201), the returned response is nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting "response=nil" in this case...
yes. the index is in the error object:
kubernetes/vendor/github.com/coreos/etcd/client/keys.go
Lines 57 to 62 in e85b81b
type Error struct { | |
Code int `json:"errorCode"` | |
Message string `json:"message"` | |
Cause string `json:"cause"` | |
Index uint64 `json:"index"` | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah ok - thanks. It works now. PTAL
6b9383d
to
6a470d1
Compare
etcd v2 should also be fixed now. PTAL |
@@ -347,7 +347,8 @@ func (h *etcdHelper) GetToList(ctx context.Context, key string, resourceVersion | |||
metrics.RecordEtcdRequestLatency("get", getTypeName(listPtr), startTime) | |||
if err != nil { | |||
if etcdutil.IsEtcdNotFound(err) { | |||
return nil | |||
etcdErr := err.(etcd.Error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe be a little more fault tolerant... do a conditional cast, and only call UpdateList if the cast is successful and etcdErr.Index != 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough - fixed.
6a470d1
to
a3578c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt - PTAL
@@ -347,7 +347,8 @@ func (h *etcdHelper) GetToList(ctx context.Context, key string, resourceVersion | |||
metrics.RecordEtcdRequestLatency("get", getTypeName(listPtr), startTime) | |||
if err != nil { | |||
if etcdutil.IsEtcdNotFound(err) { | |||
return nil | |||
etcdErr := err.(etcd.Error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough - fixed.
if err != nil { | ||
return err | ||
} | ||
if len(getResp.Kvs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - that's true.
But if you don't feel very strongly about this, I would prefer leaving as is.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, wojtek-t 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 |
/test pull-kubernetes-e2e-kops-aws |
Automatic merge from submit-queue (batch tested with PRs 64102, 63303, 64150, 63841). If you want to cherry-pick this change to another branch, please follow the instructions here. |
/lgtm |
Fix : #64147