Skip to content

Commit 0ead4d4

Browse files
authored
feat: add support for degraded diff drift calculation (#209)
1 parent 8af6fcc commit 0ead4d4

File tree

9 files changed

+907
-40
lines changed

9 files changed

+907
-40
lines changed

pkg/controllers/workapplier/apply.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,12 @@ func (r *Reconciler) serverSideApply(
320320
Resource(*gvr).Namespace(manifestObj.GetNamespace()).
321321
Apply(ctx, manifestObj.GetName(), manifestObj, applyOpts)
322322
if err != nil {
323-
wrappedErr := controller.NewAPIServerError(false, err)
324-
return nil, fmt.Errorf("failed to apply the manifest object: %w", wrappedErr)
323+
// Note (chenyu1): the current implementation of NewAPIServerError flattens the passed-in error,
324+
// effectively dropping the error hierarchy. This can be an issue if the caller of the function
325+
// needs to identify a specific error in the hierarchy; to avoid this, this method will not return
326+
// any error wrapped by NewAPIServerError.
327+
_ = controller.NewAPIServerError(false, err)
328+
return nil, fmt.Errorf("failed to apply the manifest object: an error is returned by the API server: %w", err)
325329
}
326330
return appliedObj, nil
327331
}

pkg/controllers/workapplier/controller.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ const (
276276
ApplyOrReportDiffResTypeNotTakenOver ManifestProcessingApplyOrReportDiffResultType = "NotTakenOver"
277277
ApplyOrReportDiffResTypeFailedToRunDriftDetection ManifestProcessingApplyOrReportDiffResultType = "FailedToRunDriftDetection"
278278
ApplyOrReportDiffResTypeFoundDrifts ManifestProcessingApplyOrReportDiffResultType = "FoundDrifts"
279+
ApplyOrReportDiffResTypeFoundDriftsInDegradedMode ManifestProcessingApplyOrReportDiffResultType = "FoundDriftsInDegradedMode"
279280
// Note that the reason string below uses the same value as kept in the old work applier.
280281
ApplyOrReportDiffResTypeFailedToApply ManifestProcessingApplyOrReportDiffResultType = "ManifestApplyFailed"
281282

@@ -297,15 +298,17 @@ const (
297298
ApplyOrReportDiffResTypeFailedToReportDiff ManifestProcessingApplyOrReportDiffResultType = "FailedToReportDiff"
298299

299300
// The result type for successful diff reportings.
300-
ApplyOrReportDiffResTypeFoundDiff ManifestProcessingApplyOrReportDiffResultType = "FoundDiff"
301-
ApplyOrReportDiffResTypeNoDiffFound ManifestProcessingApplyOrReportDiffResultType = "NoDiffFound"
301+
ApplyOrReportDiffResTypeFoundDiff ManifestProcessingApplyOrReportDiffResultType = "FoundDiff"
302+
ApplyOrReportDiffResTypeFoundDiffInDegradedMode ManifestProcessingApplyOrReportDiffResultType = "FoundDiffInDegradedMode"
303+
ApplyOrReportDiffResTypeNoDiffFound ManifestProcessingApplyOrReportDiffResultType = "NoDiffFound"
302304
)
303305

304306
const (
305307
// The descriptions for different diff reporting result types.
306-
ApplyOrReportDiffResTypeFailedToReportDiffDescription = "Failed to report the diff between the hub cluster and the member cluster (error = %s)"
307-
ApplyOrReportDiffResTypeNoDiffFoundDescription = "No diff has been found between the hub cluster and the member cluster"
308-
ApplyOrReportDiffResTypeFoundDiffDescription = "Diff has been found between the hub cluster and the member cluster"
308+
ApplyOrReportDiffResTypeFailedToReportDiffDescription = "Failed to report the diff between the hub cluster and the member cluster (error = %s)"
309+
ApplyOrReportDiffResTypeNoDiffFoundDescription = "No diff has been found between the hub cluster and the member cluster"
310+
ApplyOrReportDiffResTypeFoundDiffDescription = "Diff has been found between the hub cluster and the member cluster"
311+
ApplyOrReportDiffResTypeFoundDiffInDegradedModeDescription = "Diff has been found in degraded mode: cannot perform partial comparison as the member cluster API server rejected the manifest object (object is invalid)"
309312
)
310313

311314
var (
@@ -319,6 +322,7 @@ var (
319322
ApplyOrReportDiffResTypeNotTakenOver,
320323
ApplyOrReportDiffResTypeFailedToRunDriftDetection,
321324
ApplyOrReportDiffResTypeFoundDrifts,
325+
ApplyOrReportDiffResTypeFoundDriftsInDegradedMode,
322326
ApplyOrReportDiffResTypeFailedToApply,
323327
ApplyOrReportDiffResTypeAppliedWithFailedDriftDetection,
324328
ApplyOrReportDiffResTypeApplied,

0 commit comments

Comments
 (0)