Skip to content

Commit 697ec67

Browse files
Merge pull request #2710 from openshift-cherrypick-robot/cherry-pick-2684-to-release-4.20
[release-4.20] OCPBUGS-62979: Remove AlertManager endpoints when disabled
2 parents 5d3e60e + f05e053 commit 697ec67

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

pkg/manifests/manifests.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, telemetrySecret *v1.Secret)
14481448
p.Spec.Thanos.Image = &f.config.Images.Thanos
14491449
}
14501450

1451-
setupAlerting(p, platformAlertmanagerService, f.namespace)
1451+
setupAlerting(p, platformAlertmanagerService, f.namespace, f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.IsEnabled())
14521452
f.adjustGoGCRelatedConfig(p)
14531453

14541454
for i, container := range p.Spec.Containers {
@@ -1514,7 +1514,12 @@ func (f *Factory) adjustGoGCRelatedConfig(p *monv1.Prometheus) {
15141514
}
15151515
}
15161516

1517-
func setupAlerting(p *monv1.Prometheus, svcName, svcNamespace string) {
1517+
func setupAlerting(p *monv1.Prometheus, svcName, svcNamespace string, enabled bool) {
1518+
if !enabled {
1519+
p.Spec.Alerting.Alertmanagers = []monv1.AlertmanagerEndpoints{}
1520+
return
1521+
}
1522+
15181523
eps := p.Spec.Alerting.Alertmanagers[0]
15191524

15201525
eps.Name = svcName
@@ -1805,9 +1810,9 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus,
18051810
f.adjustGoGCRelatedConfig(p)
18061811

18071812
if f.config.UserWorkloadConfiguration.Alertmanager.Enabled {
1808-
setupAlerting(p, userWorkloadAlertmanagerService, f.namespaceUserWorkload)
1813+
setupAlerting(p, userWorkloadAlertmanagerService, f.namespaceUserWorkload, true)
18091814
} else {
1810-
setupAlerting(p, platformAlertmanagerService, f.namespace)
1815+
setupAlerting(p, platformAlertmanagerService, f.namespace, f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.IsEnabled())
18111816
}
18121817

18131818
alertManagerConfigs := f.config.AdditionalAlertmanagerConfigsForPrometheusUserWorkload()

test/e2e/alertmanager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ func TestAlertmanagerDisabling(t *testing.T) {
702702
{name: "assert old service monitor does not exists", assertion: f.AssertServiceMonitorDoesNotExist("alertmanager", f.Ns)},
703703
{name: "alertmanager public URL is unset", assertion: f.AssertValueInConfigMapEquals(
704704
"monitoring-shared-config", "openshift-config-managed", "alertmanagerPublicURL", "")},
705+
{name: "assert prometheus alertmanager endpoints empty", assertion: f.AssertPrometheusAlertmanagerEndpointsEmpty("prometheus-k8s", f.Ns)},
705706
{name: "assert operator not degraded", assertion: f.AssertOperatorCondition(statusv1.OperatorDegraded, statusv1.ConditionFalse)},
706707
}
707708
t.Run("disable alertmanager", func(t *testing.T) {

test/e2e/framework/assertions.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,24 @@ func (f *Framework) AssertPrometheusExists(name, namespace string) func(t *testi
311311
}
312312
}
313313

314+
func (f *Framework) AssertPrometheusAlertmanagerEndpointsEmpty(name, namespace string) func(t *testing.T) {
315+
return func(t *testing.T) {
316+
err := Poll(time.Second, 5*time.Minute, func() error {
317+
const prometheusConfigSecretName = "prometheus-k8s"
318+
prometheusConfig := f.PrometheusConfigFromSecret(t, namespace, prometheusConfigSecretName)
319+
320+
if len(prometheusConfig.AlertingConfig.AlertmanagerConfigs) != 0 {
321+
return fmt.Errorf("expected no alertmanager endpoints in runtime config, got %d", len(prometheusConfig.AlertingConfig.AlertmanagerConfigs))
322+
}
323+
324+
return nil
325+
})
326+
if err != nil {
327+
t.Fatal(err)
328+
}
329+
}
330+
}
331+
314332
type PodAssertion func(pod v1.Pod) error
315333

316334
// AssertPodConfiguration for each pod in the namespace that matches the label selector

0 commit comments

Comments
 (0)