Skip to content

Conversation

@Anujkumar9081
Copy link

@Anujkumar9081 Anujkumar9081 commented Jan 27, 2026

This PR enhances the Fluid injector to automatically enable Native Sidecar mode as the default injection strategy when running on Kubernetes clusters v1.29 or higher.

Key Changes
• Automatic Detection
Added logic in NewInjector
(pkg/application/inject/fuse/injector.go) to detect the Kubernetes server version at runtime.
• Version Compatibility
• Kubernetes ≥ 1.29
Defaults to SidecarInjectionMode_NativeSidecar, leveraging built-in Kubernetes sidecar support for improved lifecycle management and performance.
• Kubernetes < 1.29
Preserves the existing legacy behavior (standard init container or regular sidecar with lifecycle hooks) to ensure backward compatibility.
• Utility Update
Introduced a new helper function GetServerVersion() under pkg/utils/discovery to safely retrieve Kubernetes server version information.

II. Does this pull request fix an issue?

Fixes #5320

III. Test Coverage
• Unit Tests
Verified that existing tests in
pkg/application/inject/fuse/injector_test.go pass with the new version-based injection logic.
• New Utility
Added pkg/utils/discovery/version.go, which is exercised through standard package imports and usage in the injector.

No additional test cases were required.

IV. How to Verify
1. Environment Setup
Prepare a Kubernetes cluster running v1.29 or later.
2. Deploy Fluid
Deploy Fluid with this change applied.
3. Run Workload
Submit a Pod (e.g., a serverless application) that mounts a Fluid Dataset without explicitly specifying the sidecar mode.
4. Verification
• Inspect the generated Pod YAML.
• Confirm that the Fuse sidecar is injected as an initContainer with restartPolicy: Always, which indicates Native Sidecar mode.
5. Backward Compatibility Check
• Repeat the above steps on a Kubernetes v1.28 or older cluster.
• Confirm that the injector uses the legacy sidecar injection mechanism.

V. Special Notes for Reviewers

This implementation relies on discovery.GetServerVersion(), which initializes on the first call. If the Kubernetes discovery client fails (e.g., due to restricted environments or specific test scenarios), the injector gracefully falls back to the legacy default behavior, ensuring no disruption to existing workflows.

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Jan 27, 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 yangyuliufeng for approval by writing /assign @yangyuliufeng 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Anujkumar9081, 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 introduces an intelligent sidecar injection mechanism to Fluid, dynamically adapting its strategy based on the Kubernetes cluster version. It prioritizes the use of native sidecar capabilities for newer Kubernetes environments (1.29 and above) to enhance efficiency and integration, while meticulously preserving compatibility with older versions. This ensures that Fluid deployments benefit from the latest Kubernetes features without compromising stability on diverse cluster setups.

Highlights

  • Automatic Native Sidecar Injection: The Fluid injector now automatically defaults to Native Sidecar mode for Kubernetes clusters running version 1.29 or higher, leveraging built-in sidecar support for improved lifecycle management and performance.
  • Backward Compatibility: For Kubernetes clusters older than version 1.29, the injector retains the legacy behavior (standard Init Container or regular sidecar with lifecycle hooks) to ensure existing workflows are not disrupted.
  • Kubernetes Version Discovery Utility: A new utility function, GetServerVersion(), has been added in pkg/utils/discovery to safely retrieve the Kubernetes server's major and minor version information, with built-in caching and error handling.
  • Robust Error Handling: If the Kubernetes discovery client fails to connect or retrieve server version information, the injector gracefully falls back to the legacy default sidecar injection mode, preventing disruptions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Jan 27, 2026

Hi @Anujkumar9081. 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
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 enhances the Fluid injector to automatically use Native Sidecar mode on Kubernetes v1.29 and higher. The implementation correctly detects the server version and falls back to the legacy mode on older versions or if version detection fails. The changes are well-structured and the logic is sound. I have a couple of suggestions to improve the code's readability and maintainability.

Comment on lines +49 to +60
if mode == common.SidecarInjectionMode_Default {
major, minor, err := discovery.GetServerVersion()
if err != nil {
ctrl.Log.WithName("fuse-injector").V(1).Info("Failed to discover server version, using default sidecar injection mode", "error", err)
} else {
// Native sidecar is supported and enabled by default in K8s 1.29+
if major > 1 || (major == 1 && minor >= 29) {
mode = common.SidecarInjectionMode_NativeSidecar
ctrl.Log.WithName("fuse-injector").Info("Detected K8s version >= 1.29, using native sidecar mode")
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and maintainability, consider defining the Kubernetes version numbers (1 and 29) as named constants. This makes the code's intent clearer and easier to update if the required version changes in the future. Also, including the detected version in the log message would be helpful for debugging.

	if mode == common.SidecarInjectionMode_Default {
		const (
			nativeSidecarMinK8sMajorVersion = 1
			nativeSidecarMinK8sMinorVersion = 29
		)

		major, minor, err := discovery.GetServerVersion()
		if err != nil {
			ctrl.Log.WithName("fuse-injector").V(1).Info("Failed to discover server version, using default sidecar injection mode", "error", err)
		} else {
			// Native sidecar is supported and enabled by default in K8s 1.29+
			if major > nativeSidecarMinK8sMajorVersion || (major == nativeSidecarMinK8sMajorVersion && minor >= nativeSidecarMinK8sMinorVersion) {
				mode = common.SidecarInjectionMode_NativeSidecar
				ctrl.Log.WithName("fuse-injector").Info("Detected K8s version >= 1.29, using native sidecar mode", "major", major, "minor", minor)
			}
		}
	}

Comment on lines +20 to +54
func GetServerVersion() (int, int, error) {
versionOnce.Do(func() {
restConfig, err := ctrl.GetConfig()
if err != nil {
discoveryErr = err
return
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(restConfig)
if err != nil {
discoveryErr = err
return
}
versionInfo, err := discoveryClient.ServerVersion()
if err != nil {
discoveryErr = err
return
}

serverVersionMajor, err = strconv.Atoi(versionInfo.Major)
if err != nil {
discoveryErr = err
return
}

// Minor version might have a suffix like "28+", trim it
minor := strings.TrimSuffix(versionInfo.Minor, "+")
serverVersionMinor, err = strconv.Atoi(minor)
if err != nil {
discoveryErr = err
return
}
})

return serverVersionMajor, serverVersionMinor, discoveryErr
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and maintainability, you could refactor the logic inside versionOnce.Do into a separate private function. This would reduce the repetitive if err != nil blocks and make the GetServerVersion function's purpose clearer.

func GetServerVersion() (int, int, error) {
	versionOnce.Do(func() {
		serverVersionMajor, serverVersionMinor, discoveryErr = discoverServerVersion()
	})

	return serverVersionMajor, serverVersionMinor, discoveryErr
}

func discoverServerVersion() (major int, minor int, err error) {
	restConfig, err := ctrl.GetConfig()
	if err != nil {
		return 0, 0, err
	}

	discoveryClient, err := discovery.NewDiscoveryClientForConfig(restConfig)
	if err != nil {
		return 0, 0, err
	}

	versionInfo, err := discoveryClient.ServerVersion()
	if err != nil {
		return 0, 0, err
	}

	major, err = strconv.Atoi(versionInfo.Major)
	if err != nil {
		return 0, 0, err
	}

	// Minor version might have a suffix like "28+", trim it
	minorStr := strings.TrimSuffix(versionInfo.Minor, "+")
	minor, err = strconv.Atoi(minorStr)
	if err != nil {
		return 0, 0, err
	}

	return major, minor, nil
}

@Anujkumar9081
Copy link
Author

closed

@sonarqubecloud
Copy link

@Anujkumar9081 Anujkumar9081 deleted the feature/native-sidecar-default branch February 4, 2026 07:09
@Anujkumar9081 Anujkumar9081 restored the feature/native-sidecar-default branch February 4, 2026 07:10
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.

[FEATURES] Native Sidecar Default Mode + Backward Compatibility

1 participant