Skip to content

Commit 1942245

Browse files
committed
test: use dedicated namespace for health-analyzer e2e PrometheusRule
Move the test PrometheusRule from openshift-monitoring to a throwaway namespace labeled with openshift.io/cluster-monitoring=true. The platform Prometheus picks up rules from any namespace with that label, so the test still works but avoids writing into a shared system namespace. Made-with: Cursor
1 parent 9146e40 commit 1942245

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

test/e2e/uiplugin_cluster_health_analyzer_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/prometheus/common/model"
1212
"gotest.tools/v3/assert"
1313
appsv1 "k8s.io/api/apps/v1"
14+
corev1 "k8s.io/api/core/v1"
1415
"k8s.io/apimachinery/pkg/api/errors"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
"k8s.io/apimachinery/pkg/util/intstr"
@@ -22,7 +23,7 @@ import (
2223

2324
const (
2425
healthAnalyzerDeploymentName = "health-analyzer"
25-
prometheusRuleNamespace = "openshift-monitoring"
26+
prometheusRuleNamespace = "e2e-health-analyzer-rules"
2627
)
2728

2829
func clusterHealthAnalyzer(t *testing.T) {
@@ -50,6 +51,8 @@ func clusterHealthAnalyzer(t *testing.T) {
5051
ruleName := "e2e-health-analyzer-" + suffix
5152
alertName := "E2EHealthAnalyzer" + suffix
5253

54+
createRuleNamespace(t, prometheusRuleNamespace)
55+
5356
rule := newAlwaysFiringRule(t, ruleName, alertName)
5457
err = f.K8sClient.Create(t.Context(), rule)
5558
assert.NilError(t, err, "failed to create PrometheusRule")
@@ -122,17 +125,30 @@ func newMonitoringUIPlugin(t *testing.T) *uiv1.UIPlugin {
122125
return plugin
123126
}
124127

128+
func createRuleNamespace(t *testing.T, name string) {
129+
t.Helper()
130+
ns := &corev1.Namespace{
131+
ObjectMeta: metav1.ObjectMeta{
132+
Name: name,
133+
Labels: map[string]string{
134+
"openshift.io/cluster-monitoring": "true",
135+
},
136+
},
137+
}
138+
if err := f.K8sClient.Create(t.Context(), ns); err != nil && !errors.IsAlreadyExists(err) {
139+
t.Fatalf("failed to create rule namespace %s: %v", name, err)
140+
}
141+
f.CleanUp(t, func() {
142+
ctx := context.WithoutCancel(t.Context())
143+
f.K8sClient.Delete(ctx, ns)
144+
})
145+
}
146+
125147
func newAlwaysFiringRule(t *testing.T, ruleName, alertName string) *monv1.PrometheusRule {
126148
rule := &monv1.PrometheusRule{
127149
ObjectMeta: metav1.ObjectMeta{
128150
Name: ruleName,
129151
Namespace: prometheusRuleNamespace,
130-
Labels: map[string]string{
131-
"app.kubernetes.io/name": "kube-prometheus",
132-
"app.kubernetes.io/part-of": "openshift-monitoring",
133-
"prometheus": "k8s",
134-
"role": "alert-rules",
135-
},
136152
},
137153
Spec: monv1.PrometheusRuleSpec{
138154
Groups: []monv1.RuleGroup{{

0 commit comments

Comments
 (0)