From 1267365dda9a19bb89d7631830be105402a703de Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Wed, 11 Aug 2021 15:41:29 +0100 Subject: [PATCH] Allow TechPreviewNoUpgrade alerts when running on a TechPreview cluster --- test/extended/prometheus/prometheus.go | 38 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/test/extended/prometheus/prometheus.go b/test/extended/prometheus/prometheus.go index 2447adc324de..7c9456fbedb4 100644 --- a/test/extended/prometheus/prometheus.go +++ b/test/extended/prometheus/prometheus.go @@ -19,6 +19,8 @@ import ( v1 "k8s.io/api/core/v1" + configv1 "github.com/openshift/api/config/v1" + kapierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -105,6 +107,14 @@ var _ = g.Describe("[sig-instrumentation][Late] Alerts", func() { }, } + if isTechPreviewCluster(oc) { + allowedFiringAlerts = append(allowedFiringAlerts, helper.MetricCondition{ + Selector: map[string]string{"alertname": "TechPreviewNoUpgrade"}, + Text: "Allow testing of TechPreviewNoUpgrade clusters, this will only fire when a FeatureGate has been installed", + }, + ) + } + pendingAlertsWithBugs := helper.MetricConditions{} allowedPendingAlerts := helper.MetricConditions{ { @@ -503,9 +513,21 @@ var _ = g.Describe("[sig-instrumentation] Prometheus", func() { oc.AdminKubeClient().CoreV1().Pods(ns).Delete(context.Background(), execPod.Name, *metav1.NewDeleteOptions(1)) }() + // Checking Watchdog alert state is done in "should have a Watchdog alert in firing state". + allowedAlertNames := []string{ + "Watchdog", + "AlertmanagerReceiversNotConfigured", + "PrometheusRemoteWriteDesiredShards", + } + + if isTechPreviewCluster(oc) { + // On a TechPreviewNoUpgrade cluster we must ignore the TechPreviewNoUpgrade alert + // fired by the Kube API Operator. This alert is expected in this case. + allowedAlertNames = append(allowedAlertNames, "TechPreviewNoUpgrade") + } + tests := map[string]bool{ - // Checking Watchdog alert state is done in "should have a Watchdog alert in firing state". - `ALERTS{alertname!~"Watchdog|AlertmanagerReceiversNotConfigured|PrometheusRemoteWriteDesiredShards",alertstate="firing",severity!="info"} >= 1`: false, + fmt.Sprintf(`ALERTS{alertname!~"%s",alertstate="firing",severity!="info"} >= 1`, strings.Join(allowedAlertNames, "|")): false, } err := helper.RunQueries(tests, oc, ns, execPod.Name, url, bearerToken) o.Expect(err).NotTo(o.HaveOccurred()) @@ -804,3 +826,15 @@ func hasPullSecret(client clientset.Interface, name string) bool { } return len(ps.Auths[name].Auth) > 0 } + +func isTechPreviewCluster(oc *exutil.CLI) bool { + featureGate, err := oc.AdminConfigClient().ConfigV1().FeatureGates().Get(context.Background(), "cluster", metav1.GetOptions{}) + if err != nil { + if kapierrs.IsNotFound(err) { + return false + } + e2e.Failf("could not retrieve feature-gate: %v", err) + } + + return featureGate.Spec.FeatureSet == configv1.TechPreviewNoUpgrade +}