-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: default to native sidecar on k8s >= 1.29 #5519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: default to native sidecar on k8s >= 1.29 #5519
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @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
🧠 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 AssistThe 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
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 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
|
|
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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
There was a problem hiding this 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.
| 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") | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
}
}
}| 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 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}|
closed |
|



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.