From 489b98f74cbf5bd3cdfb1775457199d8a9c5d42f Mon Sep 17 00:00:00 2001 From: Gonzalo Reyero Ferreras Date: Thu, 28 Nov 2024 15:10:02 +0100 Subject: [PATCH] Fix for operator-single-crd-owner test case. As stated in issue https://github.com/redhat-best-practices-for-k8s/certsuite/issues/2593 , the test case operator-single-crd-owner might produce false positives. The original implementation didn't handle cases where a single CRD name can have more than one version. --- tests/operator/suite.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/operator/suite.go b/tests/operator/suite.go index ed44397ce..e4bf6e841 100644 --- a/tests/operator/suite.go +++ b/tests/operator/suite.go @@ -317,9 +317,19 @@ func testOperatorSingleCrdOwner(check *checksdb.Check, env *provider.TestEnviron for i := range env.Operators { operator := env.Operators[i] ownedCrds := operator.Csv.Spec.CustomResourceDefinitions.Owned + + // Helper map to filter out different versions of the same CRD name. + uniqueOnwnedCrds := map[string]struct{}{} for j := range ownedCrds { - crdOwners[ownedCrds[j].Name] = append(crdOwners[ownedCrds[j].Name], operator.Name) + uniqueOnwnedCrds[ownedCrds[j].Name] = struct{}{} + } + + // Now we can append the operator as CRD owner + for crdName := range uniqueOnwnedCrds { + crdOwners[crdName] = append(crdOwners[crdName], operator.Name) } + + check.LogInfo("CRDs owned by operator %s: %+v", operator.Name, uniqueOnwnedCrds) } // Flag those that are owned by more than one operator