From 9f1ebd903f3ae85adaa6c6992be3741ebc7d7203 Mon Sep 17 00:00:00 2001 From: Gonzalo Reyero Ferreras <87083379+greyerof@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:39:47 +0100 Subject: [PATCH] CSVs autodiscovery fix. (#2653) PR #2479 fixed the autodiscovery of operator's pods and also added them to the pods-under-test list. The problem is that it was also adding every cluster-wide operator's controller pods to that list. With this change, the operator (controller's pod) must be running in one of the configured/test namespaces in order to consider that CSV as part of the operators under test. --- pkg/autodiscover/autodiscover_operators.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/autodiscover/autodiscover_operators.go b/pkg/autodiscover/autodiscover_operators.go index 07f330fe7..a55040cd8 100644 --- a/pkg/autodiscover/autodiscover_operators.go +++ b/pkg/autodiscover/autodiscover_operators.go @@ -81,6 +81,14 @@ func findOperatorsMatchingAtLeastOneLabel(olmClient clientOlm.Interface, labels } func findOperatorsByLabels(olmClient clientOlm.Interface, labels []labelObject, namespaces []configuration.Namespace) (csvs []*olmv1Alpha.ClusterServiceVersion) { + const nsAnnotation = "olm.operatorNamespace" + + // Helper namespaces map to do quick search of the operator's controller namespace. + namespacesMap := map[string]bool{} + for _, ns := range namespaces { + namespacesMap[ns.Name] = true + } + csvs = []*olmv1Alpha.ClusterServiceVersion{} var csvList *olmv1Alpha.ClusterServiceVersionList for _, ns := range namespaces { @@ -97,7 +105,18 @@ func findOperatorsByLabels(olmClient clientOlm.Interface, labels []labelObject, } } for i := range csvList.Items { - csvs = append(csvs, &csvList.Items[i]) + csv := &csvList.Items[i] + + // Filter out CSV if operator's controller pod/s is/are not running in any configured/test namespace. + controllerNamespace, found := csv.Annotations[nsAnnotation] + if !found { + log.Error("Failed to get ns annotation %q from csv %v/%v", nsAnnotation, csv.Namespace, csv.Name) + continue + } + + if namespacesMap[controllerNamespace] { + csvs = append(csvs, csv) + } } } for i := range csvs {