Skip to content

Commit

Permalink
Shorten some of the compliant messages
Browse files Browse the repository at this point in the history
Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl committed Jun 28, 2023
1 parent 36596a4 commit dd11dbf
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 37 deletions.
2 changes: 1 addition & 1 deletion controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleOb
} else {
log.V(2).Info("Created missing must have object", "resource", obj.gvr.Resource, "name", obj.name)
reason = reasonWantFoundCreated
msg = fmt.Sprintf("%v %v was missing, and was created successfully", obj.gvr.Resource, idStr)
msg = fmt.Sprintf("%v %v was created successfully", obj.gvr.Resource, idStr)

var uidIsString bool
uid, uidIsString, err = unstructured.NestedString(obj.object.Object, "metadata", "uid")
Expand Down
19 changes: 8 additions & 11 deletions controllers/configurationpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must have` object already exists",
"configmaps [buzz] found as specified, therefore, this object template is compliant in namespace toy-story",
"configmaps [buzz] found as specified in namespace toy-story",
},
{
"must have single object compliant cluster-scoped",
Expand All @@ -479,7 +479,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must have` object already exists",
"namespaces [movies] found as specified, therefore, this object template is compliant",
"namespaces [movies] found as specified",
},
{
"must have multiple namespaces single object compliant",
Expand All @@ -506,8 +506,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must have` object already exists",
"configmaps [buzz] found as specified, therefore, this object template is compliant in namespaces: " +
"toy-story, toy-story3",
"configmaps [buzz] found as specified in namespaces: toy-story, toy-story3",
},
{
"must have unnamed object compliant",
Expand All @@ -534,8 +533,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must have` object already exists",
"secrets [bo-peep] found as specified, therefore, this object template is compliant in namespace " +
"toy-story4; secrets [buzz] found as specified, therefore, this object template is compliant in " +
"secrets [bo-peep] found as specified in namespace toy-story4; secrets [buzz] found as specified in " +
"namespace toy-story",
},
{
Expand All @@ -554,7 +552,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s creation success",
"configmaps [buzz] was missing, and was created successfully in namespace toy-story",
"configmaps [buzz] was created successfully in namespace toy-story",
},
{
"must have single object created in one namespace and exists in another",
Expand All @@ -581,8 +579,8 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must have` object already exists; K8s creation success",
"configmaps [buzz] found as specified, therefore, this object template is compliant in namespace " +
"toy-story4; configmaps [buzz] was missing, and was created successfully in namespace toy-story",
"configmaps [buzz] found as specified in namespace toy-story4; configmaps [buzz] was created " +
"successfully in namespace toy-story",
},
{
"must have single object not found in one of the namespaces",
Expand Down Expand Up @@ -663,8 +661,7 @@ func TestCreateStatus(t *testing.T) {
},
true,
"K8s `must not have` object already missing",
"configmaps [buzz] missing as expected, therefore, this object template is compliant in namespace " +
"toy-story",
"configmaps [buzz] missing as expected in namespace toy-story",
},
{
"must not have single object deleted",
Expand Down
10 changes: 3 additions & 7 deletions controllers/configurationpolicy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,10 @@ func createStatus(
switch reason {
case reasonWantFoundExists:
generatedReason = "K8s `must have` object already exists"
generatedMsg = fmt.Sprintf(
"%s%s found as specified, therefore, this object template is compliant", resourceName, namesStr,
)
generatedMsg = fmt.Sprintf("%s%s found as specified", resourceName, namesStr)
case reasonWantFoundCreated:
generatedReason = reasonWantFoundCreated
generatedMsg = fmt.Sprintf("%s%s was missing, and was created successfully", resourceName, namesStr)
generatedMsg = fmt.Sprintf("%s%s was created successfully", resourceName, namesStr)
case reasonUpdateSuccess:
generatedReason = reasonUpdateSuccess
generatedMsg = fmt.Sprintf("%s%s was updated successfully", resourceName, namesStr)
Expand All @@ -590,9 +588,7 @@ func createStatus(
compliancyDetailsMsg += fmt.Sprintf("%s%s found", resourceName, namesStr)
case reasonWantNotFoundDNE:
generatedReason = "K8s `must not have` object already missing"
compliancyDetailsMsg += fmt.Sprintf(
"%s%s missing as expected, therefore, this object template is compliant", resourceName, namesStr,
)
compliancyDetailsMsg += fmt.Sprintf("%s%s missing as expected", resourceName, namesStr)
default:
// If it's not one of the above reasons, then skip consolidation. This is likely an error being
// reported.
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/case13_templatization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ var _ = Describe("Test templatization", func() {
case13LookupClusterClaim, testNamespace, true, defaultTimeoutSeconds)

return utils.GetStatusMessage(managedPlc)
}, defaultTimeoutSeconds, 1).Should(Equal(
"pods [testvalue] found as specified, therefore, this object template is compliant in " +
"namespace default",
))
}, defaultTimeoutSeconds, 1).Should(Equal("pods [testvalue] found as specified in namespace default"))
utils.Kubectl("delete", "configurationpolicy", case13LookupSecret, "-n", testNamespace)
utils.Kubectl("delete", "configurationpolicy", case13LookupClusterClaim, "-n", testNamespace)
})
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/case27_showupdateinstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ var _ = Describe("Verify status update after updating object", Ordered, func() {
case27ConfigPolicyName, testNamespace, true, defaultTimeoutSeconds)

return utils.GetStatusMessage(managedPlc)
}, 120, 1).Should(Equal(
"configmaps [case27-map] found as specified, therefore, this object template is compliant in " +
"namespace default",
))
}, 120, 1).Should(Equal("configmaps [case27-map] found as specified in namespace default"))
})
It("configmap and status should be updated properly on the managed cluster", func() {
By("Updating " + case27ConfigPolicyName + " on managed")
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/case4_clusterversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ var _ = Describe("Test cluster version obj template handling", func() {
case4ConfigPolicyNameInform, testNamespace, true, defaultTimeoutSeconds)

return utils.GetStatusMessage(managedPlc)
}, 120, 1).Should(Equal(
"clusterversions [version] found as specified, therefore, this object template is compliant"))
}, 120, 1).Should(Equal("clusterversions [version] found as specified"))
})
It("Cleans up", func() {
policies := []string{
Expand Down
12 changes: 4 additions & 8 deletions test/e2e/case5_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,15 @@ var _ = Describe("Test multiple obj template handling", func() {
case5MultiNSInformConfigPolicyName, 0, defaultTimeoutSeconds, expectedMsg)
})
It("Should show merged messages when it is multiple namespaces", func() {
expectedMsg := "pods [case5-multi-namespace-enforce-pod] found as specified, therefore, this object " +
"template is compliant in namespaces: n1, n2, n3"
expectedMsg := "pods [case5-multi-namespace-enforce-pod] found as specified in namespaces: n1, n2, n3"
utils.Kubectl("apply", "-f", case5EnforceYaml)
utils.DoConfigPolicyMessageTest(clientManagedDynamic, gvrConfigPolicy, testNamespace,
case5MultiNSConfigPolicyName, 0, defaultTimeoutSeconds, expectedMsg)
})
It("Should show 3 merged messages when it is multiple namespaces and multiple obj-template", func() {
firstMsg := "pods [case5-multi-obj-temp-pod-11] found as specified, therefore, this object template is " +
"compliant in namespaces: n1, n2, n3"
secondMsg := "pods [case5-multi-obj-temp-pod-22] found as specified, therefore, this object template is " +
"compliant in namespaces: n1, n2, n3"
thirdMsg := "pods [case5-multi-obj-temp-pod-33] found as specified, therefore, this object template is " +
"compliant in namespaces: n1, n2, n3"
firstMsg := "pods [case5-multi-obj-temp-pod-11] found as specified in namespaces: n1, n2, n3"
secondMsg := "pods [case5-multi-obj-temp-pod-22] found as specified in namespaces: n1, n2, n3"
thirdMsg := "pods [case5-multi-obj-temp-pod-33] found as specified in namespaces: n1, n2, n3"
utils.Kubectl("apply", "-f", case5MultiObjTmpYaml)
utils.DoConfigPolicyMessageTest(clientManagedDynamic, gvrConfigPolicy, testNamespace,
case5MultiObjNSConfigPolicyName, 0, defaultTimeoutSeconds, firstMsg)
Expand Down

0 comments on commit dd11dbf

Please sign in to comment.