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

Conditions on podupdater functions of kubernetes autodiscovery #71

Merged
merged 33 commits into from
Jan 12, 2024

Conversation

gizas
Copy link
Contributor

@gizas gizas commented Dec 13, 2023

  • Enhancement

Proposed commit message

  • WHAT: Update the PodUpdater fucntion with additonal checks before actaully triggering Pod watcher restarts
  • WHY: There where node and namespace events that dont always inlcude Metadata changes. We want only update events that change labels and annotations of node and namespace to trigger pod updates. This leads to bettwr management of watchers

How to test this PR locally

See info elastic/beats#37338

Related issues

Copy link

@constanca-m constanca-m left a comment

Choose a reason for hiding this comment

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

I left this comment elastic/beats#37338 (comment) on the issue. It seems to work, so I am approving it.

@@ -134,19 +138,25 @@ type podUpdaterStore interface {
List() []interface{}
}

type UpdateWatcher interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

@gizas could you please add Doc comments for the exported type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me know if ok?

kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved

// Slice includes the old and new version of caching object that changes in the current update event. slice[0] is the old version and slice[1] the new updated one
slice := n.nodewatcher.Deltaobjects()
cachednodeold, ok := slice[0].(*Node)
Copy link
Contributor

@tetianakravchenko tetianakravchenko Jan 2, 2024

Choose a reason for hiding this comment

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

slice[1] seems to be not used and instead the old version (slice[0]) is compared with the obj.(*Node) passed to the OnUpdate. The same for the namespace
Do we actually need the updated version?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get the meaning of checking the current namespace name is the same as the cached version. Maybe you can clarify that in a comment. Should we instead check the new name has not changed compared to the cached version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gsantoro the one you call "current" is the one that triggers the OnUpdate. So still the "current" is not saved in the cache until we make the checks. The actual checks to make the replacement is the ones that come from isEqualMetadata function. And if we have diffrences in metadata we proceed with the Pod updates

FYI : The check we make ns.Name == cachednamespaceold.Name is just for safety in order to make sure that we talk for the same object in cache

@tetianakravchenko indeed only the old version is needed (former slice[0]). I initially thought the wather to rerutn only the old version. Then I changed my mind that probably we will need in the future the deltas if we need to make more checks. I dont think that it is a big diff to return both? But tbh I have not tested the memory in scale here

Copy link
Contributor

@tetianakravchenko tetianakravchenko Jan 9, 2024

Choose a reason for hiding this comment

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

@tetianakravchenko indeed only the old version is needed (former slice[0]). I initially thought the wather to rerutn only the old version. Then I changed my mind that probably we will need in the future the deltas if we need to make more checks. I don't think that it is a big diff to return both? But tbh I have not tested the memory in scale here

since obj.(*Node) passed to the OnUpdate is equal to the slice[1] (new version) - then we are just duplicating data here and I can't imagine any use case to use this slice[1] for future (instead of obj.(*Node)), do you have anything in mind?
I also don't think that it is a big diff to return, but I think it is better to not introduce obscurity/duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tetianakravchenko I was biased due to this and was thinking that we might use it in the future. But not needed for now for sure.

I chanhed again the code only to return old object.

kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/watcher.go Outdated Show resolved Hide resolved
locker: locker,
handler: handler,
store: store,
namespacewatcher: namespacewatcher,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use MixedCaps (aka camelCase) here and for all other variables? as suggested at https://go.dev/doc/effective_go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update in 16b0fca

Let me know If I missed anything

kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/watcher.go Outdated Show resolved Hide resolved
kubernetes/watcher.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
kubernetes/eventhandler.go Outdated Show resolved Hide resolved
@@ -209,16 +208,16 @@ func (*namespacePodUpdater) OnDelete(interface{}) {}
type nodePodUpdater struct {
handler podUpdaterHandlerFunc
store podUpdaterStore
nodewatcher OldobjectWatcher
nodeWatcher oldObjectWatcher
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry I meant to say to replace any other reference to oldObject -> cachedObject

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 @gsantoro
thank for insisting on this

Also relevant updates done in tests of elastic/beats#37431
Could you also have a look and approve there as well?

@gizas
Copy link
Contributor Author

gizas commented Jan 10, 2024

@fearful-symmetry or @belimawr can I have a review here as codeowners?

Copy link
Contributor

@MichaelKatsoulis MichaelKatsoulis left a comment

Choose a reason for hiding this comment

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

Thanks @gizas . I believe now the PR looks great!

kubernetes/watcher.go Outdated Show resolved Hide resolved
Co-authored-by: Tetiana Kravchenko <[email protected]>
CHANGELOG.md Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@gizas gizas merged commit 018039d into main Jan 12, 2024
3 checks passed
@gizas gizas deleted the conditionsonPodupdater branch January 12, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants