Fix operatorpolicy confusing status when invalid #413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
When the subscription section of the OperatorPolicy is invalid, the status might incorrectly indicate that other parts of the policy are invalid. This, combined with the many "... because the policy is invalid" clauses in the overall status, makes it very confusing to read and understand what parts might need to be fixed by the user.
Change summary
Refactored buildResources to simplify control flow, ensure accurate changed propagation, and improve early error reporting.
Added focused unit tests and dryrun tests; refined e2e case38 to reflect new validation behavior and to fix formatting.
Previous results:
The status message was extremely long, for example:
“NonCompliant; installPlanApproval is prohibited in spec.subscription, the namespace specified in spec.operatorGroup ('example') must match the namespace used for the subscription ('openshift-operators'), the status of the OperatorGroup could not be determined because the policy is invalid, the status of the Subscription could not be determined because the policy is invalid, the status of the InstallPlan could not be determined because the policy is invalid, a relevant installed ClusterServiceVersion could not be found, no CRDs were found for the operator, there are no relevant deployments because the ClusterServiceVersion is missing, the status of the CatalogSource could not be determined because the policy is invalid.”
After the fix:
The only meaningful part is now:
“installPlanApproval is prohibited in spec.subscription.”
Everything else was just unnecessary noise and is no longer included.
This part is actually incorrect: "the namespace specified in spec.operatorGroup ('example') must match the namespace used for the subscription ('openshift-operators'),".
Ref: https://issues.redhat.com/browse/ACM-16781