Skip to content

Skip unnecessary node events in config reconciler#1607

Merged
fedepaol merged 2 commits intometallb:mainfrom
pperiyasamy:skip-node-unnecessary-event
Sep 20, 2022
Merged

Skip unnecessary node events in config reconciler#1607
fedepaol merged 2 commits intometallb:mainfrom
pperiyasamy:skip-node-unnecessary-event

Conversation

@pperiyasamy
Copy link
Contributor

The config controller watches node event to populate l2 and bgp advertisement objects with selected nodes based on node selector labels.

But currently a change in the node results in reprocessing the configuration, which results in reprocessing the services. This results in an unnecessary cpu load.

Hence this change skips processing unnecessary node events other than node create, node update (if its with new labels) and node delete events.

Signed-off-by: Periyasamy Palanisamy pepalani@redhat.com

}

for _, node := range nodes.Items {
r.Nodes[node.Name] = node
Copy link
Member

Choose a reason for hiding this comment

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

I think every round must be deleted and recreated otherwise we won't be able to deal with deletions (or, you must iterate over it and remove nodes not in items, but recreating seems enough)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, but anyway this local cache is no longer needed with new predicate version which overrides UpdateFunc.

if !ok {
return true
}
err := r.Get(context.Background(), types.NamespacedName{Namespace: newNodeObj.Namespace,
Copy link
Member

Choose a reason for hiding this comment

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

I'd use the predicate version with the action instead of doing the get.

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.

return false
}
if existingNodeObj, ok := r.Nodes[newNodeObj.Name]; ok &&
labels.Set(existingNodeObj.Labels).String() == labels.Set(newNodeObj.Labels).String() {
Copy link
Member

Choose a reason for hiding this comment

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

will these be always in the right order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, changed to use labels.Equals method.

@fedepaol
Copy link
Member

Can you add a unit test for this scenario?

@pperiyasamy pperiyasamy force-pushed the skip-node-unnecessary-event branch from 74ab08a to dbdc588 Compare September 14, 2022 08:07
tasks.py Outdated
run("go test -short -race ./...")
envtest_asset_dir = os.getcwd() + "/testbin"
run('sudo rm -rf "%s"' % envtest_asset_dir)
os.mkdir(envtest_asset_dir)
Copy link
Member

Choose a reason for hiding this comment

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

what is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is for setting up envtest cluster as it is needed for running TestNodeEvent test.

Copy link
Member

Choose a reason for hiding this comment

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

Can we just add a copy of the file locally (under dev-env/unittests maybe) instead of fetching it every time?
Would it be better (just wondering)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, done.

@fedepaol
Copy link
Member

LGTM, just a question about the test setup

@pperiyasamy pperiyasamy force-pushed the skip-node-unnecessary-event branch from dbdc588 to 953a05c Compare September 14, 2022 15:34
tasks.py Outdated
envtest_asset_dir = os.getcwd() + "/dev-env/unittest"
run("source {}/setup-envtest.sh; fetch_envtest_tools {}; setup_envtest_env {}; go test -short ./...".format(envtest_asset_dir, envtest_asset_dir, envtest_asset_dir), echo=True)
run("source {}/setup-envtest.sh; fetch_envtest_tools {}; setup_envtest_env {}; go test -short -race ./...".format(envtest_asset_dir, envtest_asset_dir, envtest_asset_dir), echo=True)
run("sudo rm -rf {}/bin".format(envtest_asset_dir), echo=True)
Copy link
Member

Choose a reason for hiding this comment

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

I'd just add it to gitignore and not remove it, otherwise every time we run unit tests (locally) we'll download everything again.

tasks.py Outdated
run("go test -short -race ./...")

envtest_asset_dir = os.getcwd() + "/dev-env/unittest"
run("source {}/setup-envtest.sh; fetch_envtest_tools {}; setup_envtest_env {}; go test -short ./...".format(envtest_asset_dir, envtest_asset_dir, envtest_asset_dir), echo=True)
Copy link
Member

Choose a reason for hiding this comment

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

We can run fetch once I guess, maybe even setup, before running the two tests?

The config controller watches node event to populate l2 and bgp
advertisement objects with selected nodes based on node selector
labels.

But currently a change in the node results in reprocessing the
configuration, which results in reprocessing the services.
This results in an unnecessary cpu load.

Hence this change skips processing unnecessary node events
other than node create, node update (if its with new labels)
and node delete events.

Signed-off-by: Periyasamy Palanisamy <pepalani@redhat.com>
@pperiyasamy pperiyasamy force-pushed the skip-node-unnecessary-event branch from 953a05c to 3a55c33 Compare September 15, 2022 07:27
@fedepaol
Copy link
Member

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.

2 participants