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

Config Controller: ignore changes that are not relevant #1791

Merged
merged 1 commit into from Jan 26, 2023

Conversation

fedepaol
Copy link
Member

The configuration controller is triggered by multiple events, including all the secrets in the metallb's namespace. This cause a cascade effect of reprocessing all the services which is not necessary.

Here we compare the last processed configuration with the one we just produced (which takes into account of non used secrets and non used namespaces, for example), limiting configuration reload events to those that really are changing the metallb's internal configuration.

On top of that, in order to keep the node label test effective, the implementation of the reconciliation function is deferred to a local function that can be overridden by the tests.

Fixes #1770

@@ -133,7 +139,12 @@ func (r *ConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

level.Debug(r.Logger).Log("controller", "ConfigReconciler", "rendered config", dumpConfig(cfg))
if r.oldConfig != nil && reflect.DeepEqual(r.oldConfig, cfg) {
level.Error(r.Logger).Log("controller", "ConfigReconciler", "event", "configuration did not change, ignoring")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have level.Info here instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, good catch

Copy link
Member

Choose a reason for hiding this comment

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

this could even be debug imo, unless you expect this to not show so often?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +183 to +205
handlerCalled = false
err = fakeClient.Create(context.TODO(), &v1beta2.BGPPeer{
ObjectMeta: metav1.ObjectMeta{
Name: "peer2",
Namespace: testNamespace,
},
Spec: v1beta2.BGPPeerSpec{
MyASN: 42,
ASN: 142,
Address: "1.2.3.4",
BFDProfile: "default",
},
})
if err != nil {
t.Fatalf("create failed on peer2: %v", err)
}
_, err = r.Reconcile(context.TODO(), req)
if err != nil {
t.Fatalf("reconcile failed: %v", err)
}
if !handlerCalled {
t.Fatalf("handler not called")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the second reconciler call with the bgppeer in this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to ensure that if the configuration is changed, the handler is called

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok got it. sounds good!

handlerCalled = false
err = fakeClient.Create(context.TODO(), &corev1.Secret{Type: corev1.SecretTypeBasicAuth, ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: testNamespace},
Data: map[string][]byte{"password": []byte([]byte("nopass"))}})

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra newline between the err = .... and the if err != nil

Copy link
Member Author

Choose a reason for hiding this comment

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

the line above is on multiple lines, having it attached seems a bit cramped.

@liornoy
Copy link
Contributor

liornoy commented Jan 23, 2023

Left a couple of comments, regarding the node selector tests, I don't understand what you mean by to keep the node label test effective. Are those changes required because the changes of the reconciler broke them?

@fedepaol
Copy link
Member Author

Left a couple of comments, regarding the node selector tests, I don't understand what you mean by to keep the node label test effective. Are those changes required because the changes of the reconciler broke them?

it didn't "broke them" but the handler wasn't being called anymore because the configuration wasn't changing

@liornoy
Copy link
Contributor

liornoy commented Jan 23, 2023

Left a couple of comments, regarding the node selector tests, I don't understand what you mean by to keep the node label test effective. Are those changes required because the changes of the reconciler broke them?

it didn't "broke them" but the handler wasn't being called anymore because the configuration wasn't changing

Thanks for the clarification.

@pupseba
Copy link

pupseba commented Jan 26, 2023

Hi. Is there any estimated date for when this improvement will hit master and be released in a new version?


r.oldConfig = cfg
Copy link
Member

Choose a reason for hiding this comment

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

maybe I'm missing something, but isn't setting this before the Handler problematic in the sense that if the Handler fails with a retry error the config would be ignored in the next reconcile (because of the new DeepEqual conditional)?

Copy link
Member Author

Choose a reason for hiding this comment

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

no the consideration is totally fair. Let me change it so we set the current only when the current is processed successfuly

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -133,7 +139,12 @@ func (r *ConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

level.Debug(r.Logger).Log("controller", "ConfigReconciler", "rendered config", dumpConfig(cfg))
if r.oldConfig != nil && reflect.DeepEqual(r.oldConfig, cfg) {
level.Error(r.Logger).Log("controller", "ConfigReconciler", "event", "configuration did not change, ignoring")
Copy link
Member

Choose a reason for hiding this comment

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

this could even be debug imo, unless you expect this to not show so often?

@@ -44,9 +45,14 @@ type ConfigReconciler struct {
ValidateConfig config.Validate
ForceReload func()
BGPType string
oldConfig *config.Config
Copy link
Member

Choose a reason for hiding this comment

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

nit: isn't this more currentConfig?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@fedepaol
Copy link
Member Author

Hi. Is there any estimated date for when this improvement will hit master and be released in a new version?

@pupseba no promises, but aiming at merging by end of this week and doing a new release by end of next week

The configuration controller is triggered by multiple events, including
all the secrets in the metallb's namespace. This cause a cascade effect
of reprocessing all the services which is not necessary.

Here we compare the last processed configuration with the one we just
produced (which takes into account of non used secrets and non used
namespaces, for example), limiting configuration reload events to those
that really are changing the metallb's internal configuration.

On top of that, in order to keep the node label test effective, the
implementation of the reconciliation function is deferred to a local
function that can be overridden by the tests.

Signed-off-by: Federico Paolinelli <fpaoline@redhat.com>
Copy link
Member

@oribon oribon left a comment

Choose a reason for hiding this comment

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

lgtm

@fedepaol fedepaol merged commit fd4ca5e into metallb:main Jan 26, 2023
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.

serviceAnnounced for no reason and excesive ServiceReconciler logs after update to 0.13.7 from 0.12.1
4 participants