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

fix: enable kube events for hooks with namespace.labelSelector bindings #411

Merged
merged 3 commits into from
Jul 22, 2022

Conversation

diafour
Copy link
Contributor

@diafour diafour commented Jul 12, 2022

Overview

Add flag to enable KubeEvents for varying informers after Synchronization phase.

What this PR does / why we need it

See #379 and #399. This fix enables events for hooks with namespace.labelSelector.

Special notes for your reviewer

"before" situation can be emulated by commenting m.eventsEnabled = true in monitor.go. Test will fail:

    monitor_test.go:119: 
        Timed out after 5.000s.
        Should fire KubeEvent after Synchronization
        Expected
            <bool>: false
        to be true

Does this PR introduce a user-facing change?


and-1 and others added 2 commits July 12, 2022 20:32
See #379.

- update #399 solution to work with Synchronization concept

Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
@diafour diafour requested a review from nabokihms July 12, 2022 19:39
@diafour diafour self-assigned this Jul 12, 2022
@diafour diafour requested a review from yalosev July 12, 2022 19:39
@diafour diafour changed the title Fix dynamic ns bindings fix: enable kube events for hooks with namespace.labelSelector bindings Jul 12, 2022
@diafour diafour requested a review from shvgn July 14, 2022 08:10
Copy link
Contributor

@shvgn shvgn left a comment

Choose a reason for hiding this comment

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

I'd prefer strict assertions.

pkg/kube_events_manager/monitor_test.go Show resolved Hide resolved
pkg/kube_events_manager/monitor_test.go Show resolved Hide resolved
// Wait until informer for new NS appears.
g.Eventually(func() bool {
monImpl := mon.(*monitor)
return len(monImpl.VaryingInformers) == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Counting seems good enough since this behavior looks deterministic. But I suggest to be more strict and test that VaryingInformers actually contains key "test-ns-2"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've rewrite this test.

// Wait until informer appears.
g.Eventually(func() bool {
monImpl := mon.(*monitor)
return len(monImpl.VaryingInformers) == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Counting seems good enough since this behavior looks deterministic. But I suggest to be more strict and test that VaryingInformers actually contains expected keys


// Should update snapshot.
g.Eventually(func() bool {
return len(mon.Snapshot()) == 4
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to find exact object reference in snapshots. We probably don't case about the amount, but we do care about the inclusion of the configmap. What if there is a bug that copies snap[0] all the time orgrows the slice with nils? :trollface:

pkg/kube_events_manager/monitor.go Show resolved Hide resolved
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
@diafour diafour requested a review from shvgn July 21, 2022 06:51
Copy link
Contributor

@nabokihms nabokihms left a comment

Choose a reason for hiding this comment

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

Lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants