Skip to content

Commit

Permalink
Operator Installation outside of targetNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bnshr committed Nov 26, 2024
1 parent 9695127 commit 822dfe9
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 97 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
languages: ${{ matrix.language }}
tools: latest
Expand All @@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/autobuild@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -78,4 +78,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard (optional).
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
sarif_file: results.sarif
24 changes: 20 additions & 4 deletions CATALOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Depending on the workload type, not all tests are required to pass to satisfy be

## Test cases summary

### Total test cases: 116
### Total test cases: 117

### Total suites: 10

Expand All @@ -19,7 +19,7 @@ Depending on the workload type, not all tests are required to pass to satisfy be
|manageability|2|
|networking|12|
|observability|5|
|operator|10|
|operator|11|
|performance|6|
|platform-alteration|13|
|preflight|17|
Expand All @@ -36,11 +36,11 @@ Depending on the workload type, not all tests are required to pass to satisfy be
|---|---|
|8|1|

### Non-Telco specific tests only: 68
### Non-Telco specific tests only: 69

|Mandatory|Optional|
|---|---|
|43|25|
|44|25|

### Telco specific tests only: 27

Expand Down Expand Up @@ -1346,6 +1346,22 @@ Tags|common,operator
|Non-Telco|Mandatory|
|Telco|Mandatory|

#### operator-valid-installation-tenant-namespace

Property|Description
---|---
Unique ID|operator-valid-installation-tenant-namespace
Description|Tests whether operator installation is valid in tenant namespace.
Suggested Remediation|Ensure that operator with install mode SingleNamespace only is installed in the tenant namespace.
Best Practice Reference|https://redhat-best-practices-for-k8s.github.io/guide/#redhat-best-practices-for-k8s-cnf-operator-requirements
Exception Process|No exceptions
Tags|common,operator
|**Scenario**|**Optional/Mandatory**|
|Extended|Mandatory|
|Far-Edge|Mandatory|
|Non-Telco|Mandatory|
|Telco|Mandatory|

### performance

#### performance-exclusive-cpu-pool
Expand Down
2 changes: 2 additions & 0 deletions config/certsuite_config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
targetNameSpaces:
- name: tnf
- name: certsuite-operator
podsUnderTestLabels:
- "redhat-best-practices-for-k8s.com/generic: target"
operatorsUnderTestLabels:
- "redhat-best-practices-for-k8s.com/operator:target"
- "redhat-best-practices-for-k8s.com/operator1:new"
- "cnf/test:cr-scale-operator"
- "operators.coreos.com/rh-best-practices-for-k8s-certsuite-operator.certsuite-operator:"
targetCrdFilters:
- nameSuffix: "group1.test.com"
scalable: false
Expand Down
1 change: 1 addition & 0 deletions expected_results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ testCases:
- operator-single-crd-owner
- operator-pods-no-hugepages
- operator-multiple-same-operators
- operator-valid-installation-tenant-namespace
- performance-exclusive-cpu-pool
- performance-max-resources-exec-probes
- performance-shared-cpu-pool-non-rt-scheduling-policy # hazelcast pod meets requirements
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ require (
github.com/redhat-best-practices-for-k8s/certsuite-claim v1.0.50
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1
)

require k8s.io/client-go v0.31.2
require k8s.io/client-go v0.31.3

require (
github.com/mittwald/go-helm-client v0.12.14
Expand All @@ -22,8 +22,8 @@ require (
github.com/operator-framework/operator-lifecycle-manager v0.30.0
github.com/pkg/errors v0.9.1 // indirect
helm.sh/helm/v3 v3.16.3
k8s.io/api v0.31.2
k8s.io/apimachinery v0.31.2
k8s.io/api v0.31.3
k8s.io/apimachinery v0.31.3
k8s.io/klog/v2 v2.130.1 // indirect
)

Expand Down Expand Up @@ -194,9 +194,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiserver v0.31.2 // indirect
k8s.io/cli-runtime v0.31.2 // indirect
k8s.io/component-base v0.31.2 // indirect
k8s.io/apiserver v0.31.3 // indirect
k8s.io/cli-runtime v0.31.3 // indirect
k8s.io/component-base v0.31.3 // indirect
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 // indirect
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect
modernc.org/libc v1.37.6 // indirect
Expand All @@ -215,7 +215,7 @@ require (

require (
github.com/hashicorp/go-version v1.7.0
k8s.io/apiextensions-apiserver v0.31.2
k8s.io/apiextensions-apiserver v0.31.3
)

require (
Expand All @@ -226,13 +226,13 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.5
github.com/manifoldco/promptui v0.9.0
github.com/redhat-best-practices-for-k8s/oct v0.0.27
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.39
github.com/redhat-best-practices-for-k8s/oct v0.0.28
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.40
github.com/redhat-openshift-ecosystem/openshift-preflight v0.0.0-20241021175030-e64988a27024
github.com/robert-nix/ansihtml v1.0.1
golang.org/x/term v0.26.0
google.golang.org/api v0.207.0
k8s.io/kubectl v0.31.2
google.golang.org/api v0.209.0
k8s.io/kubectl v0.31.3
)

replace github.com/redhat-openshift-ecosystem/openshift-preflight => github.com/redhat-openshift-ecosystem/openshift-preflight v0.0.0-20241021175030-e64988a27024
Expand Down
47 changes: 24 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/redhat-best-practices-for-k8s/certsuite-claim v1.0.50 h1:I5h0QManS/gIqu+ontECO7wl7YRNynITdu2ox55aHmQ=
github.com/redhat-best-practices-for-k8s/certsuite-claim v1.0.50/go.mod h1:MEPl9mYANLNgdd7KKpW6rRXmUK1pXtbWmG2eVaKmBKM=
github.com/redhat-best-practices-for-k8s/oct v0.0.27 h1:7iJ1475uhyxjhStR4riCQisG/LzUhKktMKdwaaGzBQo=
github.com/redhat-best-practices-for-k8s/oct v0.0.27/go.mod h1:ilJ7CTkImZOhT0WW5jbqxYighVRBPpLxcxcuc5Fd/ZU=
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.39 h1:fdifQZFjx5NIiD/8pt94ELeTPUXy7s/KYwJC8wzgqns=
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.39/go.mod h1:Xvn/SQLaro2vpiVut0e1epYr/SrUsw5VBueIZcb2dcM=
github.com/redhat-best-practices-for-k8s/oct v0.0.28 h1:jsVQ8zNY4HP0a+N5LpW445Y3phklZ4PGtlU1pZQ0Wic=
github.com/redhat-best-practices-for-k8s/oct v0.0.28/go.mod h1:TnyopIPwdsaI7gikOi7WmT9/lgzd1Lp6DZaN6nMJhBA=
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.40 h1:imtI6P0XZSeaGbMd81Dg6QpsJrtUPobAlHhvwEyGouU=
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.40/go.mod h1:ZVOdgHN8bR8bRFQytKgyDa+26AUa96wcnjsnJ6RYnzQ=
github.com/redhat-openshift-ecosystem/openshift-preflight v0.0.0-20241021175030-e64988a27024 h1:qPsNS6SIDigSwcUMUrEdDovIAdbVCNOGvhir8p6wVNc=
github.com/redhat-openshift-ecosystem/openshift-preflight v0.0.0-20241021175030-e64988a27024/go.mod h1:WgrOUZnQYsTQetJwbMHkcNecYaOcWMmTVDmDOTTIMcQ=
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 h1:EaDatTxkdHG+U3Bk4EUr+DZ7fOGwTfezUiUJMaIcaho=
Expand Down Expand Up @@ -511,8 +511,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
Expand Down Expand Up @@ -665,8 +666,8 @@ golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSm
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/api v0.207.0 h1:Fvt6IGCYjf7YLcQ+GCegeAI2QSQCfIWhRkmrMPj3JRM=
google.golang.org/api v0.207.0/go.mod h1:I53S168Yr/PNDNMi5yPnDc0/LGRZO6o7PoEbl/HY3CM=
google.golang.org/api v0.209.0 h1:Ja2OXNlyRlWCWu8o+GgI4yUn/wz9h/5ZfFbKz+dQX+w=
google.golang.org/api v0.209.0/go.mod h1:I53S168Yr/PNDNMi5yPnDc0/LGRZO6o7PoEbl/HY3CM=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down Expand Up @@ -721,26 +722,26 @@ helm.sh/helm/v3 v3.16.3 h1:kb8bSxMeRJ+knsK/ovvlaVPfdis0X3/ZhYCSFRP+YmY=
helm.sh/helm/v3 v3.16.3/go.mod h1:zeVWGDR4JJgiRbT3AnNsjYaX8OTJlIE9zC+Q7F7iUSU=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0=
k8s.io/apiextensions-apiserver v0.31.2/go.mod h1:i+Geh+nGCJEGiCGR3MlBDkS7koHIIKWVfWeRFiOsUcM=
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.31.2 h1:VUzOEUGRCDi6kX1OyQ801m4A7AUPglpsmGvdsekmcI4=
k8s.io/apiserver v0.31.2/go.mod h1:o3nKZR7lPlJqkU5I3Ove+Zx3JuoFjQobGX1Gctw6XuE=
k8s.io/cli-runtime v0.31.2 h1:7FQt4C4Xnqx8V1GJqymInK0FFsoC+fAZtbLqgXYVOLQ=
k8s.io/cli-runtime v0.31.2/go.mod h1:XROyicf+G7rQ6FQJMbeDV9jqxzkWXTYD6Uxd15noe0Q=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
k8s.io/component-base v0.31.2 h1:Z1J1LIaC0AV+nzcPRFqfK09af6bZ4D1nAOpWsy9owlA=
k8s.io/component-base v0.31.2/go.mod h1:9PeyyFN/drHjtJZMCTkSpQJS3U9OXORnHQqMLDz0sUQ=
k8s.io/api v0.31.3 h1:umzm5o8lFbdN/hIXbrK9oRpOproJO62CV1zqxXrLgk8=
k8s.io/api v0.31.3/go.mod h1:UJrkIp9pnMOI9K2nlL6vwpxRzzEX5sWgn8kGQe92kCE=
k8s.io/apiextensions-apiserver v0.31.3 h1:+GFGj2qFiU7rGCsA5o+p/rul1OQIq6oYpQw4+u+nciE=
k8s.io/apiextensions-apiserver v0.31.3/go.mod h1:2DSpFhUZZJmn/cr/RweH1cEVVbzFw9YBu4T+U3mf1e4=
k8s.io/apimachinery v0.31.3 h1:6l0WhcYgasZ/wk9ktLq5vLaoXJJr5ts6lkaQzgeYPq4=
k8s.io/apimachinery v0.31.3/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.31.3 h1:+1oHTtCB+OheqFEz375D0IlzHZ5VeQKX1KGXnx+TTuY=
k8s.io/apiserver v0.31.3/go.mod h1:PrxVbebxrxQPFhJk4powDISIROkNMKHibTg9lTRQ0Qg=
k8s.io/cli-runtime v0.31.3 h1:fEQD9Xokir78y7pVK/fCJN090/iYNrLHpFbGU4ul9TI=
k8s.io/cli-runtime v0.31.3/go.mod h1:Q2jkyTpl+f6AtodQvgDI8io3jrfr+Z0LyQBPJJ2Btq8=
k8s.io/client-go v0.31.3 h1:CAlZuM+PH2cm+86LOBemaJI/lQ5linJ6UFxKX/SoG+4=
k8s.io/client-go v0.31.3/go.mod h1:2CgjPUTpv3fE5dNygAr2NcM8nhHzXvxB8KL5gYc3kJs=
k8s.io/component-base v0.31.3 h1:DMCXXVx546Rfvhj+3cOm2EUxhS+EyztH423j+8sOwhQ=
k8s.io/component-base v0.31.3/go.mod h1:xME6BHfUOafRgT0rGVBGl7TuSg8Z9/deT7qq6w7qjIU=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 h1:MErs8YA0abvOqJ8gIupA1Tz6PKXYUw34XsGlA7uSL1k=
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094/go.mod h1:7ioBJr1A6igWjsR2fxq2EZ0mlMwYLejazSIc2bzMp2U=
k8s.io/kubectl v0.31.2 h1:gTxbvRkMBwvTSAlobiTVqsH6S8Aa1aGyBcu5xYLsn8M=
k8s.io/kubectl v0.31.2/go.mod h1:EyASYVU6PY+032RrTh5ahtSOMgoDRIux9V1JLKtG5xM=
k8s.io/kubectl v0.31.3 h1:3r111pCjPsvnR98oLLxDMwAeM6OPGmPty6gSKaLTQes=
k8s.io/kubectl v0.31.3/go.mod h1:lhMECDCbJN8He12qcKqs2QfmVo9Pue30geovBVpH5fs=
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 h1:MDF6h2H/h4tbzmtIKTuctcwZmY0tY9mD9fNT47QO6HI=
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
modernc.org/libc v1.37.6 h1:orZH3c5wmhIQFTXF+Nt+eeauyd+ZIt2BX6ARe+kD+aw=
Expand Down
74 changes: 73 additions & 1 deletion pkg/autodiscover/autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"path"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -62,6 +63,7 @@ type DiscoveredTestData struct {
AllPods []corev1.Pod
ProbePods []corev1.Pod
CSVToPodListMap map[types.NamespacedName][]*corev1.Pod
OperandPods []*corev1.Pod
ResourceQuotaItems []corev1.ResourceQuota
PodDisruptionBudgets []policyv1.PodDisruptionBudget
NetworkPolicies []networkingv1.NetworkPolicy
Expand Down Expand Up @@ -133,7 +135,7 @@ func createLabels(labelStrings []string) (labelObjects []labelObject) {

// DoAutoDiscover finds objects under test
//
//nolint:funlen
//nolint:funlen,gocyclo
func DoAutoDiscover(config *configuration.TestConfiguration) DiscoveredTestData {
oc := clientsholder.GetClientsHolder()

Expand Down Expand Up @@ -198,6 +200,17 @@ func DoAutoDiscover(config *configuration.TestConfiguration) DiscoveredTestData
log.Fatal("Failed to get the operator pods, err: %v", err)
}

// Best effort mode autodiscovery for operand (running-only) pods.
pods, _ := findPodsByLabels(oc.K8sClient.CoreV1(), nil, data.Namespaces)
if err != nil {
log.Fatal("Failed to get running pods, err: %v", err)
}

data.OperandPods, err = getOperandPodsFromTestCsvs(data.Csvs, pods)
if err != nil {
log.Fatal("Failed to get operand pods, err: %v", err)
}

openshiftVersion, err := getOpenshiftVersion(oc.OcpClient)
if err != nil {
log.Fatal("Failed to get the OpenShift version, err: %v", err)
Expand Down Expand Up @@ -355,3 +368,62 @@ func getPodsOwnedByCsv(csvName, operatorNamespace string, client *clientsholder.
}
return managedPods, nil
}

// getOperandPodsFromTestCsvs returns a subset of pods whose owner CRs are managed by any of the testCsvs.
func getOperandPodsFromTestCsvs(testCsvs []*olmv1Alpha.ClusterServiceVersion, pods []corev1.Pod) ([]*corev1.Pod, error) {
// Helper var to store all the managed crds from the operators under test
// They map key is "Kind.group/version" or "Kind.APIversion", which should be the same.
// e.g.: "Subscription.operators.coreos.com/v1alpha1"
crds := map[string]*olmv1Alpha.ClusterServiceVersion{}

// First, iterate on each testCsv to fill the helper crds map.
for _, csv := range testCsvs {
ownedCrds := csv.Spec.CustomResourceDefinitions.Owned
if len(ownedCrds) == 0 {
continue
}

for i := range ownedCrds {
crd := &ownedCrds[i]

_, group, found := strings.Cut(crd.Name, ".")
if !found {
return nil, fmt.Errorf("failed to parse resources and group from crd name %q", crd.Name)
}

log.Info("CSV %q owns crd %v", csv.Name, crd.Kind+"/"+group+"/"+crd.Version)

crdPath := path.Join(crd.Kind, group, crd.Version)
crds[crdPath] = csv
}
}

// Now, iterate on every pod in the list to check whether they're owned by any of the CRs that
// the csvs are managing.
operandPods := []*corev1.Pod{}
for i := range pods {
pod := &pods[i]
owners, err := podhelper.GetPodTopOwner(pod.Namespace, pod.OwnerReferences)
if err != nil {
return nil, fmt.Errorf("failed to get top owners of pod %v/%v: %v", pod.Namespace, pod.Name, err)
}

for _, owner := range owners {
versionedCrdPath := path.Join(owner.Kind, owner.APIVersion)

var csv *olmv1Alpha.ClusterServiceVersion
if csv = crds[versionedCrdPath]; csv == nil {
// The owner is not a CR or it's not a CR owned by any operator under test
continue
}

log.Info("Pod %v/%v has owner CR %s of CRD %q (CSV %v)", pod.Namespace, pod.Name,
owner.Name, versionedCrdPath, csv.Name)

operandPods = append(operandPods, pod)
break
}
}

return operandPods, nil
}
1 change: 1 addition & 0 deletions pkg/autodiscover/autodiscover_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func getAllNamespaces(oc corev1client.CoreV1Interface) (allNs []string, err erro
}
return allNs, nil
}

func getAllOperators(olmClient clientOlm.Interface) ([]*olmv1Alpha.ClusterServiceVersion, error) {
csvs := []*olmv1Alpha.ClusterServiceVersion{}

Expand Down
Loading

0 comments on commit 822dfe9

Please sign in to comment.