Skip to content

refactor: extract shared job-status helper in DataLoad and DataMigra…#6067

Open
adityaupasani2 wants to merge 1 commit into
fluid-cloudnative:masterfrom
adityaupasani2:refactor/dataload-datamigrate-shared-handler
Open

refactor: extract shared job-status helper in DataLoad and DataMigra…#6067
adityaupasani2 wants to merge 1 commit into
fluid-cloudnative:masterfrom
adityaupasani2:refactor/dataload-datamigrate-shared-handler

Conversation

@adityaupasani2

Copy link
Copy Markdown
Contributor

Ⅰ. Describe what this PR does

OnceStatusHandler and OnEventStatusHandler in both DataLoad and DataMigrate contained near-identical ~40-line blocks for looking up the triggered job, checking its finished condition, and returning phase/conditions/duration. This resulted in four copies of the same logic that had to be kept in sync.

Extracts a shared getJobOperationStatus() helper in each package so both handlers delegate to it. The helper takes a generateNodeAffinity bool parameter so the DataMigrate parallelism guard (Parallelism == 1 before setting NodeAffinity) can be expressed cleanly at the call site:

// DataLoad (always generates node affinity)
return getJobOperationStatus(ctx, r.Client, releaseName, jobName, ctx.Namespace, true, opStatus)

// DataMigrate (only when not parallel)
generateNodeAffinity := m.dataMigrate.Spec.Parallelism == 1
return getJobOperationStatus(ctx, m.Client, releaseName, jobName, object.GetNamespace(), generateNodeAffinity, opStatus)

Net result: 122 lines removed, future status-handling fixes are a single edit instead of four.

Ⅱ. Does this pull request fix one issue?

Closes #6065

Ⅲ. List the added test cases

No new tests needed — existing tests for all four handlers continue to pass unchanged.

Ⅳ. Describe how to verify it

go test ./pkg/controllers/v1alpha1/dataload/... ./pkg/controllers/v1alpha1/datamigrate/...

Ⅴ. Special notes for reviews

This was promised as a follow-up to PR #5945 (review comment by cheyang requesting the refactor).

…te handlers

OnceStatusHandler and OnEventStatusHandler in both DataLoad and DataMigrate
contained near-identical logic for looking up the triggered job, checking
its finished condition, and returning phase/conditions/duration. This
duplicated four copies of the same ~40-line block.

Extract a shared getJobOperationStatus() helper in each package so both
handlers delegate to it. The helper takes a generateNodeAffinity bool so
the DataMigrate parallelism guard (only set NodeAffinity when Parallelism==1)
can be expressed cleanly at the call site.

This was promised as a follow-up to PR fluid-cloudnative#5945 (review comment by cheyang).

Closes fluid-cloudnative#6065

Signed-off-by: Aditya Upasani <adityaupasani29@gmail.com>
@fluid-e2e-bot

fluid-e2e-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign trafalgarzzz for approval by writing /assign @trafalgarzzz in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fluid-e2e-bot

fluid-e2e-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

Hi @adityaupasani2. Thanks for your PR.

I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sonarqubecloud

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the status handlers for both DataLoad and DataMigrate controllers by extracting common logic into a shared helper function, getJobOperationStatus. This helper handles retrieving the job, checking its completion status, and updating the operation status, thereby reducing code duplication in OnceStatusHandler and OnEventStatusHandler. As there are no review comments, I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.77%. Comparing base (36f0467) to head (622189e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6067   +/-   ##
=======================================
  Coverage   64.77%   64.77%           
=======================================
  Files         484      484           
  Lines       33892    33892           
=======================================
  Hits        21954    21954           
  Misses      10215    10215           
  Partials     1723     1723           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

return getJobOperationStatus(ctx, r.Client, releaseName, jobName, ctx.Namespace, true, opStatus)
}
func (c *CronStatusHandler) GetOperationStatus(ctx cruntime.ReconcileRequestContext, opStatus *datav1alpha1.OperationStatus) (result *datav1alpha1.OperationStatus, err error) {
result = opStatus.DeepCopy()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up on a small but real semantic shift here. In the old OnceStatusHandler.GetOperationStatus, when kubeclient.GetJob returned a NotFound error and helm.DeleteReleaseIfExists succeeded, control fell through the inner if and ended up at ctx.Log.Error(err, "can't get dataload job", ...) with err == nil, then returned. The new getJobOperationStatus helper adds an explicit return after the successful delete, so that spurious nil-error log line is no longer emitted for the Once path. This matches what the old OnEventStatusHandler already did and what DataMigrate already did, so the new behavior is the more reasonable one — but it is a behavior change and is worth calling out in the commit message so future readers don't have to dig for it.

// It looks up the triggered job, checks its finished condition, and returns the updated
// OperationStatus with the correct phase, conditions and duration. If generateNodeAffinity
// is true and the job succeeded, it also populates NodeAffinity from the job's node labels.
func getJobOperationStatus(ctx cruntime.ReconcileRequestContext, c client.Client, releaseName, jobName, namespace string, generateNodeAffinity bool, opStatus *datav1alpha1.OperationStatus) (result *datav1alpha1.OperationStatus, err error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title says "extract shared job-status helper in DataLoad and DataMigrate", but what actually landed is two package-local helpers — one getJobOperationStatus in pkg/controllers/v1alpha1/dataload and another getJobOperationStatus in pkg/controllers/v1alpha1/datamigrate. They are byte-identical apart from the log labels ("DataLoad" vs "DataMigrate" and the chart-existed info log). Within a single controller this PR removes ~80 lines of duplication, which is a clear win, but the cross-controller duplication that #6065 originally pointed at is still there. Not blocking — moving the helper to pkg/dataoperation (where the StatusHandler interface already lives) would require parameterizing the log labels and likely passing the logger explicitly, which is more invasive. Worth a follow-up issue if we want full dedup later.

// It looks up the triggered job, checks its finished condition, and returns the updated
// OperationStatus with the correct phase, conditions and duration. If generateNodeAffinity
// is true and the job succeeded, it also populates NodeAffinity from the job's node labels.
func getJobOperationStatus(ctx cruntime.ReconcileRequestContext, c client.Client, releaseName, jobName, namespace string, generateNodeAffinity bool, opStatus *datav1alpha1.OperationStatus) (result *datav1alpha1.OperationStatus, err error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing OnceStatusHandler and OnEventStatusHandler test cases continue to pass and indirectly cover getJobOperationStatus. That's fine, and explicit coverage is not required for merge. If you want to firm things up, a small focused test on getJobOperationStatus itself — exercising the four branches (job missing + helm delete OK, job missing + helm delete fail, job running, job finished with generateNodeAffinity toggled) — would lock in the contract going forward and make any future regression obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Extract shared job-status helper between OnceStatusHandler and OnEventStatusHandler in DataLoad and DataMigrate

2 participants