-
Notifications
You must be signed in to change notification settings - Fork 2.3k
plugin/kubernetes: Handle endpoint tombstones #3887
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
Conversation
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
thanks @chrisohaver . Was this knowable at the time when we did the refactoring to make the memory go down? |
Looks like this may have been an issue since CoreDNS 1.2.3, when API object trimming was introduced. I would not recommend reverting back to a version before 1.2.3 to avoid this bug. This bug should be relatively uncommon to encounter, however some things that could increase occurrence:
|
Theoretically? Probably.
Makes sense. I'll add it in |
plugin/kubernetes/object/endpoint.go
Outdated
@@ -44,10 +44,10 @@ type EndpointPort struct { | |||
func EndpointsKey(name, namespace string) string { return name + "." + namespace } | |||
|
|||
// ToEndpoints converts an api.Endpoints to a *Endpoints. | |||
func ToEndpoints(obj interface{}) (*api.Endpoints, *Endpoints) { | |||
func ToEndpoints(obj interface{}) (*api.Endpoints, interface{}) { |
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.
This is kind of a weird change. I think it would be more readable if we changed the signature to func ToEndpoints(*api.Endpoints) (*Endpoints)
, do the casting in the caller, and just not call it if obj
is not a *api.Endpoints
.
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.
Assuming as I believe ToEndpoints
is only called once anyway.
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.
yeah - i was just making this change. :)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Codecov Report
@@ Coverage Diff @@
## master #3887 +/- ##
==========================================
- Coverage 56.78% 56.75% -0.04%
==========================================
Files 222 222
Lines 11305 11316 +11
==========================================
+ Hits 6420 6422 +2
- Misses 4391 4398 +7
- Partials 494 496 +2
Continue to review full report at Codecov.
|
plugin/kubernetes/object/endpoint.go
Outdated
return nil, nil | ||
} | ||
|
||
func ToEndpoints(end *api.Endpoints) (*api.Endpoints, *Endpoints) { |
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 still don't get why we pass in end
and then just return it.
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 mean, why do we need to return it?
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 mean, why do we need to return it?
You're right. I should do more refactoring here...
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
I've further jostled the code around to reduce verbosity and scope of changes. |
Many controllers have examples of handling this scenario |
Yes, I have essentially based this change on such examples. |
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
The latest iteration moves the delta object inspection to inside the switch cases. I think it reads better. Note that now it sends the (possibly outdated) endpoints object from the tombstone to |
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
if err := clientState.Delete(tombstone); err != nil { | ||
return err | ||
} | ||
apiEndpoints, ok = tombstone.Obj.(*api.Endpoints) |
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 fully understand this, why do we need this part if we already deleted it with the tombstone?
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.
It hasn't been deleted yet at this point. It gets deleted later with clientState.Delete(obj)
. If we don't call clientState.Delete
, it will remain in the cache.
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.
So what does clientState.Delete(tombstone)
do?
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.
arg! - I left that in by accident. Thanks for catching that. I'll remove it and run the test again.
Not sure why I have not seen this for Service objects in my tests - perhaps the API doesn't send tombstones for Service objects, just the endpoints. I have not tested Pods, but I suspect we'll see this issue there too. But I want to get this PR squared away in a state that is acceptable before replicating it to Pods and Services. |
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Ok, that looks better! |
Thanks for your work on that @chrisohaver! This fix will make live easier for us, we recently saw this issue a lot on clusters running in Azure VMs. |
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Bug 1868315: Back port Handle endpoint tombstones (upstream coredns#3887)
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
…-to-release-4.5 [release-4.5] Bug 1869309: Back port Handle endpoint tombstones (upstream coredns#3887)
…-to-release-4.4 [release-4.4] Bug 1869310: Back port Handle endpoint tombstones (upstream coredns#3887)
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* check for nil Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * handle tombstone Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move casting to caller. add comments. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more sanding Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * more scrubbing Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move object unwraping to switch cases Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * oops remove debug Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove cruft Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
1. Why is this pull request needed and what does it do?
ToEndpoints()
conversion was filtering out Endpoint deletion tombstones (where the object in the event is not an*api.Endpoint
, but rather acache.DeletedFinalStateUnknown
). The tombstones are essentially indicators that the Endpoint was deleted, without a containing a full copy of the Endpoints object - just a key value.ToEndpoints()
was returning a nil*object.Endpoints
when these were encountered, which caused failures downstream when deleting from the index.This fix is allows
ToEndpoints()
to pass the tombstones through, so they can be deleted properly from theclientState
.2. Which issues (if any) are related?
Fixes #3860
3. Which documentation changes (if any) need to be made?
none
4. Does this introduce a backward incompatible change or deprecation?
no