-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Extend CacheRuntime phase 2.4: add dataset related labels to nodes and support app pod affinity #5836
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
Open
xliuqq
wants to merge
2
commits into
fluid-cloudnative:master
Choose a base branch
from
xliuqq:cache_affinity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Extend CacheRuntime phase 2.4: add dataset related labels to nodes and support app pod affinity #5836
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,9 @@ import ( | |||||||||||||||||
| datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" | ||||||||||||||||||
| "github.com/fluid-cloudnative/fluid/pkg/common" | ||||||||||||||||||
| "github.com/fluid-cloudnative/fluid/pkg/utils" | ||||||||||||||||||
| "github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient" | ||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||
| corev1 "k8s.io/api/core/v1" | ||||||||||||||||||
| "k8s.io/apimachinery/pkg/api/resource" | ||||||||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||||||
| "k8s.io/apimachinery/pkg/types" | ||||||||||||||||||
|
|
@@ -52,8 +54,6 @@ type Conventions interface { | |||||||||||||||||
|
|
||||||||||||||||||
| GetDatasetNumLabelName() string | ||||||||||||||||||
|
|
||||||||||||||||||
| GetWorkerStatefulsetName() string | ||||||||||||||||||
|
|
||||||||||||||||||
| GetExclusiveLabelValue() string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -63,6 +63,9 @@ type Conventions interface { | |||||||||||||||||
| type RuntimeInfoInterface interface { | ||||||||||||||||||
| Conventions | ||||||||||||||||||
|
|
||||||||||||||||||
| // GetWorkerPods returns the worker object and selector for runtime workers. | ||||||||||||||||||
| GetWorkerPods(client client.Client) ([]corev1.Pod, error) | ||||||||||||||||||
|
|
||||||||||||||||||
| GetTieredStoreInfo() TieredStoreInfo | ||||||||||||||||||
|
|
||||||||||||||||||
| GetName() string | ||||||||||||||||||
|
|
@@ -375,6 +378,21 @@ func (info *RuntimeInfo) SetupFuseCleanPolicy(policy datav1alpha1.FuseCleanPolic | |||||||||||||||||
| info.fuse.CleanPolicy = policy | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func (info *RuntimeInfo) GetWorkerPods(client client.Client) ([]corev1.Pod, error) { | ||||||||||||||||||
| workers, err := kubeclient.GetStatefulSet(client, info.GetWorkerStatefulsetName(), info.GetNamespace()) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+382
to
+385
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. If the worker StatefulSet is not found,
Suggested change
|
||||||||||||||||||
| workerSelector, err := metav1.LabelSelectorAsSelector(workers.Spec.Selector) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| workerPods, err := kubeclient.GetPodsForStatefulSet(client, workers, workerSelector) | ||||||||||||||||||
|
|
||||||||||||||||||
| return workerPods, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func (info *RuntimeInfo) GetFuseCleanPolicy() datav1alpha1.FuseCleanPolicy { | ||||||||||||||||||
| return info.fuse.CleanPolicy | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -598,66 +616,97 @@ func GetRuntimeInfo(reader client.Reader, name, namespace string) (runtimeInfo R | |||||||||||||||||
| return runtimeInfo, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // GetRuntimeStatus gets the runtime status according to the runtime type, name, and namespace. | ||||||||||||||||||
| // This function is primarily responsible for retrieving the current status of a specific runtime | ||||||||||||||||||
| // based on its type from the Kubernetes cluster. | ||||||||||||||||||
| // | ||||||||||||||||||
| // Parameters: | ||||||||||||||||||
| // - client (client.Client): The Kubernetes client used to interact with the API server. | ||||||||||||||||||
| // - runtimeType (string): The type of the runtime (e.g., AlluxioRuntime, JindoRuntime, GooseFSRuntime). | ||||||||||||||||||
| // - name (string): The name of the runtime. | ||||||||||||||||||
| // - namespace (string): The namespace where the runtime is located. | ||||||||||||||||||
| // | ||||||||||||||||||
| // Returns: | ||||||||||||||||||
| // - status (*datav1alpha1.RuntimeStatus): The status of the requested runtime. | ||||||||||||||||||
| // - err (error): Returns an error if the runtime status cannot be retrieved or the runtime type is unsupported, otherwise returns nil. | ||||||||||||||||||
| func GetRuntimeStatus(client client.Client, runtimeType, name, namespace string) (status *datav1alpha1.RuntimeStatus, err error) { | ||||||||||||||||||
| // RuntimeStatusAccessor provides a unified interface to access common status fields across different runtime types | ||||||||||||||||||
| type RuntimeStatusAccessor interface { | ||||||||||||||||||
| // GetCacheAffinity returns the cache affinity from the runtime status | ||||||||||||||||||
| GetCacheAffinity() (*corev1.NodeAffinity, error) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // GetRuntimeStatusAccessor returns a unified status accessor for the given runtime | ||||||||||||||||||
| func GetRuntimeStatusAccessor(client client.Client, runtimeType, name, namespace string) (RuntimeStatusAccessor, error) { | ||||||||||||||||||
| switch runtimeType { | ||||||||||||||||||
| case common.AlluxioRuntime, common.JindoRuntime, common.GooseFSRuntime, | ||||||||||||||||||
| common.JuiceFSRuntime, common.EFCRuntime, common.ThinRuntime, common.VineyardRuntime: | ||||||||||||||||||
| status, err := GetDDCRuntimeStatus(client, runtimeType, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &DDCRuntimeStatusAccessor{status: status}, nil | ||||||||||||||||||
| case common.CacheRuntime: | ||||||||||||||||||
| runtime, err := utils.GetCacheRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &CacheRuntimeStatusAccessor{status: &runtime.Status}, nil | ||||||||||||||||||
| default: | ||||||||||||||||||
| return nil, fmt.Errorf("fail to get runtime status accessor for runtime type: %s", runtimeType) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // GetDDCRuntimeStatus retrieves the runtime object based on runtime type for DDC-based runtimes | ||||||||||||||||||
| func GetDDCRuntimeStatus(client client.Client, runtimeType, name, namespace string) (*datav1alpha1.RuntimeStatus, error) { | ||||||||||||||||||
| switch runtimeType { | ||||||||||||||||||
| case common.AlluxioRuntime: | ||||||||||||||||||
| runtime, err := utils.GetAlluxioRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.JindoRuntime: | ||||||||||||||||||
| runtime, err := utils.GetJindoRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.GooseFSRuntime: | ||||||||||||||||||
| runtime, err := utils.GetGooseFSRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.JuiceFSRuntime: | ||||||||||||||||||
| runtime, err := utils.GetJuiceFSRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.EFCRuntime: | ||||||||||||||||||
| runtime, err := utils.GetEFCRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.ThinRuntime: | ||||||||||||||||||
| runtime, err := utils.GetThinRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| case common.VineyardRuntime: | ||||||||||||||||||
| runtime, err := utils.GetVineyardRuntime(client, name, namespace) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return status, err | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| } | ||||||||||||||||||
| return &runtime.Status, nil | ||||||||||||||||||
| // TODO: how to handle with cache runtime? (currently used in app pod affinity scene) | ||||||||||||||||||
| default: | ||||||||||||||||||
| err = fmt.Errorf("fail to get runtimeInfo for runtime type: %s", runtimeType) | ||||||||||||||||||
| return nil, err | ||||||||||||||||||
| return nil, fmt.Errorf("unsupported DDC runtime type: %s", runtimeType) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // DDCRuntimeStatusAccessor implements RuntimeStatusAccessor for DDC-based runtimes (Alluxio, Jindo, GooseFS, etc.) | ||||||||||||||||||
| type DDCRuntimeStatusAccessor struct { | ||||||||||||||||||
| status *datav1alpha1.RuntimeStatus | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func (d *DDCRuntimeStatusAccessor) GetCacheAffinity() (*corev1.NodeAffinity, error) { | ||||||||||||||||||
| return d.status.CacheAffinity, nil | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // CacheRuntimeStatusAccessor implements RuntimeStatusAccessor for CacheRuntime | ||||||||||||||||||
| type CacheRuntimeStatusAccessor struct { | ||||||||||||||||||
| status *datav1alpha1.CacheRuntimeStatus | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func (c *CacheRuntimeStatusAccessor) GetCacheAffinity() (*corev1.NodeAffinity, error) { | ||||||||||||||||||
| return c.status.CacheAffinity, nil | ||||||||||||||||||
| } | ||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 comment for
GetWorkerPodsis inaccurate as it mentions returning a "worker object and selector", but the method signature returns a slice of pods.