Skip to content

Commit 9da76ab

Browse files
mprahlopenshift-merge-bot[bot]
authored andcommitted
Add a test for OperatorPolicy spec.versions templating
Relates: https://issues.redhat.com/browse/ACM-15658 Signed-off-by: mprahl <mprahl@users.noreply.github.com>
1 parent 69c7434 commit 9da76ab

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

test/integration/policy_install_operator_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test install Operator",
2424
const (
2525
testNS = "grcqeoptest-ns"
2626
policyNoGroupYAML = "../resources/policy_install_operator/operator_policy_no_group.yaml"
27+
policyNoGroupTmplYAML = "../resources/policy_install_operator/" +
28+
"operator_policy_no_group_templated_versions.yaml"
2729
policyWithGroupYAML = "../resources/policy_install_operator/operator_policy_with_group.yaml"
2830
policyAllDefaultsYAML = "../resources/policy_install_operator/operator_policy_all_defaults.yaml"
2931
cleanupPolicyYAML = "../resources/policy_install_operator/clean-up-grcqeoptest-ns.yaml"
@@ -246,6 +248,58 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test install Operator",
246248
g.Expect(opDeployment).NotTo(BeNil())
247249
}, defaultTimeoutSeconds*4, 5).Should(Succeed())
248250
})
251+
252+
It("RHACM4K-53812: Should be compliant with a templated versions array", func() {
253+
By("Updating the OperatorPolicy to be inform and include the templated versions array")
254+
_, err := common.OcHub("apply", "-f", policyNoGroupTmplYAML, "-n", userNamespace)
255+
Expect(err).ToNot(HaveOccurred())
256+
257+
var opPolicy *unstructured.Unstructured
258+
259+
By("Waiting for the OperatorPolicy update to be processed")
260+
Eventually(func(g Gomega) {
261+
opPolicy = utils.GetWithTimeout(
262+
clientManagedDynamic,
263+
common.GvrOperatorPolicy,
264+
"operator-policy"+noGroupSuffix,
265+
clusterNamespace,
266+
true,
267+
defaultTimeoutSeconds,
268+
)
269+
g.Expect(opPolicy).NotTo(BeNil())
270+
271+
observedGeneration, _, _ := unstructured.NestedInt64(
272+
opPolicy.Object, "status", "observedGeneration",
273+
)
274+
g.Expect(observedGeneration).To(Equal(opPolicy.GetGeneration()))
275+
}, defaultTimeoutSeconds, 1).Should(Succeed())
276+
277+
By("Verifying the ClusterServiceVersionCompliant condition is true")
278+
found := false
279+
conditions, _, _ := unstructured.NestedSlice(opPolicy.Object, "status", "conditions")
280+
281+
for _, condition := range conditions {
282+
conditionTyped, ok := condition.(map[string]interface{})
283+
if !ok {
284+
continue
285+
}
286+
287+
conditionType, ok := conditionTyped["type"].(string)
288+
if !ok || conditionType != "ClusterServiceVersionCompliant" {
289+
continue
290+
}
291+
292+
conditionStatus, ok := conditionTyped["status"].(string)
293+
Expect(ok).To(BeTrue(), "Expected the condition status to be a string")
294+
Expect(conditionStatus).To(Equal("True"))
295+
296+
found = true
297+
298+
break
299+
}
300+
301+
Expect(found).To(BeTrue(), "Expected to find a ClusterServiceVersionCompliant condition")
302+
})
249303
})
250304

251305
Context("When an OperatorGroup is specified", func() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: policy.open-cluster-management.io/v1
2+
kind: Policy
3+
metadata:
4+
name: test-op-43544
5+
annotations:
6+
policy.open-cluster-management.io/description: Test rhacm4k-43544
7+
spec:
8+
disabled: false
9+
remediationAction: inform
10+
policy-templates:
11+
- objectDefinition:
12+
apiVersion: policy.open-cluster-management.io/v1beta1
13+
kind: OperatorPolicy
14+
metadata:
15+
name: operator-policy-43544
16+
spec:
17+
remediationAction: inform
18+
severity: medium
19+
complianceType: musthave
20+
subscription:
21+
channel: stable-3.8
22+
name: quay-operator
23+
namespace: grcqeoptest-ns-43544
24+
source: redhat-operators
25+
sourceNamespace: openshift-marketplace
26+
upgradeApproval: Automatic
27+
versions:
28+
- '{{ (lookup "operators.coreos.com/v1alpha1" "Subscription" "grcqeoptest-ns-43544" "quay-operator").status.installedCSV | default "no-value" }}'

0 commit comments

Comments
 (0)