Skip to content

Commit 15623ab

Browse files
authored
fix: refactor the work applier code to reduce conditional checking + address an issue in work applier where some errors might not get properly surfaced in ReportDiff mode (#183)
1 parent 11f130e commit 15623ab

22 files changed

+1055
-477
lines changed

pkg/controllers/workapplier/availability_tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *Reconciler) trackInMemberClusterObjAvailability(ctx context.Context, bu
4848

4949
doWork := func(pieces int) {
5050
bundle := bundles[pieces]
51-
if !isManifestObjectApplied(bundle.applyResTyp) {
51+
if !isManifestObjectApplied(bundle.applyOrReportDiffResTyp) {
5252
// The manifest object in the bundle has not been applied yet. No availability check
5353
// is needed.
5454
bundle.availabilityResTyp = ManifestProcessingAvailabilityResultTypeSkipped

pkg/controllers/workapplier/availability_tracker_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,74 +1047,74 @@ func TestTrackInMemberClusterObjAvailability(t *testing.T) {
10471047
id: &fleetv1beta1.WorkResourceIdentifier{
10481048
Ordinal: 0,
10491049
},
1050-
gvr: &utils.DeploymentGVR,
1051-
inMemberClusterObj: toUnstructured(t, availableDeploy),
1052-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1050+
gvr: &utils.DeploymentGVR,
1051+
inMemberClusterObj: toUnstructured(t, availableDeploy),
1052+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
10531053
},
10541054
// A failed to get applied service.
10551055
{
10561056
id: &fleetv1beta1.WorkResourceIdentifier{
10571057
Ordinal: 1,
10581058
},
1059-
gvr: &utils.ServiceGVR,
1060-
inMemberClusterObj: nil,
1061-
applyResTyp: ManifestProcessingApplyResultTypeFailedToApply,
1059+
gvr: &utils.ServiceGVR,
1060+
inMemberClusterObj: nil,
1061+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeFailedToApply,
10621062
},
10631063
// An unavailable daemon set.
10641064
{
10651065
id: &fleetv1beta1.WorkResourceIdentifier{
10661066
Ordinal: 2,
10671067
},
1068-
gvr: &utils.DaemonSetGVR,
1069-
inMemberClusterObj: toUnstructured(t, unavailableDaemonSet),
1070-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1068+
gvr: &utils.DaemonSetGVR,
1069+
inMemberClusterObj: toUnstructured(t, unavailableDaemonSet),
1070+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
10711071
},
10721072
// An untrackable job.
10731073
{
10741074
id: &fleetv1beta1.WorkResourceIdentifier{
10751075
Ordinal: 3,
10761076
},
1077-
gvr: &utils.JobGVR,
1078-
inMemberClusterObj: toUnstructured(t, untrackableJob),
1079-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1077+
gvr: &utils.JobGVR,
1078+
inMemberClusterObj: toUnstructured(t, untrackableJob),
1079+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
10801080
},
10811081
},
10821082
wantBundles: []*manifestProcessingBundle{
10831083
{
10841084
id: &fleetv1beta1.WorkResourceIdentifier{
10851085
Ordinal: 0,
10861086
},
1087-
gvr: &utils.DeploymentGVR,
1088-
inMemberClusterObj: toUnstructured(t, availableDeploy),
1089-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1090-
availabilityResTyp: ManifestProcessingAvailabilityResultTypeAvailable,
1087+
gvr: &utils.DeploymentGVR,
1088+
inMemberClusterObj: toUnstructured(t, availableDeploy),
1089+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
1090+
availabilityResTyp: ManifestProcessingAvailabilityResultTypeAvailable,
10911091
},
10921092
{
10931093
id: &fleetv1beta1.WorkResourceIdentifier{
10941094
Ordinal: 1,
10951095
},
1096-
gvr: &utils.ServiceGVR,
1097-
inMemberClusterObj: nil,
1098-
applyResTyp: ManifestProcessingApplyResultTypeFailedToApply,
1099-
availabilityResTyp: ManifestProcessingAvailabilityResultTypeSkipped,
1096+
gvr: &utils.ServiceGVR,
1097+
inMemberClusterObj: nil,
1098+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeFailedToApply,
1099+
availabilityResTyp: ManifestProcessingAvailabilityResultTypeSkipped,
11001100
},
11011101
{
11021102
id: &fleetv1beta1.WorkResourceIdentifier{
11031103
Ordinal: 2,
11041104
},
1105-
gvr: &utils.DaemonSetGVR,
1106-
inMemberClusterObj: toUnstructured(t, unavailableDaemonSet),
1107-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1108-
availabilityResTyp: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1105+
gvr: &utils.DaemonSetGVR,
1106+
inMemberClusterObj: toUnstructured(t, unavailableDaemonSet),
1107+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
1108+
availabilityResTyp: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
11091109
},
11101110
{
11111111
id: &fleetv1beta1.WorkResourceIdentifier{
11121112
Ordinal: 3,
11131113
},
1114-
gvr: &utils.JobGVR,
1115-
inMemberClusterObj: toUnstructured(t, untrackableJob),
1116-
applyResTyp: ManifestProcessingApplyResultTypeApplied,
1117-
availabilityResTyp: ManifestProcessingAvailabilityResultTypeNotTrackable,
1114+
gvr: &utils.JobGVR,
1115+
inMemberClusterObj: toUnstructured(t, untrackableJob),
1116+
applyOrReportDiffResTyp: ApplyOrReportDiffResTypeApplied,
1117+
availabilityResTyp: ManifestProcessingAvailabilityResultTypeNotTrackable,
11181118
},
11191119
},
11201120
},

pkg/controllers/workapplier/backoff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
)
6161

6262
const (
63-
processingResultStrTpl = "%s,%s,%s"
63+
processingResultStrTpl = "%s,%s"
6464
)
6565

6666
// RequeueMultiStageWithExponentialBackoffRateLimiter is a rate limiter that allows requeues of various
@@ -287,7 +287,7 @@ func computeProcessingResultHash(work *fleetv1beta1.Work, bundles []*manifestPro
287287
// The order of manifests is stable in a bundle.
288288
processingResults := make([]string, 0, len(bundles))
289289
for _, bundle := range bundles {
290-
processingResults = append(processingResults, fmt.Sprintf(processingResultStrTpl, bundle.applyResTyp, bundle.availabilityResTyp, bundle.reportDiffResTyp))
290+
processingResults = append(processingResults, fmt.Sprintf(processingResultStrTpl, bundle.applyOrReportDiffResTyp, bundle.availabilityResTyp))
291291
}
292292

293293
processingResHash, err := resource.HashOf(processingResults)

0 commit comments

Comments
 (0)