Skip to content

Commit f40a845

Browse files
mprahlopenshift-merge-bot[bot]
authored andcommitted
Add more details to Gatekeeper compliance history failures
Relates: stolostron/backlog#27551 Signed-off-by: mprahl <mprahl@users.noreply.github.com>
1 parent 03c3e16 commit f40a845

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

test/integration/compliance_history_test.go

+20-9
Original file line numberDiff line numberDiff line change
@@ -500,33 +500,41 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the compliance history API",
500500

501501
// Ensure the ConstraintTemplate has 1 event
502502
g.Expect(policyToEventDetails["complianceapitest"]).To(HaveLen(1))
503-
g.Expect(policyToEventDetails["complianceapitest"][0]["compliance"]).To(Equal("Compliant"))
504-
expectedMsg := "ConstraintTemplate complianceapitest was created successfully"
505-
g.Expect(policyToEventDetails["complianceapitest"][0]["message"]).To(Equal(expectedMsg))
503+
msg := policyToEventDetails["complianceapitest"][0]["message"]
504+
g.Expect(policyToEventDetails["complianceapitest"][0]["compliance"]).To(
505+
Equal("Compliant"),
506+
fmt.Sprintf("The ConstraintTemplate was not compliant on cluster %s: %s", cluster, msg),
507+
)
508+
g.Expect(msg).To(Equal("ConstraintTemplate complianceapitest was created successfully"))
506509

507510
// Ensure the constraint has 2 or more events. More than one template-error compliance event can
508511
// be set based on race conditions.
509512
lenOk := len(policyToEventDetails["compliance-api"]) >= 2
510513
g.Expect(lenOk).To(
511514
BeTrue(),
512515
fmt.Sprintf(
513-
"Expected the compliance-api policy to have 2 or more compliance events, got %d",
514-
len(policyToEventDetails["compliance-api"]),
516+
"Expected the compliance-api policy to have 2 or more compliance events, got %d on cluster %s",
517+
len(policyToEventDetails["compliance-api"]), cluster,
515518
),
516519
)
517520
// Sorted by timestamp in descending order
518521
g.Expect(policyToEventDetails["compliance-api"][0]["compliance"]).To(Equal("NonCompliant"))
519-
expectedMsg = "warn - All configmaps must have a 'my-gk-test' label (on ConfigMap " +
522+
expectedMsg := "warn - All configmaps must have a 'my-gk-test' label (on ConfigMap " +
520523
"compliance-api-test/compliance-api-test)"
521-
g.Expect(policyToEventDetails["compliance-api"][0]["message"]).To(Equal(expectedMsg))
524+
g.Expect(policyToEventDetails["compliance-api"][0]["message"]).To(
525+
Equal(expectedMsg),
526+
"The constraint compliance message didn't match on cluster "+cluster,
527+
)
522528

523529
// All other compliance events should be a template-error
524530
for _, eventDetails := range policyToEventDetails["compliance-api"][1:] {
525531
g.Expect(eventDetails["compliance"]).To(Equal("NonCompliant"))
526532
expectedMsg = "template-error; Mapping not found, check if the required ConstraintTemplate has " +
527533
"been deployed: the resource version was not found: constraints.gatekeeper.sh/v1beta1, " +
528534
"Kind=ComplianceAPITest"
529-
g.Expect(eventDetails["message"]).To(Equal(expectedMsg))
535+
g.Expect(eventDetails["message"]).To(
536+
Equal(expectedMsg), "Unexpected constraint NonCompliant event on cluster "+cluster,
537+
)
530538
}
531539
}
532540
// It can take a while for the Gatekeeper audit pod to produce audit results.
@@ -557,7 +565,10 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the compliance history API",
557565
g.Expect(events).To(HaveLen(1), fmt.Sprintf("expected cluster %s to have one compliant event", cluster))
558566

559567
eventDetails := events[0].(map[string]interface{})["event"].(map[string]interface{})
560-
g.Expect(eventDetails["compliance"]).To(Equal("Compliant"))
568+
g.Expect(eventDetails["compliance"]).To(
569+
Equal("Compliant"),
570+
fmt.Sprintf("The constraint was not compliant on cluster %s: %s", cluster, eventDetails["message"]),
571+
)
561572
g.Expect(eventDetails["message"]).To(Equal("The constraint has no violations"))
562573
}
563574
}, defaultTimeoutSeconds*2, 1).Should(Succeed())

0 commit comments

Comments
 (0)