Skip to content

Commit

Permalink
CSVs autodiscovery fix.
Browse files Browse the repository at this point in the history
PR redhat-best-practices-for-k8s#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.
  • Loading branch information
greyerof committed Dec 18, 2024
1 parent c87f00f commit 8b2cb86
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/autodiscover/autodiscover_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -97,7 +105,17 @@ 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)
}

if namespacesMap[controllerNamespace] {
csvs = append(csvs, csv)
}
}
}
for i := range csvs {
Expand Down

0 comments on commit 8b2cb86

Please sign in to comment.