Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions test/e2e/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/framework/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down