Skip to content

Commit

Permalink
Refactor: better uid lookup
Browse files Browse the repository at this point in the history
In both instances, the object is already assured to be non-nil, so there
are no errors that can occur here.

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
  • Loading branch information
JustinKuli authored and openshift-merge-robot committed Sep 7, 2023
1 parent 4eea290 commit 05177fb
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,10 @@ func (r *ConfigurationPolicyReconciler) cleanUpChildObjects(plc policyv1.Configu
} else if string(plc.Spec.PruneObjectBehavior) == "DeleteIfCreated" {
// if prune behavior is DeleteIfCreated, we need to check whether createdByPolicy
// is true and the UID is not stale
uid, uidFound, err := unstructured.NestedString(existing.Object, "metadata", "uid")

if !uidFound || err != nil {
log.Error(err, "Tried to pull UID from obj but the field did not exist or was not a string")
} else if object.Properties != nil &&
if object.Properties != nil &&
object.Properties.CreatedByPolicy != nil &&
*object.Properties.CreatedByPolicy &&
object.Properties.UID == uid {
object.Properties.UID == string(existing.GetUID()) {
needsDelete = true
}
}
Expand Down Expand Up @@ -2061,13 +2057,7 @@ func (r *ConfigurationPolicyReconciler) enforceByCreatingOrDeleting(obj singleOb
reason = reasonWantFoundCreated
msg = fmt.Sprintf("%v %v was created successfully", obj.gvr.Resource, idStr)

var uidIsString bool
uid, uidIsString, err = unstructured.NestedString(createdObj.Object, "metadata", "uid")

if !uidIsString || err != nil {
log.Error(err, "Tried to set UID in status but the field is not a string")
}

uid = string(createdObj.GetUID())
completed = true
}
} else {
Expand Down

0 comments on commit 05177fb

Please sign in to comment.