Skip to content

fix: propagate context through configmap follow-up#5808

Open
CAICAIIs wants to merge 2 commits intofluid-cloudnative:masterfrom
CAICAIIs:5705-configmap-context-followup
Open

fix: propagate context through configmap follow-up#5808
CAICAIIs wants to merge 2 commits intofluid-cloudnative:masterfrom
CAICAIIs:5705-configmap-context-followup

Conversation

@CAICAIIs
Copy link
Copy Markdown
Contributor

Ⅰ. Describe what this PR does

This PR is a small follow-up for issue #5705 to finish wiring reconcile context into the remaining short ConfigMap/DaemonSet helper paths after #5747.

It keeps the change narrowly scoped to:

  • cache runtime ConfigMap create/sync paths
  • thin referencedataset DaemonSet/ConfigMap copy paths
  • related focused unit tests

Main changes:

  • add CreateConfigMapWithOwnerWithContext(...) in pkg/utils/kubeclient/configmap.go
  • keep CreateConfigMapWithOwner(...) as a compatibility wrapper
  • pass reconcile ctx from cache Setup(ctx) / Sync(ctx) down to:
    • createRuntimeConfigMaps
    • createConfigMapInRuntimeClass
    • createRuntimeValueConfigMap
    • syncRuntimeValueConfigMap
  • switch those cache paths to use:
    • GetConfigmapByNameWithContext
    • CreateConfigMapWithOwnerWithContext
    • UpdateConfigMapWithContext
  • pass reconcile ctx from thin referencedataset Setup(ctx) down to:
    • copyFuseDaemonSetForRefDataset
    • createConfigMapForRefDataset
  • switch thin referencedataset paths to use:
    • GetDaemonsetWithContext
    • CopyConfigMapWithContext
    • client.Create(ctx, ...)

This PR does not expand into repo-wide context cleanup or unrelated refactors.

Ⅱ. Does this pull request fix one issue?

fixes #5705

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Added/updated unit tests:

  • pkg/utils/kubeclient/configmap_test.go

    • verify CreateConfigMapWithOwnerWithContext really passes canceled context to the underlying client via contextAwareClient
  • pkg/ddc/cache/engine/cm_test.go

    • canceled context returns context.Canceled on cache ConfigMap paths
    • runtime class ConfigMap create path creates missing ConfigMap
    • runtime value ConfigMap create path creates missing ConfigMap
    • sync path skips update when ConfigMap data is unchanged
  • pkg/ddc/thin/referencedataset/cm_test.go

    • canceled context is propagated through referencedataset DaemonSet/ConfigMap paths
    • existing destination ConfigMap keeps skip semantics
    • missing source ConfigMap still returns the existing error
    • existing DaemonSet / AlreadyExists semantics remain unchanged

Ⅳ. Describe how to verify it

Run the focused verification set:

go test ./pkg/utils/kubeclient
go test ./pkg/ddc/thin/referencedataset
go test ./pkg/ddc/cache/engine

Signed-off-by: CAICAIIs <3360776475@qq.com>
@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot Bot commented Apr 24, 2026

[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 zwwhdls for approval by writing /assign @zwwhdls 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
Copy link
Copy Markdown

fluid-e2e-bot Bot commented Apr 24, 2026

Hi @CAICAIIs. 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.

Copy link
Copy Markdown
Contributor

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

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 several internal methods and utility functions to support context propagation, ensuring better lifecycle management and cancellation handling during ConfigMap and DaemonSet operations. Key changes include updating the CacheEngine and ReferenceDatasetEngine to pass contexts through their setup and synchronization flows, and introducing context-aware helper functions in the kubeclient package. Comprehensive unit tests were added to verify context cancellation behavior and error handling. I have no feedback to provide as the implementation is consistent and well-tested.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 75.75758% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.49%. Comparing base (82e490e) to head (8a0c454).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/ddc/cache/engine/cm.go 75.00% 3 Missing ⚠️
pkg/ddc/cache/engine/sync.go 50.00% 3 Missing ⚠️
pkg/ddc/cache/engine/setup.go 0.00% 1 Missing ⚠️
pkg/utils/kubeclient/configmap.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5808      +/-   ##
==========================================
+ Coverage   58.17%   58.49%   +0.32%     
==========================================
  Files         478      478              
  Lines       32485    32479       -6     
==========================================
+ Hits        18899    19000     +101     
+ Misses      12042    11916     -126     
- Partials     1544     1563      +19     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Follow-up to #5705/#5747 to finish propagating reconcile context.Context through remaining ConfigMap/DaemonSet helper paths so cancellation/timeouts flow down to controller-runtime client calls.

Changes:

  • Add CreateConfigMapWithOwnerWithContext(...) to kubeclient ConfigMap helpers and keep CreateConfigMapWithOwner(...) as a compatibility wrapper.
  • Wire reconcile context through cache engine ConfigMap create/sync paths and thin referencedataset DaemonSet/ConfigMap copy paths.
  • Add/extend focused unit tests to validate context cancellation propagation and existing “skip/AlreadyExists” semantics.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/utils/kubeclient/configmap.go Introduces ctx-aware CreateConfigMapWithOwnerWithContext and wraps legacy helper.
pkg/utils/kubeclient/configmap_test.go Adds a cancellation-propagation test for the new ctx-aware owner create helper.
pkg/ddc/cache/engine/cm.go Threads context into cache runtime ConfigMap creation paths (extra-resources + runtime value CM).
pkg/ddc/cache/engine/setup.go Passes reconcile context into cache ConfigMap setup chain.
pkg/ddc/cache/engine/sync.go Threads context into cache runtime value ConfigMap sync path (Get/Create/Update).
pkg/ddc/cache/engine/cm_test.go Adds unit tests for cache ConfigMap create/sync behavior and cancellation propagation.
pkg/ddc/thin/referencedataset/engine.go Passes reconcile context down into referencedataset DaemonSet/ConfigMap helpers.
pkg/ddc/thin/referencedataset/cm.go Converts referencedataset DaemonSet/ConfigMap operations to ctx-aware kubeclient/client calls.
pkg/ddc/thin/referencedataset/cm_test.go Adds tests ensuring cancellation propagation and preserves existing skip/error semantics.
Comments suppressed due to low confidence (1)

pkg/ddc/cache/engine/sync.go:64

  • syncRuntimeValueConfigMap uses ctx-aware ConfigMap helpers, but generateRuntimeConfigData(runtime) still reads the Dataset via utils.GetDataset(...) which uses context.TODO() internally. That means a canceled reconcile context may still allow the dataset Get call to proceed. To fully propagate cancellation/timeouts, pass ctx into generateRuntimeConfigData and use utils.GetDatasetWithContext(ctx, ...) (or pass ctx.Context explicitly).
func (e *CacheEngine) syncRuntimeValueConfigMap(ctx cruntime.ReconcileRequestContext, runtime *datav1alpha1.CacheRuntime) error {
	configMap, err := kubeclient.GetConfigmapByNameWithContext(ctx, e.Client, e.getRuntimeConfigConfigMapName(), e.namespace)
	if err != nil {
		return err
	}
	data, err := e.generateRuntimeConfigData(runtime)
	if err != nil {
		return err
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/ddc/cache/engine/cm.go
Comment thread pkg/utils/kubeclient/configmap_test.go Outdated
Signed-off-by: CAICAIIs <3360776475@qq.com>
@sonarqubecloud
Copy link
Copy Markdown

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: propagate context.Context through controller and utility call chains

2 participants