Skip to content

Commit

Permalink
Consolidate mustnothave deletion compliance 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 33da9d1 commit cf2b973
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
reasonWantFoundExists = "Resource found as expected"
reasonWantFoundCreated = "K8s creation success"
reasonUpdateSuccess = "K8s update success"
reasonDeleteSuccess = "K8s deletion success"
reasonWantFoundNoMatch = "Resource found but does not match"
reasonWantFoundDNE = "Resource not found but should exist"
reasonWantNotFoundExists = "Resource found but should not exist"
Expand Down Expand Up @@ -2045,7 +2046,7 @@ func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleOb
reason = "K8s deletion error"
msg = fmt.Sprintf("%v %v exists, and cannot be deleted, reason: `%v`", obj.gvr.Resource, idStr, err)
} else {
reason = "K8s deletion success"
reason = reasonDeleteSuccess
msg = fmt.Sprintf("%v %v existed, and was deleted successfully", obj.gvr.Resource, idStr)
obj.object = nil
}
Expand Down
18 changes: 18 additions & 0 deletions controllers/configurationpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,24 @@ func TestCreateStatus(t *testing.T) {
"configmaps [buzz] missing as expected, therefore, this object template is compliant in namespace " +
"toy-story",
},
{
"must not have single object deleted",
"configmaps",
map[string]*objectTmplEvalResultWithEvent{
"toy-story": {
result: objectTmplEvalResult{
objectNames: []string{"buzz"},
},
event: objectTmplEvalEvent{
compliant: true,
reason: reasonDeleteSuccess,
},
},
},
true,
"K8s deletion success",
"configmaps [buzz] existed, and was deleted successfully in namespace toy-story",
},
{
"unnamed object single error",
"configmaps",
Expand Down
4 changes: 4 additions & 0 deletions controllers/configurationpolicy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ func createStatus(
reasonWantFoundExists,
reasonWantFoundCreated,
reasonUpdateSuccess,
reasonDeleteSuccess,
reasonWantFoundDNE,
reasonWantFoundNoMatch,
reasonWantNotFoundDNE,
Expand Down Expand Up @@ -575,6 +576,9 @@ func createStatus(
case reasonUpdateSuccess:
generatedReason = reasonUpdateSuccess
generatedMsg = fmt.Sprintf("%s%s was updated successfully", resourceName, namesStr)
case reasonDeleteSuccess:
generatedReason = reasonDeleteSuccess
generatedMsg = fmt.Sprintf("%s%s existed, and was deleted successfully", resourceName, namesStr)
case reasonWantFoundDNE:
generatedReason = "K8s does not have a `must have` object"
compliancyDetailsMsg += fmt.Sprintf("%s%s not found", resourceName, namesStr)
Expand Down

0 comments on commit cf2b973

Please sign in to comment.