-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Handle DeletedFinalStateUnknown in k8s OnDelete #23419
Conversation
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Pinging @elastic/integrations (Team:Integrations) |
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
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.
Looks good, but maybe we should do it at the watcher level, let me know what you think.
service, isNode := obj.(*kubernetes.Service) | ||
// We can get DeletedFinalStateUnknown instead of *kubernetes.Service here and we need to handle that correctly. #23385 | ||
if !isNode { |
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.
service, isNode := obj.(*kubernetes.Service) | |
// We can get DeletedFinalStateUnknown instead of *kubernetes.Service here and we need to handle that correctly. #23385 | |
if !isNode { | |
service, isService := obj.(*kubernetes.Service) | |
// We can get DeletedFinalStateUnknown instead of *kubernetes.Service here and we need to handle that correctly. #23385 | |
if !isService { |
node, isNode := obj.(*kubernetes.Node) | ||
// We can get DeletedFinalStateUnknown instead of *kubernetes.Node here and we need to handle that correctly. #23385 | ||
if !isNode { | ||
deletedState, ok := obj.(cache.DeletedFinalStateUnknown) |
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 exposing details from the watcher and the client cache in the handlers. DeleteFinalStateUnknown
happens when a informer misses the delete event, and it sees in a resync that an object is not there anymore. As it doesn't know what was the final state, it includes the last known state, that in our case is probably enough to remove configurations.
Also, handling this in the handler level forces us to repeat some code in each handler we add.
Wdyt about trying to handle it in the watcher directly?
For example watcher.enqueue()
already does something related to DeletedFinalStateUnknown
when it calls cache.DeletionHandlingMetaNamespaceKeyFunc
. We could maybe modify enqueue
to do something like this:
func (w *watcher) enqueue(obj interface{}, state string) {
// DeletionHandlingMetaNamespaceKeyFunc that we get a key only if the resource's state is not Unknown.
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
return
}
if deleted, ok := obj.(cache.DeletedFinalStateUnknown); ok {
w.logger.Debugf(.....)
obj = deleted.Obj
}
w.queue.Add(&item{key, obj, state})
}
Signed-off-by: chrismark <[email protected]>
It is better at watcher level yes, thank you! I moved the check there. |
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.
Looks good, thanks! Would it be possible to add some test for this?
if deleted, ok := obj.(cache.DeletedFinalStateUnknown); ok { | ||
w.logger.Debugf("Enqueued DeletedFinalStateUnknown contained object: %+v", deleted.Obj) | ||
obj = deleted.Obj | ||
} |
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.
Would it be possible to add some test?
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 afraid it is not possible right now since we need to trigger the watcher with an actual event and even the fake k8s client cannot achieve that.
(cherry picked from commit 6d43535)
(cherry picked from commit 6d43535)
What does this PR do?
We can get
DeletedFinalStateUnknown
instead of *kubernetes.Resource onOnDelete
method ofResourceEventer
and we need to handle that correctly.Why is it important?
Without this Beats will fail with
panic
.Related issues