-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(jindo): guard SyncRuntime against nil client and stabilize unit test detection #5668
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Copyright 2022 The Fluid Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package jindo | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/fluid-cloudnative/fluid/pkg/common" | ||
| "github.com/fluid-cloudnative/fluid/pkg/utils/docker" | ||
| ) | ||
|
|
||
| // resolveSmartDataImage returns the full image string for the SmartData container | ||
| func resolveSmartDataImage() string { | ||
| var ( | ||
| defaultImage = "registry.cn-shanghai.aliyuncs.com/jindofs/smartdata" | ||
| defaultTag = "3.8.0" | ||
| ) | ||
|
|
||
| image := docker.GetImageRepoFromEnv(common.JindoSmartDataImageEnv) | ||
| tag := docker.GetImageTagFromEnv(common.JindoSmartDataImageEnv) | ||
|
|
||
| if len(image) == 0 { | ||
| image = defaultImage | ||
| } | ||
| if len(tag) == 0 { | ||
| tag = defaultTag | ||
| } | ||
|
|
||
| return fmt.Sprintf("%s:%s", image, tag) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,9 +16,70 @@ limitations under the License. | |||||||||||||
|
|
||||||||||||||
| package jindo | ||||||||||||||
|
|
||||||||||||||
| import cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime" | ||||||||||||||
| import ( | ||||||||||||||
| "k8s.io/apimachinery/pkg/types" | ||||||||||||||
|
|
||||||||||||||
| "github.com/fluid-cloudnative/fluid/pkg/ctrl" | ||||||||||||||
| cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime" | ||||||||||||||
| "github.com/fluid-cloudnative/fluid/pkg/utils" | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| // SyncRuntime syncs the runtime spec | ||||||||||||||
| func (e *JindoEngine) SyncRuntime(ctx cruntime.ReconcileRequestContext) (changed bool, err error) { | ||||||||||||||
| return | ||||||||||||||
| if e.Client == nil { | ||||||||||||||
| e.Log.V(1).Info("Client is nil, skipping SyncRuntime") | ||||||||||||||
|
Comment on lines
+29
to
+30
|
||||||||||||||
| if e.Client == nil { | |
| e.Log.V(1).Info("Client is nil, skipping SyncRuntime") | |
| // In normal production flows, e.Client is expected to be non-nil. | |
| // This guard primarily exists for unit tests where the Client is not initialized. | |
| if e.Client == nil { | |
| e.Log.Info("Client is nil, skipping SyncRuntime; this should only occur in unit tests") |
Copilot
AI
Feb 12, 2026
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.
The new SyncRuntime implementation returns false for the changed parameter even when an image update is applied. According to the function signature, changed should indicate whether the runtime spec was changed. When an image update is triggered (line 72), the function should return true instead of false to properly indicate that a change was made. This would allow the reconciliation loop to properly track that a change occurred.
| // Return false, nil to continue reconciliation without short-circuiting | |
| return false, nil | |
| // Indicate that a change was made so the reconciliation loop can track it | |
| return true, nil |
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.
The function returns false for the changed flag even after successfully updating the worker StatefulSet. While this avoids an immediate requeue, it's inconsistent with the semantics of the changed return value and other runtime engine implementations, which typically return true to signal that a change was made. Returning true would make the control flow clearer and more consistent across the codebase.
| return false, nil | |
| return true, nil |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -544,20 +544,19 @@ func (e *JindoEngine) transformFuseArg(runtime *datav1alpha1.JindoRuntime, datas | |||||||||||||||||
|
|
||||||||||||||||||
| func (e *JindoEngine) getSmartDataConfigs() (image, tag, dnsServer string) { | ||||||||||||||||||
| var ( | ||||||||||||||||||
| defaultImage = "registry.cn-shanghai.aliyuncs.com/jindofs/smartdata" | ||||||||||||||||||
| defaultTag = "3.8.0" | ||||||||||||||||||
| defaultDnsServer = "1.1.1.1" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| image = docker.GetImageRepoFromEnv(common.JindoSmartDataImageEnv) | ||||||||||||||||||
| tag = docker.GetImageTagFromEnv(common.JindoSmartDataImageEnv) | ||||||||||||||||||
| dnsServer = os.Getenv(common.JindoDnsServer) | ||||||||||||||||||
| if len(image) == 0 { | ||||||||||||||||||
| image = defaultImage | ||||||||||||||||||
| } | ||||||||||||||||||
| if len(tag) == 0 { | ||||||||||||||||||
| tag = defaultTag | ||||||||||||||||||
| fullImage := resolveSmartDataImage() | ||||||||||||||||||
| lastColon := strings.LastIndex(fullImage, ":") | ||||||||||||||||||
| if lastColon != -1 { | ||||||||||||||||||
| image = fullImage[:lastColon] | ||||||||||||||||||
| tag = fullImage[lastColon+1:] | ||||||||||||||||||
| } else { | ||||||||||||||||||
| image = fullImage | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+551
to
557
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation for splitting the image and tag might not correctly handle image names that include a port number (e.g.,
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| dnsServer = os.Getenv(common.JindoDnsServer) | ||||||||||||||||||
| if len(dnsServer) == 0 { | ||||||||||||||||||
| dnsServer = defaultDnsServer | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,10 +16,20 @@ limitations under the License. | |||||
|
|
||||||
| package testutil | ||||||
|
|
||||||
| import "os" | ||||||
| import ( | ||||||
| "os" | ||||||
| "strings" | ||||||
| ) | ||||||
|
|
||||||
| const FluidUnitTestEnv = "FLUID_UNIT_TEST" | ||||||
|
|
||||||
| func init() { | ||||||
| // Automatically detect if running inside a test binary | ||||||
| if strings.HasSuffix(os.Args[0], ".test") || strings.HasSuffix(os.Args[0], ".test.exe") { | ||||||
|
||||||
| if strings.HasSuffix(os.Args[0], ".test") || strings.HasSuffix(os.Args[0], ".test.exe") { | |
| if len(os.Args) > 0 && (strings.HasSuffix(os.Args[0], ".test") || strings.HasSuffix(os.Args[0], ".test.exe")) { |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
The default image and tag are hardcoded here, which duplicates the
DefaultJindoRuntimeImageconstant defined inpkg/ddc/jindo/const.go. To avoid duplication and improve maintainability, it's better to derive the default image and tag from the constant.