Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelawyu committed Jan 15, 2025
1 parent 36bed76 commit 7af1d2f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions pkg/controllers/workapplier/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (r *Reconciler) createManifestObject(
}
createdObj, err := r.spokeDynamicClient.Resource(*gvr).Namespace(manifestObject.GetNamespace()).Create(ctx, manifestObject, createOpts)
if err != nil {
_ = controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to create manifest object: %w", err)
wrappedErr := controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to create manifest object: %w", wrappedErr)
}
return createdObj, nil
}
Expand Down Expand Up @@ -240,8 +240,8 @@ func (r *Reconciler) threeWayMergePatch(
Resource(*gvr).Namespace(manifestObj.GetNamespace()).
Patch(ctx, manifestObj.GetName(), patch.Type(), data, patchOpts)
if err != nil {
_ = controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to patch the manifest object: %w", err)
wrappedErr := controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to patch the manifest object: %w", wrappedErr)
}
return patchedObj, nil
}
Expand Down Expand Up @@ -282,8 +282,8 @@ func (r *Reconciler) serverSideApply(
Resource(*gvr).Namespace(manifestObj.GetNamespace()).
Apply(ctx, manifestObj.GetName(), manifestObj, applyOpts)
if err != nil {
_ = controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to apply the manifest object: %w", err)
wrappedErr := controller.NewAPIServerError(false, err)
return nil, fmt.Errorf("failed to apply the manifest object: %w", wrappedErr)
}
return appliedObj, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/workapplier/drift_detection_takeover.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (r *Reconciler) takeOverPreExistingObject(
Resource(*gvr).Namespace(inMemberClusterObjCopy.GetNamespace()).
Update(ctx, inMemberClusterObjCopy, metav1.UpdateOptions{})
if err != nil {
_ = controller.NewAPIServerError(false, err)
return nil, nil, fmt.Errorf("failed to take over the object: %w", err)
wrappedErr := controller.NewAPIServerError(false, err)
return nil, nil, fmt.Errorf("failed to take over the object: %w", wrappedErr)
}

return takenOverInMemberClusterObj, nil, nil
Expand Down Expand Up @@ -312,8 +312,8 @@ func (r *Reconciler) removeLeftBehindAppliedWorkOwnerRefs(ctx context.Context, o
switch {
case err != nil && !errors.IsNotFound(err):
// An unexpected error occurred.
_ = controller.NewAPIServerError(true, err)
return nil, fmt.Errorf("failed to get the Work object: %w", err)
wrappedErr := controller.NewAPIServerError(true, err)
return nil, fmt.Errorf("failed to get the Work object: %w", wrappedErr)
case err == nil:
// The AppliedWork owner reference is valid; no need for removal.
//
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/workapplier/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ func (r *Reconciler) removeOneLeftOverManifest(
return nil
case err != nil:
// Failed to retrieve the object from the member cluster.
_ = controller.NewAPIServerError(true, err)
return fmt.Errorf("failed to retrieve the object from the member cluster (gvr=%+v, manifestObj=%+v): %w", gvr, klog.KRef(manifestNamespace, manifestName), err)
wrappedErr := controller.NewAPIServerError(true, err)
return fmt.Errorf("failed to retrieve the object from the member cluster (gvr=%+v, manifestObj=%+v): %w", gvr, klog.KRef(manifestNamespace, manifestName), wrappedErr)
case inMemberClusterObj.GetDeletionTimestamp() != nil:
// The object has been marked for deletion; no further action is needed.
return nil
Expand Down Expand Up @@ -485,9 +485,9 @@ func (r *Reconciler) removeOneLeftOverManifest(
removeOwnerRef(inMemberClusterObj, expectedAppliedWorkOwnerRef)
if _, err := r.spokeDynamicClient.Resource(gvr).Namespace(manifestNamespace).Update(ctx, inMemberClusterObj, metav1.UpdateOptions{}); err != nil && !apierrors.IsNotFound(err) {
// Failed to drop the ownership.
_ = controller.NewAPIServerError(false, err)
wrappedErr := controller.NewAPIServerError(false, err)
return fmt.Errorf("failed to drop the ownership of the object (gvr=%+v, manifestObj=%+v, inMemberClusterObj=%+v, expectedAppliedWorkOwnerRef=%+v): %w",
gvr, klog.KRef(manifestNamespace, manifestName), klog.KObj(inMemberClusterObj), *expectedAppliedWorkOwnerRef, err)
gvr, klog.KRef(manifestNamespace, manifestName), klog.KObj(inMemberClusterObj), *expectedAppliedWorkOwnerRef, wrappedErr)
}
default:
// Fleet is the sole owner of the object; in this case, Fleet will delete the object.
Expand All @@ -510,9 +510,9 @@ func (r *Reconciler) removeOneLeftOverManifest(
}
if err := r.spokeDynamicClient.Resource(gvr).Namespace(manifestNamespace).Delete(ctx, manifestName, deleteOpts); err != nil && !apierrors.IsNotFound(err) {
// Failed to delete the object from the member cluster.
_ = controller.NewAPIServerError(false, err)
wrappedErr := controller.NewAPIServerError(false, err)
return fmt.Errorf("failed to delete the object (gvr=%+v, manifestObj=%+v, inMemberClusterObj=%+v, expectedAppliedWorkOwnerRef=%+v): %w",
gvr, klog.KRef(manifestNamespace, manifestName), klog.KObj(inMemberClusterObj), *expectedAppliedWorkOwnerRef, err)
gvr, klog.KRef(manifestNamespace, manifestName), klog.KObj(inMemberClusterObj), *expectedAppliedWorkOwnerRef, wrappedErr)
}
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/workapplier/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ func (r *Reconciler) findInMemberClusterObjectFor(
return false
default:
// An unexpected error has occurred.
_ = controller.NewAPIServerError(true, err)
bundle.applyErr = fmt.Errorf("failed to find the corresponding object for the manifest object in the member cluster: %w", err)
wrappedErr := controller.NewAPIServerError(true, err)
bundle.applyErr = fmt.Errorf("failed to find the corresponding object for the manifest object in the member cluster: %w", wrappedErr)
bundle.applyResTyp = ManifestProcessingApplyResultTypeFailedToFindObjInMemberCluster
klog.ErrorS(err,
klog.ErrorS(wrappedErr,
"Failed to find the corresponding object for the manifest object in the member cluster",
"work", klog.KObj(work), "GVR", *bundle.gvr, "manifestObj", klog.KObj(bundle.manifestObj),
"expectedAppliedWorkOwnerRef", *expectedAppliedWorkOwnerRef)
Expand Down

0 comments on commit 7af1d2f

Please sign in to comment.