diff --git a/pkg/manifests/manifests.go b/pkg/manifests/manifests.go index 663ec4817a..b3af59e64f 100644 --- a/pkg/manifests/manifests.go +++ b/pkg/manifests/manifests.go @@ -1455,7 +1455,7 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, telemetrySecret *v1.Secret) p.Spec.Thanos.Image = &f.config.Images.Thanos } - setupAlerting(p, platformAlertmanagerService, f.namespace) + setupAlerting(p, platformAlertmanagerService, f.namespace, f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.IsEnabled()) f.adjustGoGCRelatedConfig(p) for i, container := range p.Spec.Containers { @@ -1521,7 +1521,12 @@ func (f *Factory) adjustGoGCRelatedConfig(p *monv1.Prometheus) { } } -func setupAlerting(p *monv1.Prometheus, svcName, svcNamespace string) { +func setupAlerting(p *monv1.Prometheus, svcName, svcNamespace string, enabled bool) { + if !enabled { + p.Spec.Alerting.Alertmanagers = []monv1.AlertmanagerEndpoints{} + return + } + eps := p.Spec.Alerting.Alertmanagers[0] eps.Name = svcName @@ -1813,9 +1818,9 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret) (*monv1.Prometheus, f.adjustGoGCRelatedConfig(p) if f.config.UserWorkloadConfiguration.Alertmanager.Enabled { - setupAlerting(p, userWorkloadAlertmanagerService, f.namespaceUserWorkload) + setupAlerting(p, userWorkloadAlertmanagerService, f.namespaceUserWorkload, true) } else { - setupAlerting(p, platformAlertmanagerService, f.namespace) + setupAlerting(p, platformAlertmanagerService, f.namespace, f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.IsEnabled()) } alertManagerConfigs := f.config.AdditionalAlertmanagerConfigsForPrometheusUserWorkload() diff --git a/test/e2e/alertmanager_test.go b/test/e2e/alertmanager_test.go index 7e262dec81..156631fee8 100644 --- a/test/e2e/alertmanager_test.go +++ b/test/e2e/alertmanager_test.go @@ -702,6 +702,7 @@ func TestAlertmanagerDisabling(t *testing.T) { {name: "assert old service monitor does not exists", assertion: f.AssertServiceMonitorDoesNotExist("alertmanager", f.Ns)}, {name: "alertmanager public URL is unset", assertion: f.AssertValueInConfigMapEquals( "monitoring-shared-config", "openshift-config-managed", "alertmanagerPublicURL", "")}, + {name: "assert prometheus alertmanager endpoints empty", assertion: f.AssertPrometheusAlertmanagerEndpointsEmpty("prometheus-k8s", f.Ns)}, {name: "assert operator not degraded", assertion: f.AssertOperatorCondition(statusv1.OperatorDegraded, statusv1.ConditionFalse)}, } t.Run("disable alertmanager", func(t *testing.T) { diff --git a/test/e2e/framework/assertions.go b/test/e2e/framework/assertions.go index f83eb38409..19b46449d4 100644 --- a/test/e2e/framework/assertions.go +++ b/test/e2e/framework/assertions.go @@ -311,6 +311,24 @@ func (f *Framework) AssertPrometheusExists(name, namespace string) func(t *testi } } +func (f *Framework) AssertPrometheusAlertmanagerEndpointsEmpty(name, namespace string) func(t *testing.T) { + return func(t *testing.T) { + err := Poll(time.Second, 5*time.Minute, func() error { + const prometheusConfigSecretName = "prometheus-k8s" + prometheusConfig := f.PrometheusConfigFromSecret(t, namespace, prometheusConfigSecretName) + + if len(prometheusConfig.AlertingConfig.AlertmanagerConfigs) != 0 { + return fmt.Errorf("expected no alertmanager endpoints in runtime config, got %d", len(prometheusConfig.AlertingConfig.AlertmanagerConfigs)) + } + + return nil + }) + if err != nil { + t.Fatal(err) + } + } +} + type PodAssertion func(pod v1.Pod) error // AssertPodConfiguration for each pod in the namespace that matches the label selector