Skip to content

Commit

Permalink
feat: support mountMode configuration to skip check mount ready
Browse files Browse the repository at this point in the history
Signed-off-by: jiuyu <[email protected]>
  • Loading branch information
jiuyu committed Oct 11, 2024
1 parent b2e6337 commit 3002618
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 8 deletions.
15 changes: 12 additions & 3 deletions pkg/common/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package common
import "regexp"

const (
// LabelAnnotationPrefix is the prefix of every labels and annotations added by the controller.
// LabelAnnotationPrefix is the prefix of every label and annotations added by the controller.
LabelAnnotationPrefix = "fluid.io/"

// LabelAnnotationStorageCapacityPrefix is the prefix for the storage annotaion.
Expand Down Expand Up @@ -56,9 +56,18 @@ const (
// i.e. fluid.io/dataset.referring-namespace
LabelAnnotationDatasetReferringNameSpace = LabelAnnotationDataset + ".referring-namespace"

// LabelNodePublishMothod is a pv label that indicates the method nodePuhlishVolume use
// LabelNodePublishMethod is a pv label that indicates the method nodePuhlishVolume use
// i.e. fluid.io/node-publish-method
LabelNodePublishMothod = LabelAnnotationPrefix + "node-publish-method"
LabelNodePublishMethod = LabelAnnotationPrefix + "node-publish-method"

// AnnotationSkipCheckMountReadyTarget is a runtime annotation that indicates if the fuse mount related with this runtime is ready should be checked in nodePuhlishVolume
// i.e. key: fluid.io/skip-check-mount-ready-target
// value:
// "": Skip none,
// "All": Skill all mount mode to check mount ready,
// "MountPod": for only mountPod to skip check mount ready,
// "Sidecar": for only sidecar to skip check mount ready,
AnnotationSkipCheckMountReadyTarget = LabelAnnotationPrefix + "skip-check-mount-ready-target"

// LabelAnnotationMountingDatasets is a label/annotation key indicating which datasets are currently being used by a pod.
// i.e. fluid.io/datasets-in-use
Expand Down
20 changes: 17 additions & 3 deletions pkg/csi/plugins/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,27 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}

// 1. Wait the runtime fuse ready and check the sub path existence
err = utils.CheckMountReadyAndSubPathExist(fluidPath, mountType, subPath)
useSymlink := useSymlink(req)

skipCheckMountReadyMountModeSelector, err := base.ParseMountModeSelectorFromStr(req.GetVolumeContext()[common.AnnotationSkipCheckMountReadyTarget])
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if skipCheckMountReadyMountModeSelector.Selected(base.MountPodMountMode) {
// 1. only mountPod involved csi-plugin
// 2. skip check mount ready for mountPod, for the scenario that dataset.spec.mounts is nil
// 3. if check mount ready is skipped for mountPod, symlink is forced to use, avoiding that unPublishVolume error occurs
useSymlink = true
} else {
err = utils.CheckMountReadyAndSubPathExist(fluidPath, mountType, subPath)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}

// use symlink
if useSymlink(req) {
if useSymlink {
if err := utils.CreateSymlink(targetPath, mountPath); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/alluxio/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (e *AlluxioEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}
e.runtimeInfo, err = base.BuildRuntimeInfo(e.name, e.namespace, e.runtimeType, opts...)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions pkg/ddc/base/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type RuntimeInfoInterface interface {

GetMetadataList() []datav1alpha1.Metadata

GetAnnotations() map[string]string

GetFuseMetricsScrapeTarget() mountModeSelector
}

Expand Down Expand Up @@ -115,6 +117,8 @@ type RuntimeInfo struct {

client client.Client

annotations map[string]string

metadataList []datav1alpha1.Metadata
}

Expand Down Expand Up @@ -199,6 +203,17 @@ func (info *RuntimeInfo) GetMetadataList() []datav1alpha1.Metadata {
return info.metadataList
}

func WithAnnotations(annotations map[string]string) RuntimeInfoOption {
return func(info *RuntimeInfo) error {
info.annotations = annotations
return nil
}
}

func (info *RuntimeInfo) GetAnnotations() map[string]string {
return info.annotations
}

func WithClientMetrics(clientMetrics datav1alpha1.ClientMetrics) RuntimeInfoOption {
return func(info *RuntimeInfo) error {
if len(clientMetrics.ScrapeTarget) == 0 {
Expand Down Expand Up @@ -389,6 +404,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(alluxioRuntime)),
WithAnnotations(alluxioRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.AlluxioRuntime, opts...)
if err != nil {
Expand All @@ -405,6 +421,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(jindoRuntime)),
WithClientMetrics(jindoRuntime.Spec.Fuse.Metrics),
WithAnnotations(jindoRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.JindoRuntime, opts...)
if err != nil {
Expand All @@ -420,6 +437,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(goosefsRuntime)),
WithAnnotations(goosefsRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.GooseFSRuntime, opts...)
if err != nil {
Expand All @@ -435,6 +453,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(juicefsRuntime)),
WithAnnotations(juicefsRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.JuiceFSRuntime, opts...)
if err != nil {
Expand All @@ -450,6 +469,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(thinRuntime)),
WithAnnotations(thinRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.ThinRuntime, opts...)
if err != nil {
Expand All @@ -465,6 +485,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(efcRuntime)),
WithAnnotations(efcRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.EFCRuntime, opts...)
if err != nil {
Expand All @@ -480,6 +501,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R
opts := []RuntimeInfoOption{
WithTieredStore(datav1alpha1.TieredStore{}),
WithMetadataList(GetMetadataListFromAnnotation(vineyardRuntime)),
WithAnnotations(vineyardRuntime.Annotations),
}
runtimeInfo, err = BuildRuntimeInfo(name, namespace, common.VineyardRuntime, opts...)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/efc/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (e *EFCEngine) getRuntimeInfo() (info base.RuntimeInfoInterface, err error)
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}

e.runtimeInfo, err = base.BuildRuntimeInfo(e.name, e.namespace, e.runtimeType, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/goosefs/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}

e.runtimeInfo, err = base.BuildRuntimeInfo(e.name, e.namespace, e.runtimeType, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/jindo/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}
// TODO: For now hack runtimeType with engineImpl for backward compatibility. Fix this
// when refactoring runtimeInfo.
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/jindocache/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (e *JindoCacheEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}
// TODO: For now hack runtimeType with engineImpl for backward compatibility. Fix this
// when refactoring runtimeInfo.
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/jindofsx/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (e *JindoFSxEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}
// TODO: For now hack runtimeType with engineImpl for backward compatibility. Fix this
// when refactoring runtimeInfo.
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/juicefs/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (j *JuiceFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}

j.runtimeInfo, err = base.BuildRuntimeInfo(j.name, j.namespace, j.runtimeType, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/thin/referencedataset/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (e *ReferenceDatasetEngine) getRuntimeInfo() (base.RuntimeInfoInterface, er
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}

e.runtimeInfo, err = base.BuildRuntimeInfo(e.name, e.namespace, e.runtimeType, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/thin/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (t *ThinEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}

t.runtimeInfo, err = base.BuildRuntimeInfo(t.name, t.namespace, t.runtimeType, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/vineyard/runtime_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (e *VineyardEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) {
opts := []base.RuntimeInfoOption{
base.WithTieredStore(runtime.Spec.TieredStore),
base.WithMetadataList(base.GetMetadataListFromAnnotation(runtime)),
base.WithAnnotations(runtime.Annotations),
}
e.runtimeInfo, err = base.BuildRuntimeInfo(e.name, e.namespace, e.runtimeType, opts...)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pkg/utils/dataset/volume/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,23 @@ func CreatePersistentVolumeForRuntime(client client.Client,
}
}

// set from runtime
for key, value := range runtime.GetAnnotations() {
if key == common.AnnotationSkipCheckMountReadyTarget {
pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes[common.AnnotationSkipCheckMountReadyTarget] = value
}
}

// set from annotations[data.fluid.io/metadataList]
metadataList := runtime.GetMetadataList()
for i := range metadataList {
if selector := metadataList[i].Selector; selector.Group != corev1.GroupName || selector.Kind != "PersistentVolume" {
continue
}
pv.Labels = utils.UnionMapsWithOverride(pv.Labels, metadataList[i].Labels)
pv.Annotations = utils.UnionMapsWithOverride(pv.Annotations, metadataList[i].Annotations)
// if pv labels has common.LabelNodePublishMothod and it's value is symlink, add to volumeAttributes
if v, ok := metadataList[i].Labels[common.LabelNodePublishMothod]; ok && v == common.NodePublishMethodSymlink {
// if pv labels has common.LabelNodePublishMethod and it's value is symlink, add to volumeAttributes
if v, ok := metadataList[i].Labels[common.LabelNodePublishMethod]; ok && v == common.NodePublishMethodSymlink {
pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes[common.NodePublishMethod] = v
}
}
Expand Down

0 comments on commit 3002618

Please sign in to comment.