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

Trigger reprocess all event only when pool changes #1951

Merged

Conversation

mlguerrero12
Copy link
Contributor

This prevents the pool controller to trigger the reprocess all event when there are no changes in the pools.

Comment on lines 129 to 127
if !reflect.DeepEqual(c.pools, pools) {
c.pools = pools
return controllers.SyncStateReprocessAll
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should check the other way around, if is DeepEqual then return SyncStateSuccess,
with a log similar to what we have in the SetBalancer:
level.Debug(l).Log("event", "noChange", "msg", "service converged, no change")
else continue to execute the c.ips.SetPools and return Reprocess.
This is just to avoid running the c.ips.SetPools on the same/unchanged pools

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 had a reason to always run c.ips.SetPools but I can't remember what it was.

Will change it as you suggest. Thank you.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it's just a suggestion, but maybe don't negate the DeepEqual if statement,
so we won't have to branch if inside an if and make it easier to follow.
i.e. if the pools are equal we throw a log and return success, else
continue like before.

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 prefer the last return to be a success

Copy link
Contributor

Choose a reason for hiding this comment

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

you can also say that the Reprocess state is the happy path, as it was previously,
anyways it is unclear to me in what scenario would we reconcile and call the pool controller handler when the pool didn't change

Copy link
Member

Choose a reason for hiding this comment

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

it is unclear to me in what scenario would we reconcile and call the pool controller handler when the pool didn't change

This is a valid point too. The only scenario I can think of is when we do that is because a community entry changes but is not part of a legacy addresspool, which is a pretty cornery case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, mainly changes on community and namespaces not related to existing pools

Copy link
Contributor

Choose a reason for hiding this comment

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

but the community resource is translated into a BGPadv (both legacy and non) and that's part of the pool, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

community affects the legacy pools. BGPadv are part of the pools indeed but in the pools controller they are always empty

@mlguerrero12 mlguerrero12 force-pushed the preventreprocessallnopoolchanges branch from c1bd58f to 1fda5a9 Compare May 24, 2023 07:57
if err := c.ips.SetPools(pools); err != nil {
level.Error(l).Log("op", "setConfig", "error", err, "msg", "applying new configuration failed")
return controllers.SyncStateError
if !reflect.DeepEqual(c.pools, pools) {
Copy link
Member

Choose a reason for hiding this comment

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

In the configController we have this part on the higher level controller. I'd rather do the same here

if r.currentConfig != nil && reflect.DeepEqual(r.currentConfig, cfg) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that will require more changes. I would need to add a new parameter in the PoolReconciler structure to keep track of the pools. Perhaps in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

I might be missing something, but why comparing the rendered configs is not enough? At the end of the day it will contain only the pools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the config controller has a filed to store the current config, the pool controller does not

Copy link
Member

Choose a reason for hiding this comment

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

Right, but it's about copying the config controller logic.
If we want this kind of optimization, we should be consistent.

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 agree with the consistency. But perhaps the config controller should be the one that needs to be changed. I don't know. I'll study it soon. The only thing I don't like is to have (and maintain) many variables with pool. We have pools in the controller structure, allocator structure and now we are thinking about adding a new one for the pool controller structure.

Copy link
Member

Choose a reason for hiding this comment

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

I am suggesting not to keep only the pool, but do exactly the same as we do in the config controller, which is keeping an old version of the config and compare the rendered one (which yes, it will contain the pools).

I don't think it's a problem from readibility point of view, the config controller seems straightforward. We maintain a current config, check if changed and discard if it did not.

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 changed it as you suggested

This prevents the pool controller to trigger the reprocess
all event when there are no changes in the pools.

Signed-off-by: Marcelo Guerrero Viveros <marguerr@redhat.com>
@mlguerrero12 mlguerrero12 force-pushed the preventreprocessallnopoolchanges branch from 1fda5a9 to a664576 Compare June 1, 2023 09:14
@fedepaol
Copy link
Member

fedepaol commented Jun 6, 2023

lgtm, thanks!

@fedepaol fedepaol added this pull request to the merge queue Jun 6, 2023
Merged via the queue into metallb:main with commit f47465c Jun 6, 2023
24 checks passed
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

3 participants