Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report compliant when NS missing in mustnothave #245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/operatorpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (r *OperatorPolicyReconciler) buildResources(ctx context.Context, policy *p
return sub, opGroup, false, fmt.Errorf("error getting operator namespace: %w", err)
}

if gotNamespace == nil {
if gotNamespace == nil && policy.Spec.ComplianceType.IsMustHave() {
validationErrors = append(validationErrors,
fmt.Errorf("the operator namespace ('%v') does not exist", opGroupNS))
}
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/case38_install_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,44 @@ var _ = Describe("Testing OperatorPolicy", Ordered, func() {
)
})
})
Describe("Test mustnothave message when the namespace does not exist", func() {
const (
opPolYAML = "../resources/case38_operator_install/operator-policy-no-group.yaml"
opPolName = "oppol-no-group"
subName = "project-quay"
)

BeforeEach(func() {
utils.Kubectl("create", "ns", opPolTestNS)
DeferCleanup(func() {
utils.Kubectl("delete", "ns", opPolTestNS)
})

createObjWithParent(parentPolicyYAML, parentPolicyName,
opPolYAML, opPolTestNS, gvrPolicy, gvrOperatorPolicy)
})

It("should report compliant", func() {
// change the subscription namespace, and the complianceType to mustnothave
utils.Kubectl("patch", "operatorpolicy", opPolName, "-n", opPolTestNS, "--type=json", "-p",
`[{"op": "replace", "path": "/spec/subscription/namespace", "value": "imaginaryfriend"},`+
`{"op": "replace", "path": "/spec/complianceType", "value": "mustnothave"}]`)

check(
opPolName,
false,
[]policyv1.RelatedObject{},
metav1.Condition{
Type: "ValidPolicySpec",
Status: metav1.ConditionTrue,
Reason: "PolicyValidated",
Message: "the policy spec is valid",
},
"the policy spec is valid",
)
checkCompliance(opPolName, opPolTestNS, eventuallyTimeout, policyv1.Compliant)
})
})
Describe("Testing mustnothave behavior of operator groups in DeleteIfUnused mode", Ordered, func() {
const (
opPolYAML = "../resources/case38_operator_install/operator-policy-mustnothave-any-version.yaml"
Expand Down