diff --git a/controllers/configurationpolicy_controller.go b/controllers/configurationpolicy_controller.go index 376c719e..b80cffc0 100644 --- a/controllers/configurationpolicy_controller.go +++ b/controllers/configurationpolicy_controller.go @@ -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" @@ -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 } diff --git a/controllers/configurationpolicy_controller_test.go b/controllers/configurationpolicy_controller_test.go index 280cd019..3a92fd85 100644 --- a/controllers/configurationpolicy_controller_test.go +++ b/controllers/configurationpolicy_controller_test.go @@ -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", diff --git a/controllers/configurationpolicy_utils.go b/controllers/configurationpolicy_utils.go index ba706aa9..2283b571 100644 --- a/controllers/configurationpolicy_utils.go +++ b/controllers/configurationpolicy_utils.go @@ -491,6 +491,7 @@ func createStatus( reasonWantFoundExists, reasonWantFoundCreated, reasonUpdateSuccess, + reasonDeleteSuccess, reasonWantFoundDNE, reasonWantFoundNoMatch, reasonWantNotFoundDNE, @@ -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)