Skip to content

Commit

Permalink
Enhancement: Unify the implementation of label concatenation across d…
Browse files Browse the repository at this point in the history
…ifferent Runtimes, and support labels with over limit length

Signed-off-by: jiuyu <[email protected]>
  • Loading branch information
jiuyu committed Jan 7, 2025
1 parent 4e199c8 commit 3a8daff
Show file tree
Hide file tree
Showing 53 changed files with 232 additions and 809 deletions.
4 changes: 2 additions & 2 deletions pkg/csi/plugins/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
// Once the label is removed, fuse pod on corresponding node will be terminated
// since node selector in the fuse daemonSet no longer matches.
// TODO: move all the label keys into a util func
fuseLabelKey := common.LabelAnnotationFusePrefix + namespace + "-" + name
fuseLabelKey := runtimeInfo.GetFuseLabelName()
var labelsToModify common.LabelsToModify
labelsToModify.Delete(fuseLabelKey)

Expand Down Expand Up @@ -401,7 +401,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
}

// 4. Label node to launch FUSE Pod
fuseLabelKey := common.LabelAnnotationFusePrefix + namespace + "-" + name
fuseLabelKey := utils.GetFuseLabelName(namespace, name)
var labelsToModify common.LabelsToModify
labelsToModify.Add(fuseLabelKey, "true")

Expand Down
13 changes: 5 additions & 8 deletions pkg/ddc/alluxio/deprecated_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ limitations under the License.
package alluxio

import (
"github.com/fluid-cloudnative/fluid/pkg/common/deprecated"
"github.com/fluid-cloudnative/fluid/pkg/utils"
apierrs "k8s.io/apimachinery/pkg/api/errors"
)

func (e *AlluxioEngine) getDeprecatedCommonLabelname() string {
return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name
}

func (e *AlluxioEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error) {

// return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name
Expand Down Expand Up @@ -54,11 +50,12 @@ func (e *AlluxioEngine) HasDeprecatedCommonLabelname() (deprecated bool, err err
nodeSelectors := workers.Spec.Template.Spec.NodeSelector
e.Log.Info("The current node selectors for worker", "workerName", workerName, "nodeSelector", nodeSelectors)

if _, deprecated = nodeSelectors[e.getDeprecatedCommonLabelname()]; deprecated {
deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name)
if _, deprecated = nodeSelectors[deprecatedCommonLabelName]; deprecated {
//
e.Log.Info("the deprecated node selector exists", "nodeSelector", e.getDeprecatedCommonLabelname())
e.Log.Info("the deprecated node selector exists", "nodeselector", deprecatedCommonLabelName)
} else {
e.Log.Info("The deprecated node selector doesn't exist", "nodeSelector", e.getDeprecatedCommonLabelname())
e.Log.Info("The deprecated node selector doesn't exist", "nodeselector", deprecatedCommonLabelName)
}

return
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/alluxio/deprecated_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -65,10 +66,8 @@ func TestAlluxioEngine_GetDeprecatedCommonLabelname(t *testing.T) {
out: "data.fluid.io/storage-test-fluid",
},
}
fakeClient := fake.NewFakeClientWithScheme(testScheme)
for _, test := range testCases {
engine := getTestAlluxioEngine(fakeClient, test.name, test.namespace)
out := engine.getDeprecatedCommonLabelname()
out := utils.GetCommonLabelName(true, test.namespace, test.name)
if out != test.out {
t.Errorf("input parameter is %s-%s,expected %s, got %s", test.namespace, test.name, test.out, out)
}
Expand Down
27 changes: 0 additions & 27 deletions pkg/ddc/alluxio/label.go

This file was deleted.

53 changes: 0 additions & 53 deletions pkg/ddc/alluxio/label_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/ddc/alluxio/transform_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (e *AlluxioEngine) transformFuse(runtime *datav1alpha1.AlluxioRuntime, data
} else {
value.Fuse.NodeSelector = map[string]string{}
}
value.Fuse.NodeSelector[e.getFuseLabelname()] = "true"
value.Fuse.NodeSelector[e.runtimeInfo.GetFuseLabelName()] = "true"

// parse fuse container network mode
value.Fuse.HostNetwork = datav1alpha1.IsHostNetwork(runtime.Spec.Fuse.NetworkMode)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/base/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func (info *RuntimeInfo) GetDatasetNumLabelName() string {

// GetFuseLabelName gets the label indicating a fuse running on some node.
func (info *RuntimeInfo) GetFuseLabelName() string {
return common.LabelAnnotationFusePrefix + info.namespace + "-" + info.name
return utils.TransferForOverLimitLabelName(common.LabelAnnotationFusePrefix, info.namespace, info.name)
}
4 changes: 2 additions & 2 deletions pkg/ddc/base/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/fluid-cloudnative/fluid/pkg/utils"
)

func TestGetStoragetLabelName(t *testing.T) {
func TestGetStorageLabelName(t *testing.T) {
tests := []struct {
info RuntimeInfo
expectedResult string
Expand All @@ -49,7 +49,7 @@ func TestGetStoragetLabelName(t *testing.T) {
}

for _, test := range tests {
result := utils.GetStoragetLabelName(common.HumanReadType, common.MemoryStorageType, test.info.IsDeprecatedNodeLabel(), test.info.runtimeType, test.info.namespace, test.info.name)
result := utils.GetStorageLabelName(common.HumanReadType, common.MemoryStorageType, test.info.IsDeprecatedNodeLabel(), test.info.runtimeType, test.info.namespace, test.info.name)
if test.expectedResult != result {
t.Errorf("check failure, expected %s, get %s", test.expectedResult, result)
}
Expand Down
23 changes: 0 additions & 23 deletions pkg/ddc/efc/label.go

This file was deleted.

50 changes: 0 additions & 50 deletions pkg/ddc/efc/label_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/ddc/efc/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (e *EFCEngine) transformFuse(runtime *datav1alpha1.EFCRuntime,
value.Fuse.NodeSelector = runtime.Spec.Fuse.NodeSelector
}
// The label will be added by CSI Plugin when any workload pod is scheduled on the node.
value.Fuse.NodeSelector[e.getFuseLabelName()] = "true"
value.Fuse.NodeSelector[e.runtimeInfo.GetFuseLabelName()] = "true"

// tiered store
err = e.transformFuseTieredStore(runtime, value)
Expand Down
13 changes: 5 additions & 8 deletions pkg/ddc/goosefs/deprecated_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ limitations under the License.
package goosefs

import (
"github.com/fluid-cloudnative/fluid/pkg/common/deprecated"
"github.com/fluid-cloudnative/fluid/pkg/utils"
apierrs "k8s.io/apimachinery/pkg/api/errors"
)

func (e *GooseFSEngine) getDeprecatedCommonLabelname() string {
return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name
}

func (e *GooseFSEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error) {

// return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name
Expand Down Expand Up @@ -54,11 +50,12 @@ func (e *GooseFSEngine) HasDeprecatedCommonLabelname() (deprecated bool, err err
nodeSelectors := workers.Spec.Template.Spec.NodeSelector
e.Log.Info("The current node selectors for worker", "workerName", workerName, "nodeSelector", nodeSelectors)

if _, deprecated = nodeSelectors[e.getDeprecatedCommonLabelname()]; deprecated {
deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name)
if _, deprecated = nodeSelectors[deprecatedCommonLabelName]; deprecated {
//
e.Log.Info("the deprecated node selector exists", "nodeselector", e.getDeprecatedCommonLabelname())
e.Log.Info("the deprecated node selector exists", "nodeselector", deprecatedCommonLabelName)
} else {
e.Log.Info("The deprecated node selector doesn't exist", "nodeselector", e.getDeprecatedCommonLabelname())
e.Log.Info("The deprecated node selector doesn't exist", "nodeselector", deprecatedCommonLabelName)
}

return
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddc/goosefs/deprecated_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -65,10 +66,8 @@ func TestGooseFSEngine_GetDeprecatedCommonLabelname(t *testing.T) {
out: "data.fluid.io/storage-test-fluid",
},
}
fakeClient := fake.NewFakeClientWithScheme(testScheme)
for _, test := range testCases {
engine := getTestGooseFSEngine(fakeClient, test.name, test.namespace)
out := engine.getDeprecatedCommonLabelname()
out := utils.GetCommonLabelName(true, test.namespace, test.name)
if out != test.out {
t.Errorf("input parameter is %s-%s,expected %s, got %s", test.namespace, test.name, test.out, out)
}
Expand Down
27 changes: 0 additions & 27 deletions pkg/ddc/goosefs/label.go

This file was deleted.

Loading

0 comments on commit 3a8daff

Please sign in to comment.