consul-api-gateway icon indicating copy to clipboard operation
consul-api-gateway copied to clipboard

Parsing Resource Version Is Not Allowed

Open stevekuznetsov opened this issue 2 years ago • 3 comments

Overview of the Issue

The Kubernetes API explicitly disallows parsing the metadata.resourceVersion field on an object as an integer. This project, however, does so as of this commit: https://github.com/hashicorp/consul-api-gateway/pull/26/commits/cb0486e386552b24f74a457df00680785d75a2b7

During a review of code that would be affected by non-numerical resourceVersions, I came upon this code. I'm hoping to better understand what this codebase is using the parsing logic for and if there are other means to that end without using non-supported API behavior. I can see that uses of the parsing seem to all be in precondition functions passed to Upsert* methods on a store. This looks analogous to the resource version precondition provided by the Kubernetes API server, but the only implementation of the store I found was an in-memory one here - so I'm not entirely sure how the Kubernetes client and server get involved here.

stevekuznetsov avatar Nov 28 '22 16:11 stevekuznetsov

Hi @stevekuznetsov , thanks for reporting!

Personally, I wasn't aware of that note RE: metadata.resourceVersion. We're just parsing as an integer today to guard against incorrectly updating to an older version; however, it looks like the watcher probably handles that for us. If that's the case, we can just do an equality check as mentioned by the docs that you linked.

nathancoleman avatar Nov 29 '22 16:11 nathancoleman

Gotcha - if you could help me understand the in-memory storage you have and when/if/how it gets synced to a running k8s API server, I could help fix it!

stevekuznetsov avatar Nov 29 '22 16:11 stevekuznetsov

@andrewstucki provided some additional context over on my PR https://github.com/hashicorp/consul-api-gateway/pull/467#discussion_r1036280221

nathancoleman avatar Nov 30 '22 17:11 nathancoleman