Skip to content

feature(fluid-webhook): support to update check-mount.sh configmap on demand#5697

Open
Syspretor wants to merge 1 commit intofluid-cloudnative:masterfrom
Syspretor:feature/support-update-check-mount-script-on-demand
Open

feature(fluid-webhook): support to update check-mount.sh configmap on demand#5697
Syspretor wants to merge 1 commit intofluid-cloudnative:masterfrom
Syspretor:feature/support-update-check-mount-script-on-demand

Conversation

@Syspretor
Copy link
Copy Markdown
Collaborator

@Syspretor Syspretor commented Mar 18, 2026

(fluid-webhook): support to update check-mount.sh configmap on demand
[WIP]

Ⅰ. Describe what this PR does

The check-mount script ConfigMap was only created when it did not exist. If the ConfigMap already existed, updates to the check-mount script would never be applied — there was no mechanism to detect or reconcile script changes at runtime.

This PR introduces a SHA256-based change detection mechanism for the check-mount script ConfigMap:

  • SHA256 computation: Compute the SHA256 of the check-mount script content at package initialization (via init()) and store it in the fluid.io/check-mount-script-sha256 annotation on the ConfigMap.
  • Change detection: When the ConfigMap already exists, compare its stored SHA256 annotation against the current script's SHA256. If they differ (or the annotation is missing), the ConfigMap is refreshed with the latest script content and annotation.
  • Concurrent update safety: The update path is wrapped in retry.RetryOnConflict — each retry re-fetches the latest ConfigMap to get a fresh resourceVersion, avoiding 409 Conflict errors when multiple webhook requests are handled concurrently. A reflect.DeepEqual check guards the final Update call to avoid unnecessary writes.
  • Refactoring: Extracted RefreshConfigMapContents() on the script generator to encapsulate the update logic, so callers don't need to know which fields (Data, Labels, Annotations) are managed by the generator. Future changes to BuildConfigMap automatically apply to the update path as well.

Ⅱ. Does this pull request fix one issue?

fixes #XXXX

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Mar 18, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the fluid-webhook component by enabling dynamic updates of the check-mount.sh ConfigMap. By leveraging SHA256 hashes stored as Kubernetes labels, the system can now detect outdated script versions and apply necessary updates on demand, ensuring that applications consistently utilize the most current and correct mount-checking logic. This enhancement improves the robustness and maintainability of the FUSE injection process.

Highlights

  • On-demand ConfigMap Updates: Implemented a mechanism to update the check-mount.sh ConfigMap on demand, ensuring that applications always use the latest version of the script.
  • SHA256-based Content Verification: Introduced SHA256 hashing of script content to detect changes, allowing the system to determine if an existing ConfigMap needs updating.
  • New Kubernetes Label for Version Tracking: Added a new Kubernetes label, fluid.io/check-mount-script-sha256, to ConfigMaps to store the SHA256 hash of the script content for efficient version tracking.
  • Refactored ConfigMap Management Logic: Modified the ConfigMap creation and update logic to intelligently check for existing ConfigMaps and only apply updates if the script content, as indicated by the SHA256, has genuinely changed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Syspretor Syspretor changed the title feature(fluid-webhook\): support to update check-mount.sh configmap on demand feature(fluid-webhook): support to update check-mount.sh configmap on demand Mar 18, 2026
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 introduces a mechanism to update the check-mount.sh ConfigMap on-demand by comparing a SHA256 hash of the script content. This is a valuable improvement. The overall logic is sound, but there are a couple of areas for improvement. First, the SHA256 hash is truncated to fit into a Kubernetes label, which is not ideal; using an annotation would be more appropriate. Second, there's some code duplication in the hash calculation logic. Finally, a comment for the new label constant is inconsistent. I've provided specific comments with suggestions to address these points.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 62.60870% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.40%. Comparing base (9fe8f29) to head (7f06483).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
...application/inject/fuse/mutator/mutator_default.go 46.34% 15 Missing and 7 partials ⚠️
pkg/application/inject/fuse/mount_point_script.go 63.63% 10 Missing and 2 partials ⚠️
...ication/inject/fuse/poststart/script_gen_helper.go 73.33% 8 Missing ⚠️
...cation/inject/fuse/poststart/check_fuse_default.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5697      +/-   ##
==========================================
+ Coverage   61.22%   61.40%   +0.17%     
==========================================
  Files         444      444              
  Lines       30557    30657     +100     
==========================================
+ Hits        18710    18825     +115     
+ Misses      10307    10285      -22     
- Partials     1540     1547       +7     

☔ 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

This PR adds “update-on-demand” behavior for the check-mount script ConfigMaps created/used by the Fluid FUSE webhook injection path, by tracking script content via a SHA256 label and updating existing ConfigMaps when the script changes.

Changes:

  • Introduces a new label key to store a truncated SHA256 of the check-mount script content.
  • Computes and attaches the script SHA256 label when generating the sidecar and app check-mount ConfigMaps.
  • Updates existing ConfigMaps during injection when the stored SHA256 label is missing or differs from the current script.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/common/label.go Adds a new label constant for storing the script SHA256 on ConfigMaps.
pkg/application/inject/fuse/poststart/script_gen_helper.go Adds SHA256 computation helper and labels generated ConfigMaps with the script hash.
pkg/application/inject/fuse/poststart/check_fuse_default.go Computes and stores the default sidecar script SHA256.
pkg/application/inject/fuse/poststart/check_fuse_app.go Computes and stores the app script SHA256 and labels the app ConfigMap.
pkg/application/inject/fuse/mutator/mutator_default.go Changes logic to update the sidecar ConfigMap when script hash differs.
pkg/application/inject/fuse/mount_point_script.go Changes logic to update the app ConfigMap when script hash differs.

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

Comment on lines +157 to +173
// ConfigMap exists, check if the script SHA256 label matches
currentSHA256 := appScriptGen.GetScriptSHA256()
if existingCM.Labels != nil {
if labelSHA256, ok := existingCM.Labels[common.LabelCheckMountScriptSHA256]; ok && labelSHA256 == currentSHA256 {
s.log.V(1).Info("configmap script is up-to-date, skip update", "configMap", cmKey)
return appScriptGen, nil
}
}

// SHA256 mismatch or label missing: update the ConfigMap with latest script and SHA256
s.log.Info("configmap script SHA256 mismatch or label missing, updating", "configMap", cmKey, "expectedSHA256", currentSHA256)
existingCM.Data = cm.Data
if existingCM.Labels == nil {
existingCM.Labels = map[string]string{}
}
existingCM.Labels[common.LabelCheckMountScriptSHA256] = currentSHA256
if err = s.client.Update(context.TODO(), existingCM); err != nil {
Comment on lines +340 to +365
} else {
// ConfigMap exists, check if the script SHA256 label matches
currentSHA256 := gen.GetScriptSHA256()
needUpdate := true
if existingCM.Labels != nil {
if labelSHA256, ok := existingCM.Labels[common.LabelCheckMountScriptSHA256]; ok && labelSHA256 == currentSHA256 {
needUpdate = false
}
}

if needUpdate {
// SHA256 mismatch or label missing: update the ConfigMap with latest script and SHA256
newCM := gen.BuildConfigMap(dataset, cmKey)
existingCM.Data = newCM.Data
if existingCM.Labels == nil {
existingCM.Labels = map[string]string{}
}
existingCM.Labels[common.LabelCheckMountScriptSHA256] = currentSHA256
// Preserve the dataset-id label if already set
if _, ok := existingCM.Labels[common.LabelAnnotationDatasetId]; !ok {
existingCM.Labels[common.LabelAnnotationDatasetId] = newCM.Labels[common.LabelAnnotationDatasetId]
}
if err = helper.client.Update(context.TODO(), existingCM); err != nil {
return err
}
}
Comment on lines +37 to +46
// appScriptContentSHA256 stores the SHA256 hex of the app script content (first 63 chars for K8s label compatibility),
// computed once at package initialization.
var appScriptContentSHA256 string

func init() {
content := replacer.Replace(contentCheckMountReadyScript)
sum := sha256.Sum256([]byte(content))
// K8s label values must be <= 63 characters; SHA256 hex is 64 chars, so truncate to 63.
appScriptContentSHA256 = fmt.Sprintf("%x", sum)[:63]
}
Comment on lines +350 to +360
if needUpdate {
// SHA256 mismatch or label missing: update the ConfigMap with latest script and SHA256
newCM := gen.BuildConfigMap(dataset, cmKey)
existingCM.Data = newCM.Data
if existingCM.Labels == nil {
existingCM.Labels = map[string]string{}
}
existingCM.Labels[common.LabelCheckMountScriptSHA256] = currentSHA256
// Preserve the dataset-id label if already set
if _, ok := existingCM.Labels[common.LabelAnnotationDatasetId]; !ok {
existingCM.Labels[common.LabelAnnotationDatasetId] = newCM.Labels[common.LabelAnnotationDatasetId]
Comment on lines +360 to +364
existingCM.Labels[common.LabelAnnotationDatasetId] = newCM.Labels[common.LabelAnnotationDatasetId]
}
if err = helper.client.Update(context.TODO(), existingCM); err != nil {
return err
}
@Syspretor Syspretor force-pushed the feature/support-update-check-mount-script-on-demand branch from daa3a38 to dabc4af Compare March 24, 2026 06:45
@Syspretor Syspretor marked this pull request as ready for review March 24, 2026 06:51
@Syspretor Syspretor force-pushed the feature/support-update-check-mount-script-on-demand branch from dabc4af to e981521 Compare March 24, 2026 07:04
cheyang

This comment was marked as duplicate.

Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

Truncating SHA256 to 63 chars isn't really necessary for annotations - only labels have that limit. Keeping the full 64 chars removes any collision risk.

@@ -34,6 +36,14 @@ type scriptGeneratorHelper struct {
scriptContent string
scriptFileName string
Copy link
Copy Markdown
Collaborator

@cheyang cheyang Mar 24, 2026

Choose a reason for hiding this comment

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

Truncating SHA256 to 63 chars isn't really necessary for annotations - only labels have that limit. Keeping the full 64 chars removes any collision risk, however small.

Data: data,
}
}

Copy link
Copy Markdown
Collaborator

@cheyang cheyang Mar 24, 2026

Choose a reason for hiding this comment

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

If scriptContent is empty, computeScriptSHA256 will panic on the [:63] slice. Worth a guard or at least a comment.

@cheyang cheyang self-requested a review March 24, 2026 10:14
cheyang

This comment was marked as duplicate.

@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Mar 24, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheyang

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

The pull request process is described 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-webhook): support to update check-mount.sh configmap on demand

Signed-off-by: 玖宇 <guotongyu.gty@alibaba-inc.com>
@Syspretor Syspretor force-pushed the feature/support-update-check-mount-script-on-demand branch from e981521 to 7f06483 Compare March 25, 2026 02:38
@sonarqubecloud
Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants