Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…roller#112

Signed-off-by: Will Kutler <wkutler@redhat.com>

fmt

Signed-off-by: Will Kutler <wkutler@redhat.com>

fmt

Signed-off-by: Will Kutler <wkutler@redhat.com>
  • Loading branch information
willkutler authored and openshift-merge-robot committed Apr 4, 2023
1 parent e9210ef commit da733be
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,6 @@ func (r *ConfigurationPolicyReconciler) handleSingleObj(
) {
objLog := log.WithValues("object", obj.name, "policy", obj.policy.Name, "index", obj.index)

var err error
var compliant bool

compliantObject := map[string]map[string]interface{}{
Expand All @@ -1602,11 +1601,13 @@ func (r *ConfigurationPolicyReconciler) handleSingleObj(
// it is a musthave and it does not exist, so it must be created
if strings.EqualFold(string(remediation), string(policyv1.Enforce)) {
var uid string
statusUpdateNeeded, uid, err = r.enforceByCreatingOrDeleting(obj)
completed, reason, msg, uid, err := r.enforceByCreatingOrDeleting(obj)

if err != nil {
// violation created for handling error
objLog.Error(err, "Could not handle missing musthave object")

statusUpdateNeeded = addConditionToStatus(obj.policy, obj.index, completed, reason, msg)
} else {
// object is missing and will be created, so send noncompliant "does not exist" event first
// (this check has already happened, but we send the event here to avoid the status flipping on an
Expand All @@ -1622,6 +1623,8 @@ func (r *ConfigurationPolicyReconciler) handleSingleObj(
// update parent policy status
r.addForUpdate(obj.policy, true)

statusUpdateNeeded = addConditionToStatus(obj.policy, obj.index, completed, reason, msg)

created := true
creationInfo = &policyv1.ObjectProperties{
CreatedByPolicy: &created,
Expand All @@ -1637,10 +1640,12 @@ func (r *ConfigurationPolicyReconciler) handleSingleObj(
if exists && !obj.shouldExist {
// it is a mustnothave but it exist, so it must be deleted
if strings.EqualFold(string(remediation), string(policyv1.Enforce)) {
statusUpdateNeeded, _, err = r.enforceByCreatingOrDeleting(obj)
completed, reason, msg, _, err := r.enforceByCreatingOrDeleting(obj)
if err != nil {
objLog.Error(err, "Could not handle existing mustnothave object")
}

statusUpdateNeeded = addConditionToStatus(obj.policy, obj.index, completed, reason, msg)
} else { // inform
compliant = false
}
Expand Down Expand Up @@ -1994,7 +1999,7 @@ func getNamesOfKind(
// mustnothave object does exist. Eg, it does not handle the case where a targeted update would need
// to be made to an object.
func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleObject) (
result bool, uid string, erro error,
result bool, reason string, msg string, uid string, erro error,
) {
log := log.WithValues(
"object", obj.name,
Expand All @@ -2012,7 +2017,6 @@ func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleOb
}

var completed bool
var reason, msg string
var err error

if obj.shouldExist {
Expand Down Expand Up @@ -2048,7 +2052,7 @@ func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleOb
}
}

return addConditionToStatus(obj.policy, obj.index, completed, reason, msg), uid, err
return completed, reason, msg, uid, err
}

// checkMessageSimilarity decides whether to append a new condition to a configurationPolicy status
Expand Down

0 comments on commit da733be

Please sign in to comment.