Skip to content

Commit b7b20ab

Browse files
committed
address some comments
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 9d4979c commit b7b20ab

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

pkg/controllers/workapplier/apply.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,7 @@ func validateOwnerReferences(
517517
// expected AppliedWork object. For safety reasons, Fleet will still do a sanity check.
518518
found := false
519519
for _, ownerRef := range inMemberClusterObjOwnerRefs {
520-
if ownerRef.UID == expectedAppliedWorkOwnerRef.UID &&
521-
ownerRef.Name == expectedAppliedWorkOwnerRef.Name &&
522-
ownerRef.Kind == expectedAppliedWorkOwnerRef.Kind &&
523-
ownerRef.APIVersion == expectedAppliedWorkOwnerRef.APIVersion {
520+
if ownerRefEqualsExpected(&ownerRef, expectedAppliedWorkOwnerRef) {
524521
found = true
525522
break
526523
}

pkg/controllers/workapplier/controller.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func (r *Reconciler) garbageCollectAppliedWork(ctx context.Context, work *fleetv
488488
return r.removeWorkFinalizer(ctx, work)
489489
}
490490
klog.ErrorS(err, "Failed to get AppliedWork", "appliedWork", work.Name)
491-
return ctrl.Result{Requeue: true}, controller.NewAPIServerError(false, err)
491+
return ctrl.Result{}, controller.NewAPIServerError(false, err)
492492
}
493493

494494
// Delete the appliedWork object.
@@ -552,11 +552,7 @@ func (r *Reconciler) updateOwnerReference(ctx context.Context, appliedWork *flee
552552
// Re-build the owner reference; update the blockOwnerDeletion field to false.
553553
updated := false
554554
for idx := range ownerRefs {
555-
if ownerRefs[idx].UID == appliedWorkOwnerRef.UID &&
556-
ownerRefs[idx].Name == appliedWorkOwnerRef.Name &&
557-
ownerRefs[idx].Kind == appliedWorkOwnerRef.Kind &&
558-
ownerRefs[idx].APIVersion == appliedWorkOwnerRef.APIVersion &&
559-
*ownerRefs[idx].BlockOwnerDeletion {
555+
if ownerRefEqualsExpected(&ownerRefs[idx], appliedWorkOwnerRef) {
560556
ownerRefs[idx].BlockOwnerDeletion = ptr.To(false)
561557
updated = true
562558
}

pkg/controllers/workapplier/preprocess.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,7 @@ func isInMemberClusterObjectDerivedFromManifestObj(inMemberClusterObj *unstructu
543543
// Verify if the owner reference still stands.
544544
curOwners := inMemberClusterObj.GetOwnerReferences()
545545
for idx := range curOwners {
546-
if curOwners[idx].UID == expectedAppliedWorkOwnerRef.UID &&
547-
curOwners[idx].Name == expectedAppliedWorkOwnerRef.Name &&
548-
curOwners[idx].Kind == expectedAppliedWorkOwnerRef.Kind &&
549-
curOwners[idx].APIVersion == expectedAppliedWorkOwnerRef.APIVersion {
546+
if ownerRefEqualsExpected(&curOwners[idx], expectedAppliedWorkOwnerRef) {
550547
return true
551548
}
552549
}
@@ -560,14 +557,19 @@ func removeOwnerRef(obj *unstructured.Unstructured, expectedAppliedWorkOwnerRef
560557

561558
// Re-build the owner references; remove the given one from the list.
562559
for idx := range ownerRefs {
563-
if ownerRefs[idx].UID == expectedAppliedWorkOwnerRef.UID &&
564-
ownerRefs[idx].Name == expectedAppliedWorkOwnerRef.Name &&
565-
ownerRefs[idx].Kind == expectedAppliedWorkOwnerRef.Kind &&
566-
ownerRefs[idx].APIVersion == expectedAppliedWorkOwnerRef.APIVersion {
560+
if ownerRefEqualsExpected(&ownerRefs[idx], expectedAppliedWorkOwnerRef) {
567561
// Skip the expected owner reference.
568562
continue
569563
}
570564
updatedOwnerRefs = append(updatedOwnerRefs, ownerRefs[idx])
571565
}
572566
obj.SetOwnerReferences(updatedOwnerRefs)
573567
}
568+
569+
// ownerRefEquals returns true if two owner references are equal based on UID, Name, Kind, and APIVersion.
570+
func ownerRefEqualsExpected(a, b *metav1.OwnerReference) bool {
571+
return a.UID == b.UID &&
572+
a.Name == b.Name &&
573+
a.Kind == b.Kind &&
574+
a.APIVersion == b.APIVersion
575+
}

pkg/controllers/workapplier/process.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,7 @@ func canApplyWithOwnership(inMemberClusterObj *unstructured.Unstructured, expect
356356
// Verify if the object is owned by Fleet.
357357
curOwners := inMemberClusterObj.GetOwnerReferences()
358358
for idx := range curOwners {
359-
if curOwners[idx].UID == expectedAppliedWorkOwnerRef.UID &&
360-
curOwners[idx].Name == expectedAppliedWorkOwnerRef.Name &&
361-
curOwners[idx].Kind == expectedAppliedWorkOwnerRef.Kind &&
362-
curOwners[idx].APIVersion == expectedAppliedWorkOwnerRef.APIVersion {
359+
if ownerRefEqualsExpected(&curOwners[idx], expectedAppliedWorkOwnerRef) {
363360
return true
364361
}
365362
}

0 commit comments

Comments
 (0)