Repository navigation
Conversation
simonpasquier
left a comment
There was a problem hiding this comment.
Thanks! It's smoother than what I expected :)
| // If no AlertmanagerConfig selectors and AlertmanagerConfiguration are | ||
| // configured, the user wants to manage configuration themselves. | ||
| if am.Spec.AlertmanagerConfigSelector == nil && am.Spec.AlertmanagerConfiguration == nil { | ||
| amConfigs, err := c.selectAlertmanagerConfigs(ctx, am, store, version, nil) |
There was a problem hiding this comment.
hmm it doesn't feel right: as stated by the comment, the Alertmanager resource doesn't rely on AlertmanagetConfigs
| var reason string | ||
| err := checkAlertmanagerConfigResource(ctx, amc, amVersion, store) | ||
| if err == nil { | ||
| err = checkGlobalConfigFields(amc, global) |
There was a problem hiding this comment.
suggestion: have the check in checkAlertmanagerConfigResource() directly (having an if err == nil { isn't idiomatic).
| } | ||
|
|
||
| func (c *Operator) selectAlertmanagerConfigs(ctx context.Context, am *monitoringv1.Alertmanager, store *assets.StoreBuilder, amVersion semver.Version) (operator.TypedResourcesSelection[*monitoringv1alpha1.AlertmanagerConfig], error) { | ||
| func (c *Operator) selectAlertmanagerConfigs(ctx context.Context, am *monitoringv1.Alertmanager, store *assets.StoreBuilder, amVersion semver.Version, global *globalConfig) (operator.TypedResourcesSelection[*monitoringv1alpha1.AlertmanagerConfig], error) { |
There was a problem hiding this comment.
ConfigBuilder already carries version and store, maybe we can pass it directly?
cf2c764 to
b3c2d06
Compare
|
Thanks for the review, reworked in b3c2d06 and rebased onto main. |
| amConfigs, err := c.selectAlertmanagerConfigs(ctx, am, cfgBuilder) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to select alertmanager configs: %w", err) | ||
| } | ||
|
|
There was a problem hiding this comment.
| amConfigs, err := c.selectAlertmanagerConfigs(ctx, am, cfgBuilder) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to select alertmanager configs: %w", err) | |
| } |
| @@ -1017,10 +1019,7 @@ func (c *Operator) provisionAlertmanagerConfiguration(ctx context.Context, am *m | |||
| return amConfigs, nil | |||
There was a problem hiding this comment.
| return amConfigs, nil | |
| return nil, nil |
| // The base configuration is loaded first because its global section | ||
| // decides which AlertmanagerConfig objects are valid. |
There was a problem hiding this comment.
| // The base configuration is loaded first because its global section | |
| // decides which AlertmanagerConfig objects are valid. |
| // checkAlertmanagerConfig verifies that an AlertmanagerConfig object is valid | ||
| // on its own (see checkAlertmanagerConfigResource) and together with the base | ||
| // configuration the builder holds. | ||
| func (cb *ConfigBuilder) checkAlertmanagerConfig(ctx context.Context, amc *monitoringv1alpha1.AlertmanagerConfig) error { |
There was a problem hiding this comment.
If we switch to ConfigBuilder methods, they will need to move to amcfg.go, we don't want them to be scattered across files.
For the time being it's more convenient to pass configBuilder as a func argument. We can consider refactoring as a follow-up.
| } | ||
|
|
||
| for i, c := range receiver.SlackConfigs { | ||
| apiURL, err := secret(c.APIURL) |
There was a problem hiding this comment.
the secret ref has already been loaded before, let's move the empty check there. There's no good reason why someone would reference an empty secret value.
|
Thanks, all five points addressed in 3bb8f82. |
| for namespaceAndName, amc := range amConfigs { | ||
| var reason string | ||
| err := checkAlertmanagerConfigResource(ctx, amc, amVersion, store) | ||
| err := checkAlertmanagerConfig(ctx, cb, amc) |
There was a problem hiding this comment.
checkAlertmanagerConfigResource() is also called by initializeFromAlertmanagerConfig() and it needs to be preserved. I'd recommend not renaming checkAlertmanagerConfigResource() to checkAlertmanagerConfig() but rather extend it with the checks against the global config defaults.
|
Thanks, that makes sense. I kept |
|
Thanks for the approval, @simonpasquier. CI is green and the branch is up to date with main. Is there anything else you need from me before this can be merged? |
|
This is approved and every check is green. Could a maintainer merge it when convenient? Thank you @simonpasquier for the careful reviews, they made it better. |
|
This is approved and CI is green on the current head. Could a maintainer merge it when convenient? Happy to adjust anything first. |
|
Thanks again for the approval, @simonpasquier. The PR has not moved since, so I wanted to check that nothing else is needed from my side before it can be merged. |
|
@A-RYAN-1 no need to pile up more comments on the PR. We have a long stuff to review and try to get to them 1 by 1. |
|
@A-RYAN-1 can you rebase? Now that we have v0.95 out of the door, this should be good to go. |
dd8d735 to
e8e5c52
Compare
|
Rebased onto main as a single commit. The filesystem-mode check now reads the Alertmanager from the ConfigBuilder, and the pkg/alertmanager tests pass. Thanks! |
e8e5c52 to
e5554df
Compare
|
@simonpasquier the rebase onto main dismissed your earlier approval; all checks are green on e5554df. Could you re-approve when you get a chance? Thanks. |
|
|
||
| for _, receiver := range amc.Spec.Receivers { | ||
| for i, c := range receiver.EmailConfigs { | ||
| if ptr.Deref(c.Smarthost, "") == "" && global.SMTPSmarthost.Host == "" { |
There was a problem hiding this comment.
can we remove the now redundant code in pkg/alertmanager/amcfg.go?
There was a problem hiding this comment.
Done in 1c0d9ff: the now redundant smarthost and auth checks in amcfg.go are removed.
| global = cb.cfg.Global | ||
| } | ||
|
|
||
| for _, receiver := range amc.Spec.Receivers { |
There was a problem hiding this comment.
we miss Telegram fields which are covered already.
Slack apiURL, OpsGenie and VictorOps apiKey, WeChat apiSecret and corpID, and the email smarthost and from are optional in a receiver because Alertmanager can take them from the global configuration. When the global configuration did not set them, the generated file was refused by Alertmanager and no AlertmanagerConfig took effect. Load the base configuration before selecting AlertmanagerConfig objects and reject the ones whose receivers rely on a global value that is not set, like any other invalid object. The check lives in checkAlertmanagerConfigResource, which now takes the ConfigBuilder. Signed-off-by: Aryan Deshmukh <[email protected]>
…checks Add the Telegram bot token (botToken or botTokenFile, or the global value) to checkGlobalConfigFields so every receiver that depends on a global default is rejected in one place, before the configuration is generated. Remove the email smarthost and from checks and the Telegram bot token check from the receiver conversion in amcfg.go. They can no longer be reached from the operator, which only converts AlertmanagerConfig objects that passed checkAlertmanagerConfigResource, and the new checks have table tests of their own. The builder-level test cases for them go with the code. Signed-off-by: Aryan Deshmukh <[email protected]>
e5554df to
1c0d9ff
Compare
|
Thanks, both points done in 1c0d9ff. The Telegram bot token (botToken, botTokenFile or the global value) is now part of checkGlobalConfigFields, and the email smarthost and from checks and the Telegram check are removed from amcfg.go, since only objects that passed checkAlertmanagerConfigResource reach the conversion. Their builder-level test cases went with them. I also rebased on main; the only conflict was in operator_test.go, next to the new SNS tests. |
Description
Slack
apiURL, OpsGenie and VictorOpsapiKey, WeChatapiSecretandcorpID, and the emailsmarthostandfromare optional in a receiver because Alertmanager can take them from the global configuration. When the global configuration did not set them, the generated file was refused by Alertmanager and no AlertmanagerConfig took effect. Such an object is now rejected at selection, like any other invalid one, and the others keep working. The base configuration (secret or global AlertmanagerConfig) is now loaded before the selection so itsglobalsection can be used for the check.Fixes #8888
AI-assisted.
Verification
Table test
TestCheckGlobalConfigFieldsfor each receiver type (missing, set on the receiver, set in the global configuration).go test ./pkg/alertmanager/ ./pkg/operator/...passes on Linux.Open points
convertEmailConfigis kept as a safety net.