From 58ce2eac1d9a8db50a8e1fa41885b0ba2ddc5dc5 Mon Sep 17 00:00:00 2001 From: jiuyu Date: Tue, 7 Jan 2025 12:03:49 +0800 Subject: [PATCH] Enhancement: Unify the implementation of label concatenation across different Runtimes, and support labels with over limit length Signed-off-by: jiuyu --- .../alluxio/templates/worker/statefulset.yaml | 4 +- charts/efc/templates/worker/statefulset.yaml | 4 +- .../juicefs/templates/job.yaml | 2 +- .../juicefs/templates/statefulset.yaml | 2 +- .../goosefs/templates/worker/statefulset.yaml | 4 +- .../templates/worker/statefulset.yaml | 4 +- .../jindofs/templates/worker/statefulset.yaml | 4 +- .../templates/worker/statefulset.yaml | 4 +- .../juicefs/templates/worker/statefulset.yaml | 4 +- .../thin/templates/worker/statefuleset.yaml | 4 +- .../templates/worker/statefulset.yaml | 10 +-- pkg/controllers/runtime_controller.go | 2 +- pkg/csi/plugins/nodeserver.go | 5 +- pkg/ctrl/fuse.go | 4 +- pkg/datamigrate/value.go | 7 +- pkg/ddc/alluxio/deprecated_label.go | 13 ++- pkg/ddc/alluxio/deprecated_label_test.go | 5 +- pkg/ddc/alluxio/label.go | 27 ------- pkg/ddc/alluxio/label_test.go | 53 ------------ pkg/ddc/alluxio/node_test.go | 2 +- pkg/ddc/alluxio/transform.go | 1 + pkg/ddc/alluxio/transform_fuse.go | 2 +- pkg/ddc/alluxio/types.go | 3 +- pkg/ddc/base/label.go | 2 +- pkg/ddc/base/label_test.go | 4 +- pkg/ddc/efc/label.go | 23 ------ pkg/ddc/efc/label_test.go | 50 ------------ pkg/ddc/efc/transform.go | 3 +- pkg/ddc/efc/types.go | 21 ++--- pkg/ddc/goosefs/deprecated_label.go | 13 ++- pkg/ddc/goosefs/deprecated_label_test.go | 5 +- pkg/ddc/goosefs/label.go | 27 ------- pkg/ddc/goosefs/label_test.go | 53 ------------ pkg/ddc/goosefs/node_test.go | 2 +- pkg/ddc/goosefs/transform.go | 1 + pkg/ddc/goosefs/transform_fuse.go | 3 +- pkg/ddc/goosefs/types.go | 3 +- pkg/ddc/jindo/deprecated_label.go | 16 ++-- pkg/ddc/jindo/deprecated_label_test.go | 11 ++- pkg/ddc/jindo/label.go | 27 ------- pkg/ddc/jindo/label_test.go | 53 ------------ pkg/ddc/jindo/node_test.go | 2 +- pkg/ddc/jindo/runtime_info.go | 2 +- pkg/ddc/jindo/transform.go | 5 +- pkg/ddc/jindo/types.go | 49 ++++++------ pkg/ddc/jindo/worker.go | 2 +- pkg/ddc/jindocache/deprecated_label.go | 13 ++- pkg/ddc/jindocache/deprecated_label_test.go | 5 +- pkg/ddc/jindocache/label.go | 27 ------- pkg/ddc/jindocache/label_test.go | 53 ------------ pkg/ddc/jindocache/node_test.go | 2 +- pkg/ddc/jindocache/transform.go | 5 +- pkg/ddc/jindocache/types.go | 63 ++++++++------- pkg/ddc/jindofsx/deprecated_label.go | 13 ++- pkg/ddc/jindofsx/deprecated_label_test.go | 7 +- pkg/ddc/jindofsx/label.go | 27 ------- pkg/ddc/jindofsx/label_test.go | 53 ------------ pkg/ddc/jindofsx/node_test.go | 2 +- pkg/ddc/jindofsx/transform.go | 5 +- pkg/ddc/jindofsx/types.go | 63 ++++++++------- pkg/ddc/juicefs/data_migrate.go | 2 +- pkg/ddc/juicefs/deprecated_label.go | 14 ++-- pkg/ddc/juicefs/deprecated_label_test.go | 5 +- pkg/ddc/juicefs/label.go | 27 ------- pkg/ddc/juicefs/label_test.go | 55 ------------- pkg/ddc/juicefs/node_test.go | 2 +- pkg/ddc/juicefs/transform.go | 1 + pkg/ddc/juicefs/transform_fuse.go | 2 +- pkg/ddc/juicefs/type.go | 7 +- pkg/ddc/thin/label.go | 23 ------ pkg/ddc/thin/label_test.go | 54 ------------- pkg/ddc/thin/referencedataset/volume.go | 6 +- pkg/ddc/thin/transform.go | 1 + pkg/ddc/thin/transform_fuse.go | 2 +- pkg/ddc/thin/type.go | 3 +- pkg/ddc/vineyard/label.go | 24 ------ pkg/ddc/vineyard/label_test.go | 50 ------------ pkg/ddc/vineyard/node_test.go | 2 +- pkg/ddc/vineyard/transform.go | 4 +- pkg/ddc/vineyard/transform_test.go | 5 ++ pkg/ddc/vineyard/type.go | 3 +- pkg/utils/excluisve.go | 9 ++- pkg/utils/hash.go | 80 +++++++++++++++++++ pkg/utils/hash_test.go | 66 +++++++++++++++ pkg/utils/kubeclient/volume.go | 4 +- pkg/utils/label.go | 31 +++---- pkg/utils/label_test.go | 18 +++++ 87 files changed, 429 insertions(+), 956 deletions(-) delete mode 100644 pkg/ddc/alluxio/label.go delete mode 100644 pkg/ddc/alluxio/label_test.go delete mode 100644 pkg/ddc/efc/label.go delete mode 100644 pkg/ddc/efc/label_test.go delete mode 100644 pkg/ddc/goosefs/label.go delete mode 100644 pkg/ddc/goosefs/label_test.go delete mode 100644 pkg/ddc/jindo/label.go delete mode 100644 pkg/ddc/jindo/label_test.go delete mode 100644 pkg/ddc/jindocache/label.go delete mode 100644 pkg/ddc/jindocache/label_test.go delete mode 100644 pkg/ddc/jindofsx/label.go delete mode 100644 pkg/ddc/jindofsx/label_test.go delete mode 100644 pkg/ddc/juicefs/label.go delete mode 100644 pkg/ddc/juicefs/label_test.go delete mode 100644 pkg/ddc/thin/label.go delete mode 100644 pkg/ddc/thin/label_test.go delete mode 100644 pkg/ddc/vineyard/label.go delete mode 100644 pkg/ddc/vineyard/label_test.go create mode 100644 pkg/utils/hash.go create mode 100644 pkg/utils/hash_test.go diff --git a/charts/alluxio/templates/worker/statefulset.yaml b/charts/alluxio/templates/worker/statefulset.yaml index 8aba50087cc..f3700202e86 100644 --- a/charts/alluxio/templates/worker/statefulset.yaml +++ b/charts/alluxio/templates/worker/statefulset.yaml @@ -23,7 +23,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: alluxio-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -60,7 +60,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: alluxio-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} diff --git a/charts/efc/templates/worker/statefulset.yaml b/charts/efc/templates/worker/statefulset.yaml index 1c964bdba00..1e7c5912fa7 100644 --- a/charts/efc/templates/worker/statefulset.yaml +++ b/charts/efc/templates/worker/statefulset.yaml @@ -8,7 +8,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: efc-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -45,7 +45,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: efc-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} diff --git a/charts/fluid-datamigrate/juicefs/templates/job.yaml b/charts/fluid-datamigrate/juicefs/templates/job.yaml index 73f71244991..a5f47bf2017 100644 --- a/charts/fluid-datamigrate/juicefs/templates/job.yaml +++ b/charts/fluid-datamigrate/juicefs/templates/job.yaml @@ -39,7 +39,7 @@ spec: role: datamigrate-pod app: juicefs targetDataset: {{ required "targetDataset should be set" .Values.datamigrate.targetDataset }} - fluid.io/operation: migrate-{{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/operation: migrate-{{ .Values.fullNamespacedNameOverride }} {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.datamigrate.labels }} {{- range $key, $val := .Values.datamigrate.labels }} diff --git a/charts/fluid-datamigrate/juicefs/templates/statefulset.yaml b/charts/fluid-datamigrate/juicefs/templates/statefulset.yaml index 3a28ff774c5..e83699c44e7 100644 --- a/charts/fluid-datamigrate/juicefs/templates/statefulset.yaml +++ b/charts/fluid-datamigrate/juicefs/templates/statefulset.yaml @@ -34,7 +34,7 @@ spec: metadata: labels: app: {{ printf "%s-workers" .Release.Name }} - fluid.io/operation: migrate-{{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/operation: migrate-{{ .Values.fullNamespacedNameOverride }} spec: containers: - name: worker diff --git a/charts/goosefs/templates/worker/statefulset.yaml b/charts/goosefs/templates/worker/statefulset.yaml index 0ec566fed9d..bf7033936cd 100644 --- a/charts/goosefs/templates/worker/statefulset.yaml +++ b/charts/goosefs/templates/worker/statefulset.yaml @@ -12,7 +12,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} spec: @@ -37,7 +37,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} spec: enableServiceLinks: false diff --git a/charts/jindocache/templates/worker/statefulset.yaml b/charts/jindocache/templates/worker/statefulset.yaml index 7dff6313b15..9709a0490a5 100755 --- a/charts/jindocache/templates/worker/statefulset.yaml +++ b/charts/jindocache/templates/worker/statefulset.yaml @@ -13,7 +13,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -49,7 +49,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} diff --git a/charts/jindofs/templates/worker/statefulset.yaml b/charts/jindofs/templates/worker/statefulset.yaml index 28e48f5df5a..538f28f9e26 100755 --- a/charts/jindofs/templates/worker/statefulset.yaml +++ b/charts/jindofs/templates/worker/statefulset.yaml @@ -13,7 +13,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -44,7 +44,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.labels }} {{ toYaml .Values.labels | trim | indent 8 }} diff --git a/charts/jindofsx/templates/worker/statefulset.yaml b/charts/jindofsx/templates/worker/statefulset.yaml index d4e2b503de0..9c2a2b9f687 100755 --- a/charts/jindofsx/templates/worker/statefulset.yaml +++ b/charts/jindofsx/templates/worker/statefulset.yaml @@ -13,7 +13,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -49,7 +49,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} diff --git a/charts/juicefs/templates/worker/statefulset.yaml b/charts/juicefs/templates/worker/statefulset.yaml index 9eb09833ce7..b123bd43ed8 100644 --- a/charts/juicefs/templates/worker/statefulset.yaml +++ b/charts/juicefs/templates/worker/statefulset.yaml @@ -9,7 +9,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: juicefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -48,7 +48,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: juicefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} diff --git a/charts/thin/templates/worker/statefuleset.yaml b/charts/thin/templates/worker/statefuleset.yaml index f3e28923fa1..b11b6647d21 100644 --- a/charts/thin/templates/worker/statefuleset.yaml +++ b/charts/thin/templates/worker/statefuleset.yaml @@ -8,7 +8,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: thin-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -41,7 +41,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: thin-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} fluid.io/dataset-placement: {{ .Values.placement }} spec: {{- if .Values.worker.imagePullSecrets }} diff --git a/charts/vineyard/templates/worker/statefulset.yaml b/charts/vineyard/templates/worker/statefulset.yaml index 7feada86bf5..b6e06109674 100644 --- a/charts/vineyard/templates/worker/statefulset.yaml +++ b/charts/vineyard/templates/worker/statefulset.yaml @@ -25,7 +25,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: vineyard-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} {{- include "library.fluid.labels" . | nindent 4 }} {{- if .Values.owner.enabled }} ownerReferences: @@ -46,7 +46,7 @@ spec: chart: {{ $chart }} release: {{ .Release.Name }} role: vineyard-worker - app.kubernetes.io/instance: {{ .Release.Namespace }}-{{ $fullName }}-worker + app.kubernetes.io/instance: {{ .Values.fullNamespacedNameOverride }}-worker template: metadata: annotations: @@ -62,8 +62,8 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: vineyard-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} - app.kubernetes.io/instance: {{ .Release.Namespace }}-{{ $fullName }}-worker + fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} + app.kubernetes.io/instance: {{ .Values.fullNamespacedNameOverride }}-worker {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} @@ -215,5 +215,5 @@ spec: - key: app.kubernetes.io/instance operator: In values: - - {{ .Release.Namespace }}-{{ $fullName }}-worker + - {{ .Values.fullNamespacedNameOverride }}-worker topologyKey: "kubernetes.io/hostname" diff --git a/pkg/controllers/runtime_controller.go b/pkg/controllers/runtime_controller.go index b410ec73816..55624b9807b 100644 --- a/pkg/controllers/runtime_controller.go +++ b/pkg/controllers/runtime_controller.go @@ -187,7 +187,7 @@ func (r *RuntimeReconciler) ReconcileRuntimeDeletion(engine base.Engine, ctx cru return utils.RequeueAfterInterval(time.Duration(20 * time.Second)) } - // 1. Delete the implementation of the the runtime + // 1. Delete the implementation of the runtime err = engine.Shutdown() if err != nil { r.Recorder.Eventf(ctx.Runtime, corev1.EventTypeWarning, common.ErrorProcessRuntimeReason, "Failed to shutdown engine %v", err) diff --git a/pkg/csi/plugins/nodeserver.go b/pkg/csi/plugins/nodeserver.go index 1516714ed83..3c512ed8862 100644 --- a/pkg/csi/plugins/nodeserver.go +++ b/pkg/csi/plugins/nodeserver.go @@ -344,8 +344,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag // 4. remove label on node // 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 := utils.GetFuseLabelName(namespace, name) var labelsToModify common.LabelsToModify labelsToModify.Delete(fuseLabelKey) @@ -401,7 +400,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") diff --git a/pkg/ctrl/fuse.go b/pkg/ctrl/fuse.go index 1f8e5d95ade..627d156d675 100644 --- a/pkg/ctrl/fuse.go +++ b/pkg/ctrl/fuse.go @@ -109,7 +109,7 @@ func (e *Helper) CheckFuseHealthy(recorder record.EventRecorder, runtime base.Ru func (e *Helper) CleanUpFuse() (count int, err error) { var ( nodeList = &corev1.NodeList{} - fuseLabelKey = common.LabelAnnotationFusePrefix + e.runtimeInfo.GetNamespace() + "-" + e.runtimeInfo.GetName() + fuseLabelKey = utils.GetFuseLabelName(e.runtimeInfo.GetNamespace(), e.runtimeInfo.GetName()) ) labelNames := []string{fuseLabelKey} @@ -153,7 +153,7 @@ func (e *Helper) CleanUpFuse() (count int, err error) { func (e *Helper) GetFuseNodes() (nodes []corev1.Node, err error) { var ( nodeList = &corev1.NodeList{} - fuseLabelKey = common.LabelAnnotationFusePrefix + e.runtimeInfo.GetNamespace() + "-" + e.runtimeInfo.GetName() + fuseLabelKey = utils.GetFuseLabelName(e.runtimeInfo.GetNamespace(), e.runtimeInfo.GetName()) ) labelNames := []string{fuseLabelKey} diff --git a/pkg/datamigrate/value.go b/pkg/datamigrate/value.go index f91ff523463..bbf25f6c3ac 100644 --- a/pkg/datamigrate/value.go +++ b/pkg/datamigrate/value.go @@ -24,9 +24,10 @@ import ( ) type DataMigrateValue struct { - Name string `json:"name"` - Owner *common.OwnerReference `json:"owner,omitempty"` - DataMigrateInfo DataMigrateInfo `json:"datamigrate"` + Name string `json:"name"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + Owner *common.OwnerReference `json:"owner,omitempty"` + DataMigrateInfo DataMigrateInfo `json:"datamigrate"` } type DataMigrateInfo struct { diff --git a/pkg/ddc/alluxio/deprecated_label.go b/pkg/ddc/alluxio/deprecated_label.go index a4beeeea2f9..97bfc1f6d91 100644 --- a/pkg/ddc/alluxio/deprecated_label.go +++ b/pkg/ddc/alluxio/deprecated_label.go @@ -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 @@ -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 diff --git a/pkg/ddc/alluxio/deprecated_label_test.go b/pkg/ddc/alluxio/deprecated_label_test.go index fa899f118bd..3d2595a4c76 100644 --- a/pkg/ddc/alluxio/deprecated_label_test.go +++ b/pkg/ddc/alluxio/deprecated_label_test.go @@ -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" @@ -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) } diff --git a/pkg/ddc/alluxio/label.go b/pkg/ddc/alluxio/label.go deleted file mode 100644 index a19379d9975..00000000000 --- a/pkg/ddc/alluxio/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2023 The Fluid Author. - -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 alluxio - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *AlluxioEngine) getCommonLabelname() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *AlluxioEngine) getFuseLabelname() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/alluxio/label_test.go b/pkg/ddc/alluxio/label_test.go deleted file mode 100644 index 59d9297c6af..00000000000 --- a/pkg/ddc/alluxio/label_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2021 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 alluxio - -import "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &AlluxioEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelname() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/alluxio/node_test.go b/pkg/ddc/alluxio/node_test.go index 403698e3d9c..24b50e3782b 100644 --- a/pkg/ddc/alluxio/node_test.go +++ b/pkg/ddc/alluxio/node_test.go @@ -340,7 +340,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelname())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/alluxio/transform.go b/pkg/ddc/alluxio/transform.go index 78b48d890d6..36b782f821b 100644 --- a/pkg/ddc/alluxio/transform.go +++ b/pkg/ddc/alluxio/transform.go @@ -50,6 +50,7 @@ func (e *AlluxioEngine) transform(runtime *datav1alpha1.AlluxioRuntime) (value * } value.FullnameOverride = e.name + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) // 1.transform the common part err = e.transformCommonPart(runtime, dataset, value) diff --git a/pkg/ddc/alluxio/transform_fuse.go b/pkg/ddc/alluxio/transform_fuse.go index 2419f066848..71b441aa2e4 100644 --- a/pkg/ddc/alluxio/transform_fuse.go +++ b/pkg/ddc/alluxio/transform_fuse.go @@ -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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" // parse fuse container network mode value.Fuse.HostNetwork = datav1alpha1.IsHostNetwork(runtime.Spec.Fuse.NetworkMode) diff --git a/pkg/ddc/alluxio/types.go b/pkg/ddc/alluxio/types.go index 5a9de0a341a..9baca9bd975 100644 --- a/pkg/ddc/alluxio/types.go +++ b/pkg/ddc/alluxio/types.go @@ -27,7 +27,8 @@ import ( // The value yaml file type Alluxio struct { - FullnameOverride string `json:"fullnameOverride"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/base/label.go b/pkg/ddc/base/label.go index 6a7c67a1a1a..66411313dc9 100644 --- a/pkg/ddc/base/label.go +++ b/pkg/ddc/base/label.go @@ -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.TransferFullNamespacedNameWithPrefixToLegalValue(common.LabelAnnotationFusePrefix, info.namespace, info.name) } diff --git a/pkg/ddc/base/label_test.go b/pkg/ddc/base/label_test.go index 3a2111212cd..52cd561b15b 100644 --- a/pkg/ddc/base/label_test.go +++ b/pkg/ddc/base/label_test.go @@ -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 @@ -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) } diff --git a/pkg/ddc/efc/label.go b/pkg/ddc/efc/label.go deleted file mode 100644 index 5c29d27d5d4..00000000000 --- a/pkg/ddc/efc/label.go +++ /dev/null @@ -1,23 +0,0 @@ -/* - 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 efc - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *EFCEngine) getFuseLabelName() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/efc/label_test.go b/pkg/ddc/efc/label_test.go deleted file mode 100644 index bc188133d98..00000000000 --- a/pkg/ddc/efc/label_test.go +++ /dev/null @@ -1,50 +0,0 @@ -/* - 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 efc - -import ( - "testing" -) - -func TestEFCEngine_getCommonLabelName(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "fuse1", - namespace: "fluid", - out: "fluid.io/f-fluid-fuse1", - }, - { - name: "fuse2", - namespace: "fluid", - out: "fluid.io/f-fluid-fuse2", - }, - } - for _, testCase := range testCases { - engine := &EFCEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getFuseLabelName() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/efc/transform.go b/pkg/ddc/efc/transform.go index 9abe3f87175..1e322fc5656 100644 --- a/pkg/ddc/efc/transform.go +++ b/pkg/ddc/efc/transform.go @@ -47,6 +47,7 @@ func (e *EFCEngine) transform(runtime *datav1alpha1.EFCRuntime) (value *EFC, err } value.FullnameOverride = e.name + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) err = e.transformMasters(runtime, dataset, value) if err != nil { @@ -216,7 +217,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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" // tiered store err = e.transformFuseTieredStore(runtime, value) diff --git a/pkg/ddc/efc/types.go b/pkg/ddc/efc/types.go index 126cf562898..f7f7dd6e615 100644 --- a/pkg/ddc/efc/types.go +++ b/pkg/ddc/efc/types.go @@ -26,16 +26,17 @@ import ( // The value yaml file type EFC struct { - FullnameOverride string `yaml:"fullnameOverride"` - PlacementMode string `yaml:"placement,omitempty"` - Master Master `yaml:"master"` - Worker Worker `yaml:"worker"` - Fuse Fuse `yaml:"fuse"` - InitFuse InitFuse `yaml:"initFuse"` - OSAdvise OSAdvise `yaml:"osAdvise"` - Tolerations []v1.Toleration `yaml:"tolerations,omitempty"` - Owner *common.OwnerReference `yaml:"owner,omitempty"` - RuntimeIdentity common.RuntimeIdentity `yaml:"runtimeIdentity,omitempty"` + FullnameOverride string `yaml:"fullnameOverride"` + FullNamespacedNameOverride string `yaml:"fullNamespacedNameOverride"` + PlacementMode string `yaml:"placement,omitempty"` + Master Master `yaml:"master"` + Worker Worker `yaml:"worker"` + Fuse Fuse `yaml:"fuse"` + InitFuse InitFuse `yaml:"initFuse"` + OSAdvise OSAdvise `yaml:"osAdvise"` + Tolerations []v1.Toleration `yaml:"tolerations,omitempty"` + Owner *common.OwnerReference `yaml:"owner,omitempty"` + RuntimeIdentity common.RuntimeIdentity `yaml:"runtimeIdentity,omitempty"` } type OSAdvise struct { diff --git a/pkg/ddc/goosefs/deprecated_label.go b/pkg/ddc/goosefs/deprecated_label.go index d0bb66b2d7f..8d42181a033 100644 --- a/pkg/ddc/goosefs/deprecated_label.go +++ b/pkg/ddc/goosefs/deprecated_label.go @@ -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 @@ -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 diff --git a/pkg/ddc/goosefs/deprecated_label_test.go b/pkg/ddc/goosefs/deprecated_label_test.go index de2ea6360c7..e6e50689e6d 100644 --- a/pkg/ddc/goosefs/deprecated_label_test.go +++ b/pkg/ddc/goosefs/deprecated_label_test.go @@ -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" @@ -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) } diff --git a/pkg/ddc/goosefs/label.go b/pkg/ddc/goosefs/label.go deleted file mode 100644 index f94c9c5542a..00000000000 --- a/pkg/ddc/goosefs/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -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 goosefs - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *GooseFSEngine) getCommonLabelname() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *GooseFSEngine) getFuseLabelname() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/goosefs/label_test.go b/pkg/ddc/goosefs/label_test.go deleted file mode 100644 index 3e829bf1def..00000000000 --- a/pkg/ddc/goosefs/label_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 goosefs - -import "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &GooseFSEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelname() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/goosefs/node_test.go b/pkg/ddc/goosefs/node_test.go index 36b1e271b07..3ed68b08464 100644 --- a/pkg/ddc/goosefs/node_test.go +++ b/pkg/ddc/goosefs/node_test.go @@ -340,7 +340,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelname())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/goosefs/transform.go b/pkg/ddc/goosefs/transform.go index bf28da35d5c..62e6d12a28c 100644 --- a/pkg/ddc/goosefs/transform.go +++ b/pkg/ddc/goosefs/transform.go @@ -45,6 +45,7 @@ func (e *GooseFSEngine) transform(runtime *datav1alpha1.GooseFSRuntime) (value * value = &GooseFS{} value.FullnameOverride = e.name + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) // 1.transform the common part err = e.transformCommonPart(runtime, dataset, value) diff --git a/pkg/ddc/goosefs/transform_fuse.go b/pkg/ddc/goosefs/transform_fuse.go index 8fa5b690135..6a4f7b74fca 100644 --- a/pkg/ddc/goosefs/transform_fuse.go +++ b/pkg/ddc/goosefs/transform_fuse.go @@ -18,6 +18,7 @@ package goosefs import ( "fmt" + "github.com/fluid-cloudnative/fluid/pkg/utils" "strings" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" @@ -86,7 +87,7 @@ func (e *GooseFSEngine) transformFuse(runtime *datav1alpha1.GooseFSRuntime, data value.Fuse.NodeSelector = map[string]string{} } - value.Fuse.NodeSelector[e.getFuseLabelname()] = "true" + value.Fuse.NodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" value.Fuse.HostNetwork = true value.Fuse.HostPID = common.HostPIDEnabled(runtime.Annotations) value.Fuse.Enabled = true diff --git a/pkg/ddc/goosefs/types.go b/pkg/ddc/goosefs/types.go index 1f20e02ed7c..969a6570989 100644 --- a/pkg/ddc/goosefs/types.go +++ b/pkg/ddc/goosefs/types.go @@ -26,7 +26,8 @@ import ( // The value yaml file type GooseFS struct { - FullnameOverride string `yaml:"fullnameOverride"` + FullnameOverride string `yaml:"fullnameOverride"` + FullNamespacedNameOverride string `yaml:"fullNamespacedNameOverride"` common.ImageInfo `yaml:",inline"` common.UserInfo `yaml:",inline"` diff --git a/pkg/ddc/jindo/deprecated_label.go b/pkg/ddc/jindo/deprecated_label.go index 4ace71a6550..73f91410f76 100644 --- a/pkg/ddc/jindo/deprecated_label.go +++ b/pkg/ddc/jindo/deprecated_label.go @@ -17,16 +17,11 @@ limitations under the License. package jindo 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 *JindoEngine) getDeprecatedCommonLabelname() string { - return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *JindoEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error) { - +func (e *JindoEngine) HasDeprecatedCommonLabelName() (deprecated bool, err error) { // return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name var ( @@ -54,11 +49,12 @@ func (e *JindoEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error 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 diff --git a/pkg/ddc/jindo/deprecated_label_test.go b/pkg/ddc/jindo/deprecated_label_test.go index a09f6c06782..5353b5fffd4 100644 --- a/pkg/ddc/jindo/deprecated_label_test.go +++ b/pkg/ddc/jindo/deprecated_label_test.go @@ -17,6 +17,7 @@ limitations under the License. package jindo import ( + "github.com/fluid-cloudnative/fluid/pkg/utils" "testing" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" @@ -44,7 +45,7 @@ func getTestJindoEngine(client client.Client, name string, namespace string) *Ji return engine } -func TestJindoEngine_GetDeprecatedCommonLabelname(t *testing.T) { +func TestJindoEngine_GetDeprecatedCommonLabelName(t *testing.T) { testCases := []struct { name string namespace string @@ -66,10 +67,8 @@ func TestJindoEngine_GetDeprecatedCommonLabelname(t *testing.T) { out: "data.fluid.io/storage-test-fluid", }, } - fakeClient := fake.NewFakeClientWithScheme(testScheme) for _, test := range testCases { - engine := getTestJindoEngine(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) } @@ -77,7 +76,7 @@ func TestJindoEngine_GetDeprecatedCommonLabelname(t *testing.T) { } -func TestJindoEngine_HasDeprecatedCommonLabelname(t *testing.T) { +func TestJindoEngine_HasDeprecatedCommonLabelName(t *testing.T) { // worker-name = e.name+"-worker" daemonSetWithSelector := &v1.DaemonSet{ @@ -137,7 +136,7 @@ func TestJindoEngine_HasDeprecatedCommonLabelname(t *testing.T) { for _, test := range testCases { engine := getTestJindoEngine(fakeClient, test.name, test.namespace) - out, err := engine.HasDeprecatedCommonLabelname() + out, err := engine.HasDeprecatedCommonLabelName() if out != test.out { t.Errorf("input parameter is %s-%s,expected %t, got %t", test.namespace, test.name, test.out, out) } diff --git a/pkg/ddc/jindo/label.go b/pkg/ddc/jindo/label.go deleted file mode 100644 index 2496d85bd86..00000000000 --- a/pkg/ddc/jindo/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -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 "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *JindoEngine) getCommonLabelname() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *JindoEngine) getFuseLabelname() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/jindo/label_test.go b/pkg/ddc/jindo/label_test.go deleted file mode 100644 index b8b3a12c62b..00000000000 --- a/pkg/ddc/jindo/label_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &JindoEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelname() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/jindo/node_test.go b/pkg/ddc/jindo/node_test.go index a7f306c593d..75629694238 100644 --- a/pkg/ddc/jindo/node_test.go +++ b/pkg/ddc/jindo/node_test.go @@ -341,7 +341,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelname())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/jindo/runtime_info.go b/pkg/ddc/jindo/runtime_info.go index a8dfc714fcc..b453b01e314 100644 --- a/pkg/ddc/jindo/runtime_info.go +++ b/pkg/ddc/jindo/runtime_info.go @@ -46,7 +46,7 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) // Check if the runtime is using deprecated labels - isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() + isLabelDeprecated, err := e.HasDeprecatedCommonLabelName() if err != nil { return e.runtimeInfo, err } diff --git a/pkg/ddc/jindo/transform.go b/pkg/ddc/jindo/transform.go index 69248db038d..f5b7807087f 100644 --- a/pkg/ddc/jindo/transform.go +++ b/pkg/ddc/jindo/transform.go @@ -119,6 +119,9 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind Name: runtime.Name, }, } + + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) + e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) if err != nil { @@ -461,7 +464,7 @@ func (e *JindoEngine) transformFuseNodeSelector(runtime *datav1alpha1.JindoRunti } // 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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" return nil } diff --git a/pkg/ddc/jindo/types.go b/pkg/ddc/jindo/types.go index 0e62a678a08..6bbf4948782 100644 --- a/pkg/ddc/jindo/types.go +++ b/pkg/ddc/jindo/types.go @@ -23,30 +23,31 @@ import ( ) type Jindo struct { - Image string `yaml:"image"` - ImageTag string `yaml:"imageTag"` - ImagePullPolicy string `yaml:"imagePullPolicy"` - FuseImage string `yaml:"fuseImage"` - FuseImageTag string `yaml:"fuseImageTag"` - User int `yaml:"user"` - Group int `yaml:"group"` - FsGroup int `yaml:"fsGroup"` - UseHostNetwork bool `yaml:"useHostNetwork"` - Properties map[string]string `yaml:"properties"` - Master Master `yaml:"master"` - Worker Worker `yaml:"worker"` - Fuse Fuse `yaml:"fuse"` - Mounts Mounts `yaml:"mounts"` - HadoopConfig HadoopConfig `yaml:"hadoopConfig,omitempty"` - Secret string `yaml:"secret,omitempty"` - Tolerations []v1.Toleration `yaml:"tolerations,omitempty"` - InitPortCheck common.InitPortCheck `yaml:"initPortCheck,omitempty"` - Labels map[string]string `yaml:"labels,omitempty"` - LogConfig map[string]string `yaml:"logConfig,omitempty"` - PlacementMode string `yaml:"placement,omitempty"` - Owner *common.OwnerReference `yaml:"owner,omitempty"` - RuntimeIdentity common.RuntimeIdentity `yaml:"runtimeIdentity"` - ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + Image string `yaml:"image"` + ImageTag string `yaml:"imageTag"` + ImagePullPolicy string `yaml:"imagePullPolicy"` + FuseImage string `yaml:"fuseImage"` + FuseImageTag string `yaml:"fuseImageTag"` + User int `yaml:"user"` + Group int `yaml:"group"` + FsGroup int `yaml:"fsGroup"` + UseHostNetwork bool `yaml:"useHostNetwork"` + Properties map[string]string `yaml:"properties"` + Master Master `yaml:"master"` + Worker Worker `yaml:"worker"` + Fuse Fuse `yaml:"fuse"` + Mounts Mounts `yaml:"mounts"` + HadoopConfig HadoopConfig `yaml:"hadoopConfig,omitempty"` + Secret string `yaml:"secret,omitempty"` + Tolerations []v1.Toleration `yaml:"tolerations,omitempty"` + InitPortCheck common.InitPortCheck `yaml:"initPortCheck,omitempty"` + Labels map[string]string `yaml:"labels,omitempty"` + LogConfig map[string]string `yaml:"logConfig,omitempty"` + PlacementMode string `yaml:"placement,omitempty"` + Owner *common.OwnerReference `yaml:"owner,omitempty"` + RuntimeIdentity common.RuntimeIdentity `yaml:"runtimeIdentity"` + ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } type HadoopConfig struct { diff --git a/pkg/ddc/jindo/worker.go b/pkg/ddc/jindo/worker.go index 2595a84a0d9..d268340625e 100644 --- a/pkg/ddc/jindo/worker.go +++ b/pkg/ddc/jindo/worker.go @@ -225,7 +225,7 @@ func (e *JindoEngine) buildWorkersAffinity(workers *v1.StatefulSet) (workersToUp Preference: corev1.NodeSelectorTerm{ MatchExpressions: []corev1.NodeSelectorRequirement{ { - Key: e.getFuseLabelname(), + Key: utils.GetFuseLabelName(e.namespace, e.name), Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}, }, diff --git a/pkg/ddc/jindocache/deprecated_label.go b/pkg/ddc/jindocache/deprecated_label.go index d672d4f8ad1..60beb01bb40 100644 --- a/pkg/ddc/jindocache/deprecated_label.go +++ b/pkg/ddc/jindocache/deprecated_label.go @@ -17,14 +17,10 @@ limitations under the License. package jindocache 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 *JindoCacheEngine) getDeprecatedCommonLabelname() string { - return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - func (e *JindoCacheEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error) { // return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name @@ -54,11 +50,12 @@ func (e *JindoCacheEngine) HasDeprecatedCommonLabelname() (deprecated bool, 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 diff --git a/pkg/ddc/jindocache/deprecated_label_test.go b/pkg/ddc/jindocache/deprecated_label_test.go index 4f2dc0626bc..bb1d7da4e2b 100644 --- a/pkg/ddc/jindocache/deprecated_label_test.go +++ b/pkg/ddc/jindocache/deprecated_label_test.go @@ -22,6 +22,7 @@ import ( datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" "github.com/fluid-cloudnative/fluid/pkg/common" "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" @@ -66,10 +67,8 @@ func TestJindoCacheEngine_GetDeprecatedCommonLabelname(t *testing.T) { out: "data.fluid.io/storage-test-fluid", }, } - fakeClient := fake.NewFakeClientWithScheme(testScheme) for _, test := range testCases { - engine := getTestJindoCacheEngine(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) } diff --git a/pkg/ddc/jindocache/label.go b/pkg/ddc/jindocache/label.go deleted file mode 100644 index da862c32350..00000000000 --- a/pkg/ddc/jindocache/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2023 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 jindocache - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *JindoCacheEngine) getCommonLabelname() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *JindoCacheEngine) getFuseLabelname() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/jindocache/label_test.go b/pkg/ddc/jindocache/label_test.go deleted file mode 100644 index d10f9ba88c5..00000000000 --- a/pkg/ddc/jindocache/label_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2023 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 jindocache - -import "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &JindoCacheEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelname() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/jindocache/node_test.go b/pkg/ddc/jindocache/node_test.go index 7932a346a82..02ff163457d 100644 --- a/pkg/ddc/jindocache/node_test.go +++ b/pkg/ddc/jindocache/node_test.go @@ -347,7 +347,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelname())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/jindocache/transform.go b/pkg/ddc/jindocache/transform.go index 323452aa827..5ce14b84926 100644 --- a/pkg/ddc/jindocache/transform.go +++ b/pkg/ddc/jindocache/transform.go @@ -153,6 +153,9 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value Name: e.name, }, } + + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) + e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) if err != nil { @@ -904,7 +907,7 @@ func (e *JindoCacheEngine) transformFuseNodeSelector(runtime *datav1alpha1.Jindo } // 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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" } func (e *JindoCacheEngine) transformNodeSelector(runtime *datav1alpha1.JindoRuntime) map[string]string { diff --git a/pkg/ddc/jindocache/types.go b/pkg/ddc/jindocache/types.go index a5938426734..01c5736e5c0 100644 --- a/pkg/ddc/jindocache/types.go +++ b/pkg/ddc/jindocache/types.go @@ -22,37 +22,38 @@ import ( ) type Jindo struct { - FullnameOverride string `json:"fullnameOverride"` - Image string `json:"image"` - ImageTag string `json:"imageTag"` - ImagePullPolicy string `json:"imagePullPolicy"` - FuseImage string `json:"fuseImage"` - FuseImageTag string `json:"fuseImageTag"` - FuseImagePullPolicy string `json:"fuseImagePullPolicy"` - User int `json:"user"` - Group int `json:"group"` - UseHostNetwork bool `json:"useHostNetwork"` - Properties map[string]string `json:"properties"` - Master Master `json:"master"` - Worker Worker `json:"worker"` - Fuse Fuse `json:"fuse"` - Mounts Mounts `json:"mounts"` - HadoopConfig HadoopConfig `json:"hadoopConfig,omitempty"` - Secret string `json:"secret,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - InitPortCheck common.InitPortCheck `json:"initPortCheck,omitempty"` - LogConfig map[string]string `json:"logConfig,omitempty"` - FuseLogConfig map[string]string `json:"fuseLogConfig,omitempty"` - PlacementMode string `json:"placement,omitempty"` - Owner *common.OwnerReference `json:"owner,omitempty"` - RuntimeIdentity common.RuntimeIdentity `json:"runtimeIdentity"` - ClusterDomain string `json:"clusterDomain,omitempty"` - UFSVolumes []UFSVolume `json:"ufsVolumes,omitempty"` - SecretKey string `json:"secretKey,omitempty"` - SecretValue string `json:"secretValue,omitempty"` - UseStsToken bool `json:"UseStsToken"` - MountType string `json:"mountType,omitempty"` - ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + Image string `json:"image"` + ImageTag string `json:"imageTag"` + ImagePullPolicy string `json:"imagePullPolicy"` + FuseImage string `json:"fuseImage"` + FuseImageTag string `json:"fuseImageTag"` + FuseImagePullPolicy string `json:"fuseImagePullPolicy"` + User int `json:"user"` + Group int `json:"group"` + UseHostNetwork bool `json:"useHostNetwork"` + Properties map[string]string `json:"properties"` + Master Master `json:"master"` + Worker Worker `json:"worker"` + Fuse Fuse `json:"fuse"` + Mounts Mounts `json:"mounts"` + HadoopConfig HadoopConfig `json:"hadoopConfig,omitempty"` + Secret string `json:"secret,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + InitPortCheck common.InitPortCheck `json:"initPortCheck,omitempty"` + LogConfig map[string]string `json:"logConfig,omitempty"` + FuseLogConfig map[string]string `json:"fuseLogConfig,omitempty"` + PlacementMode string `json:"placement,omitempty"` + Owner *common.OwnerReference `json:"owner,omitempty"` + RuntimeIdentity common.RuntimeIdentity `json:"runtimeIdentity"` + ClusterDomain string `json:"clusterDomain,omitempty"` + UFSVolumes []UFSVolume `json:"ufsVolumes,omitempty"` + SecretKey string `json:"secretKey,omitempty"` + SecretValue string `json:"secretValue,omitempty"` + UseStsToken bool `json:"UseStsToken"` + MountType string `json:"mountType,omitempty"` + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } type HadoopConfig struct { diff --git a/pkg/ddc/jindofsx/deprecated_label.go b/pkg/ddc/jindofsx/deprecated_label.go index 409c35458e0..0fc4613eca6 100644 --- a/pkg/ddc/jindofsx/deprecated_label.go +++ b/pkg/ddc/jindofsx/deprecated_label.go @@ -17,14 +17,10 @@ limitations under the License. package jindofsx 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 *JindoFSxEngine) getDeprecatedCommonLabelname() string { - return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - func (e *JindoFSxEngine) HasDeprecatedCommonLabelname() (deprecated bool, err error) { // return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name @@ -54,11 +50,12 @@ func (e *JindoFSxEngine) HasDeprecatedCommonLabelname() (deprecated bool, err er 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 diff --git a/pkg/ddc/jindofsx/deprecated_label_test.go b/pkg/ddc/jindofsx/deprecated_label_test.go index 2119013b5a5..ecbfeae4e52 100644 --- a/pkg/ddc/jindofsx/deprecated_label_test.go +++ b/pkg/ddc/jindofsx/deprecated_label_test.go @@ -22,6 +22,7 @@ import ( datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" "github.com/fluid-cloudnative/fluid/pkg/common" "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" @@ -44,7 +45,7 @@ func getTestJindoFSxEngine(client client.Client, name string, namespace string) return engine } -func TestJindoFSxEngine_GetDeprecatedCommonLabelname(t *testing.T) { +func TestJindoFSxEngine_GetDeprecatedCommonLabelName(t *testing.T) { testCases := []struct { name string namespace string @@ -66,10 +67,8 @@ func TestJindoFSxEngine_GetDeprecatedCommonLabelname(t *testing.T) { out: "data.fluid.io/storage-test-fluid", }, } - fakeClient := fake.NewFakeClientWithScheme(testScheme) for _, test := range testCases { - engine := getTestJindoFSxEngine(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) } diff --git a/pkg/ddc/jindofsx/label.go b/pkg/ddc/jindofsx/label.go deleted file mode 100644 index bbd204a24ed..00000000000 --- a/pkg/ddc/jindofsx/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -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 jindofsx - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *JindoFSxEngine) getCommonLabelname() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *JindoFSxEngine) getFuseLabelname() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/jindofsx/label_test.go b/pkg/ddc/jindofsx/label_test.go deleted file mode 100644 index b69b2f640cb..00000000000 --- a/pkg/ddc/jindofsx/label_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 jindofsx - -import "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &JindoFSxEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelname() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/jindofsx/node_test.go b/pkg/ddc/jindofsx/node_test.go index 39153bf1706..8618e3bd862 100644 --- a/pkg/ddc/jindofsx/node_test.go +++ b/pkg/ddc/jindofsx/node_test.go @@ -347,7 +347,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelname())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/jindofsx/transform.go b/pkg/ddc/jindofsx/transform.go index 8310dd0a817..bf1431bd3f4 100644 --- a/pkg/ddc/jindofsx/transform.go +++ b/pkg/ddc/jindofsx/transform.go @@ -153,6 +153,9 @@ func (e *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J Name: e.name, }, } + + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) + e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) if err != nil { @@ -788,7 +791,7 @@ func (e *JindoFSxEngine) transformFuseNodeSelector(runtime *datav1alpha1.JindoRu } // 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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" } func (e *JindoFSxEngine) transformNodeSelector(runtime *datav1alpha1.JindoRuntime) map[string]string { diff --git a/pkg/ddc/jindofsx/types.go b/pkg/ddc/jindofsx/types.go index 9e7a166ced9..4a7e4ef8b13 100644 --- a/pkg/ddc/jindofsx/types.go +++ b/pkg/ddc/jindofsx/types.go @@ -22,37 +22,38 @@ import ( ) type Jindo struct { - FullnameOverride string `json:"fullnameOverride"` - Image string `json:"image"` - ImageTag string `json:"imageTag"` - ImagePullPolicy string `json:"imagePullPolicy"` - FuseImage string `json:"fuseImage"` - FuseImageTag string `json:"fuseImageTag"` - FuseImagePullPolicy string `json:"fuseImagePullPolicy"` - User int `json:"user"` - Group int `json:"group"` - UseHostNetwork bool `json:"useHostNetwork"` - Properties map[string]string `json:"properties"` - Master Master `json:"master"` - Worker Worker `json:"worker"` - Fuse Fuse `json:"fuse"` - Mounts Mounts `json:"mounts"` - HadoopConfig HadoopConfig `json:"hadoopConfig,omitempty"` - Secret string `json:"secret,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - InitPortCheck common.InitPortCheck `json:"initPortCheck,omitempty"` - LogConfig map[string]string `json:"logConfig,omitempty"` - FuseLogConfig map[string]string `json:"fuseLogConfig,omitempty"` - PlacementMode string `json:"placement,omitempty"` - Owner *common.OwnerReference `json:"owner,omitempty"` - RuntimeIdentity common.RuntimeIdentity `json:"runtimeIdentity"` - ClusterDomain string `json:"clusterDomain,omitempty"` - UFSVolumes []UFSVolume `json:"ufsVolumes,omitempty"` - SecretKey string `json:"secretKey,omitempty"` - SecretValue string `json:"secretValue,omitempty"` - UseStsToken bool `json:"UseStsToken"` - MountType string `json:"mountType,omitempty"` - ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + Image string `json:"image"` + ImageTag string `json:"imageTag"` + ImagePullPolicy string `json:"imagePullPolicy"` + FuseImage string `json:"fuseImage"` + FuseImageTag string `json:"fuseImageTag"` + FuseImagePullPolicy string `json:"fuseImagePullPolicy"` + User int `json:"user"` + Group int `json:"group"` + UseHostNetwork bool `json:"useHostNetwork"` + Properties map[string]string `json:"properties"` + Master Master `json:"master"` + Worker Worker `json:"worker"` + Fuse Fuse `json:"fuse"` + Mounts Mounts `json:"mounts"` + HadoopConfig HadoopConfig `json:"hadoopConfig,omitempty"` + Secret string `json:"secret,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + InitPortCheck common.InitPortCheck `json:"initPortCheck,omitempty"` + LogConfig map[string]string `json:"logConfig,omitempty"` + FuseLogConfig map[string]string `json:"fuseLogConfig,omitempty"` + PlacementMode string `json:"placement,omitempty"` + Owner *common.OwnerReference `json:"owner,omitempty"` + RuntimeIdentity common.RuntimeIdentity `json:"runtimeIdentity"` + ClusterDomain string `json:"clusterDomain,omitempty"` + UFSVolumes []UFSVolume `json:"ufsVolumes,omitempty"` + SecretKey string `json:"secretKey,omitempty"` + SecretValue string `json:"secretValue,omitempty"` + UseStsToken bool `json:"UseStsToken"` + MountType string `json:"mountType,omitempty"` + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } type HadoopConfig struct { diff --git a/pkg/ddc/juicefs/data_migrate.go b/pkg/ddc/juicefs/data_migrate.go index effebc1590a..4c0d78db387 100644 --- a/pkg/ddc/juicefs/data_migrate.go +++ b/pkg/ddc/juicefs/data_migrate.go @@ -174,6 +174,7 @@ func (j *JuiceFSEngine) generateDataMigrateValueFile(r cruntime.ReconcileRequest DataMigrateInfo: dataMigrateInfo, } dataMigrateValue.Owner = transformer.GenerateOwnerReferenceFromObject(dataMigrate) + dataMigrateValue.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", j.namespace, j.name) // 6. create the value file data, err := yaml.Marshal(dataMigrateValue) @@ -181,7 +182,6 @@ func (j *JuiceFSEngine) generateDataMigrateValueFile(r cruntime.ReconcileRequest return } j.Log.Info("dataMigrate value", "value", string(data)) - valueFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-%s-migrate-values.yaml", dataMigrate.Namespace, dataMigrate.Name)) if err != nil { return diff --git a/pkg/ddc/juicefs/deprecated_label.go b/pkg/ddc/juicefs/deprecated_label.go index c29b6979732..0f6d1e83dc4 100644 --- a/pkg/ddc/juicefs/deprecated_label.go +++ b/pkg/ddc/juicefs/deprecated_label.go @@ -17,14 +17,10 @@ limitations under the License. package juicefs import ( - "github.com/fluid-cloudnative/fluid/pkg/common/deprecated" + "github.com/fluid-cloudnative/fluid/pkg/utils" apierrs "k8s.io/apimachinery/pkg/api/errors" ) -func (j *JuiceFSEngine) getDeprecatedCommonLabelName() string { - return deprecated.LabelAnnotationStorageCapacityPrefix + j.namespace + "-" + j.name -} - func (j *JuiceFSEngine) HasDeprecatedCommonLabelName() (deprecated bool, err error) { // return deprecated.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name @@ -48,10 +44,12 @@ func (j *JuiceFSEngine) HasDeprecatedCommonLabelName() (deprecated bool, err err nodeSelectors := fuses.Spec.Template.Spec.NodeSelector j.Log.Info("The current node selectors for worker", "fuseName", fuseName, "nodeSelector", nodeSelectors) - if _, deprecated = nodeSelectors[j.getDeprecatedCommonLabelName()]; deprecated { - j.Log.Info("the deprecated node selector exists", "nodeselector", j.getDeprecatedCommonLabelName()) + deprecatedCommonLabelName := utils.GetCommonLabelName(true, j.namespace, j.name) + if _, deprecated = nodeSelectors[deprecatedCommonLabelName]; deprecated { + // + j.Log.Info("the deprecated node selector exists", "nodeselector", deprecatedCommonLabelName) } else { - j.Log.Info("The deprecated node selector doesn't exist", "nodeselector", j.getDeprecatedCommonLabelName()) + j.Log.Info("The deprecated node selector doesn't exist", "nodeselector", deprecatedCommonLabelName) } return diff --git a/pkg/ddc/juicefs/deprecated_label_test.go b/pkg/ddc/juicefs/deprecated_label_test.go index 077fcac2963..f533f773edc 100644 --- a/pkg/ddc/juicefs/deprecated_label_test.go +++ b/pkg/ddc/juicefs/deprecated_label_test.go @@ -17,6 +17,7 @@ limitations under the License. package juicefs import ( + "github.com/fluid-cloudnative/fluid/pkg/utils" "testing" "github.com/fluid-cloudnative/fluid/pkg/common" @@ -136,10 +137,8 @@ func TestJuiceFSEngine_getDeprecatedCommonLabelName(t *testing.T) { out: "data.fluid.io/storage-test-fluid", }, } - fakeClient := fake.NewFakeClientWithScheme(testScheme) for _, test := range testCases { - engine := getTestJuiceFSEngine(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) } diff --git a/pkg/ddc/juicefs/label.go b/pkg/ddc/juicefs/label.go deleted file mode 100644 index aae391cae60..00000000000 --- a/pkg/ddc/juicefs/label.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2021 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 juicefs - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (j *JuiceFSEngine) getCommonLabelName() string { - return common.LabelAnnotationStorageCapacityPrefix + j.namespace + "-" + j.name -} - -func (j *JuiceFSEngine) getFuseLabelName() string { - return common.LabelAnnotationFusePrefix + j.namespace + "-" + j.name -} diff --git a/pkg/ddc/juicefs/label_test.go b/pkg/ddc/juicefs/label_test.go deleted file mode 100644 index 40b2d2c03a4..00000000000 --- a/pkg/ddc/juicefs/label_test.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2021 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 juicefs - -import ( - "testing" -) - -func TestJuiceFSEngine_getCommonLabelName(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "fuse1", - namespace: "fluid", - out: "fluid.io/s-fluid-fuse1", - }, - { - name: "fuse2", - namespace: "fluid", - out: "fluid.io/s-fluid-fuse2", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &JuiceFSEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelName() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/juicefs/node_test.go b/pkg/ddc/juicefs/node_test.go index dc27d5102b4..62280923fb8 100644 --- a/pkg/ddc/juicefs/node_test.go +++ b/pkg/ddc/juicefs/node_test.go @@ -211,7 +211,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &corev1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelName())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/juicefs/transform.go b/pkg/ddc/juicefs/transform.go index 15776d5ca9e..47faef03603 100644 --- a/pkg/ddc/juicefs/transform.go +++ b/pkg/ddc/juicefs/transform.go @@ -52,6 +52,7 @@ func (j *JuiceFSEngine) transform(runtime *datav1alpha1.JuiceFSRuntime) (value * } value.FullnameOverride = j.name + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", j.namespace, j.name) value.Owner = transformer.GenerateOwnerReferenceFromObject(runtime) // transform toleration diff --git a/pkg/ddc/juicefs/transform_fuse.go b/pkg/ddc/juicefs/transform_fuse.go index a351672a4b2..6020a8582de 100644 --- a/pkg/ddc/juicefs/transform_fuse.go +++ b/pkg/ddc/juicefs/transform_fuse.go @@ -128,7 +128,7 @@ func (j *JuiceFSEngine) transformFuseNodeSelector(runtime *datav1alpha1.JuiceFSR } // The label will be added by CSI Plugin when any workload pod is scheduled on the node. - value.Fuse.NodeSelector[j.getFuseLabelName()] = "true" + value.Fuse.NodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" } // genValue: generate the value of juicefs diff --git a/pkg/ddc/juicefs/type.go b/pkg/ddc/juicefs/type.go index a4f87acf903..a08c3114611 100644 --- a/pkg/ddc/juicefs/type.go +++ b/pkg/ddc/juicefs/type.go @@ -25,9 +25,10 @@ import ( // JuiceFS The value json file type JuiceFS struct { - FullnameOverride string `json:"fullnameOverride"` - Edition string `json:"edition,omitempty"` - Source string `json:"source,omitempty"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + Edition string `json:"edition,omitempty"` + Source string `json:"source,omitempty"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/thin/label.go b/pkg/ddc/thin/label.go deleted file mode 100644 index a5612868769..00000000000 --- a/pkg/ddc/thin/label.go +++ /dev/null @@ -1,23 +0,0 @@ -/* - 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 thin - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (t *ThinEngine) getFuseLabelName() string { - return common.LabelAnnotationFusePrefix + t.namespace + "-" + t.name -} diff --git a/pkg/ddc/thin/label_test.go b/pkg/ddc/thin/label_test.go deleted file mode 100644 index 96d519e4a08..00000000000 --- a/pkg/ddc/thin/label_test.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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 thin - -import ( - "testing" -) - -func TestThinEngine_getFuseLabelName(t1 *testing.T) { - type fields struct { - name string - namespace string - } - tests := []struct { - name string - fields fields - want string - }{ - { - name: "fuse", - fields: fields{ - name: "fuse1", - namespace: "fluid", - }, - want: "fluid.io/f-fluid-fuse1", - }, - } - for _, tt := range tests { - t1.Run(tt.name, func(t1 *testing.T) { - t := &ThinEngine{ - name: tt.fields.name, - namespace: tt.fields.namespace, - } - out := t.getFuseLabelName() - if out != tt.want { - t1.Errorf("in: %s-%s, expect: %s, got: %s", t.namespace, t.name, tt.want, out) - } - }) - } -} diff --git a/pkg/ddc/thin/referencedataset/volume.go b/pkg/ddc/thin/referencedataset/volume.go index b5167561304..f5fd55b48c5 100644 --- a/pkg/ddc/thin/referencedataset/volume.go +++ b/pkg/ddc/thin/referencedataset/volume.go @@ -171,9 +171,9 @@ func createFusePersistentVolumeClaim(client client.Client, virtualRuntime base.R Namespace: virtualNamespace, Labels: map[string]string{ // see 'pkg/util/webhook/scheduler/mutating/schedule_pod_handler.go' 'CheckIfPVCIsDataset' function usage - common.LabelAnnotationStorageCapacityPrefix + virtualNamespace + "-" + virtualName: "true", - common.LabelAnnotationDatasetReferringName: runtimePVC.Name, - common.LabelAnnotationDatasetReferringNameSpace: runtimePVC.Namespace, + utils.TransferFullNamespacedNameWithPrefixToLegalValue(common.LabelAnnotationStorageCapacityPrefix, virtualNamespace, virtualName): "true", + common.LabelAnnotationDatasetReferringName: runtimePVC.Name, + common.LabelAnnotationDatasetReferringNameSpace: runtimePVC.Namespace, }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/ddc/thin/transform.go b/pkg/ddc/thin/transform.go index 46ff4cb8364..671b07db304 100644 --- a/pkg/ddc/thin/transform.go +++ b/pkg/ddc/thin/transform.go @@ -51,6 +51,7 @@ func (t *ThinEngine) transform(runtime *datav1alpha1.ThinRuntime, profile *datav } value.FullnameOverride = t.name + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", t.namespace, t.name) value.Owner = transformer.GenerateOwnerReferenceFromObject(runtime) toRuntimeSetConfig, err := t.toRuntimeSetConfig(nil, nil) if err != nil { diff --git a/pkg/ddc/thin/transform_fuse.go b/pkg/ddc/thin/transform_fuse.go index 1fda3b87aa9..3616e042dbf 100644 --- a/pkg/ddc/thin/transform_fuse.go +++ b/pkg/ddc/thin/transform_fuse.go @@ -56,7 +56,7 @@ func (t *ThinEngine) transformFuse(runtime *datav1alpha1.ThinRuntime, profile *d if len(runtime.Spec.Fuse.NodeSelector) > 0 { value.Fuse.NodeSelector = runtime.Spec.Fuse.NodeSelector } - value.Fuse.NodeSelector[t.getFuseLabelName()] = "true" + value.Fuse.NodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" // 5. ports if len(runtime.Spec.Fuse.Ports) != 0 { diff --git a/pkg/ddc/thin/type.go b/pkg/ddc/thin/type.go index c51497dfe7c..d2f6f662add 100644 --- a/pkg/ddc/thin/type.go +++ b/pkg/ddc/thin/type.go @@ -23,7 +23,8 @@ import ( ) type ThinValue struct { - FullnameOverride string `json:"fullnameOverride"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/vineyard/label.go b/pkg/ddc/vineyard/label.go deleted file mode 100644 index 79a11eec2ed..00000000000 --- a/pkg/ddc/vineyard/label.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2024 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 vineyard - -import "github.com/fluid-cloudnative/fluid/pkg/common" - -func (e *VineyardEngine) getCommonLabelName() string { - return common.LabelAnnotationStorageCapacityPrefix + e.namespace + "-" + e.name -} - -func (e *VineyardEngine) getFuseLabelName() string { - return common.LabelAnnotationFusePrefix + e.namespace + "-" + e.name -} diff --git a/pkg/ddc/vineyard/label_test.go b/pkg/ddc/vineyard/label_test.go deleted file mode 100644 index 3c3d0cdc8a6..00000000000 --- a/pkg/ddc/vineyard/label_test.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2024 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 vineyard - -import "testing" - -func TestGetCommonLabelname(t *testing.T) { - testCases := []struct { - name string - namespace string - out string - }{ - { - name: "hbase", - namespace: "fluid", - out: "fluid.io/s-fluid-hbase", - }, - { - name: "hadoop", - namespace: "fluid", - out: "fluid.io/s-fluid-hadoop", - }, - { - name: "common", - namespace: "default", - out: "fluid.io/s-default-common", - }, - } - for _, testCase := range testCases { - engine := &VineyardEngine{ - name: testCase.name, - namespace: testCase.namespace, - } - out := engine.getCommonLabelName() - if out != testCase.out { - t.Errorf("in: %s-%s, expect: %s, got: %s", testCase.namespace, testCase.name, testCase.out, out) - } - } -} diff --git a/pkg/ddc/vineyard/node_test.go b/pkg/ddc/vineyard/node_test.go index 3b9a35abc19..b3fbaac773c 100644 --- a/pkg/ddc/vineyard/node_test.go +++ b/pkg/ddc/vineyard/node_test.go @@ -337,7 +337,7 @@ func TestSyncScheduleInfoToCacheNodes(t *testing.T) { } nodeList := &v1.NodeList{} - datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.getCommonLabelName())) + datasetLabels, err := labels.Parse(fmt.Sprintf("%s=true", engine.runtimeInfo.GetCommonLabelName())) if err != nil { return } diff --git a/pkg/ddc/vineyard/transform.go b/pkg/ddc/vineyard/transform.go index 8bd5d5a45ad..3ed3db926d1 100644 --- a/pkg/ddc/vineyard/transform.go +++ b/pkg/ddc/vineyard/transform.go @@ -41,7 +41,7 @@ func (e *VineyardEngine) transform(runtime *datav1alpha1.VineyardRuntime) (value Owner: transformer.GenerateOwnerReferenceFromObject(runtime), } value.FullnameOverride = e.name - + value.FullNamespacedNameOverride = utils.TransferFullNamespacedNameWithPrefixToLegalValue("", e.namespace, e.name) value.TieredStore, err = e.transformTieredStore(runtime) if err != nil { return @@ -271,7 +271,7 @@ func (e *VineyardEngine) transformWorkerPorts(runtime *datav1alpha1.VineyardRunt func (e *VineyardEngine) transformFuseNodeSelector(runtime *datav1alpha1.VineyardRuntime) map[string]string { nodeSelector := map[string]string{} - nodeSelector[e.getFuseLabelName()] = "true" + nodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name)] = "true" return nodeSelector } diff --git a/pkg/ddc/vineyard/transform_test.go b/pkg/ddc/vineyard/transform_test.go index 2c066ffca11..d9ec7460109 100755 --- a/pkg/ddc/vineyard/transform_test.go +++ b/pkg/ddc/vineyard/transform_test.go @@ -14,6 +14,7 @@ limitations under the License. package vineyard import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "os" "reflect" "strings" @@ -604,6 +605,10 @@ func TestTransformFuseNodeSelector(t *testing.T) { { name: "NoWorkerPorts", runtime: &datav1alpha1.VineyardRuntime{ + ObjectMeta: metav1.ObjectMeta{ + Name: "vineyard", + Namespace: "fluid", + }, Spec: datav1alpha1.VineyardRuntimeSpec{ Worker: datav1alpha1.VineyardCompTemplateSpec{ NodeSelector: map[string]string{}, diff --git a/pkg/ddc/vineyard/type.go b/pkg/ddc/vineyard/type.go index f5f9ee18e40..bb4b73c8f71 100644 --- a/pkg/ddc/vineyard/type.go +++ b/pkg/ddc/vineyard/type.go @@ -23,7 +23,8 @@ import ( // The value yaml file type Vineyard struct { - FullnameOverride string `json:"fullnameOverride"` + FullnameOverride string `json:"fullnameOverride"` + FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/utils/excluisve.go b/pkg/utils/excluisve.go index d81d9d54153..7dfbb06ca6c 100644 --- a/pkg/utils/excluisve.go +++ b/pkg/utils/excluisve.go @@ -29,5 +29,12 @@ func GetExclusiveKey() string { // GetExclusiveValue gets exclusive value func GetExclusiveValue(namespace, name string) string { - return fmt.Sprintf("%s_%s", namespace, name) + exclusiveValue := fmt.Sprintf("%s_%s", namespace, name) + + // ensure forward compatibility + if len(exclusiveValue) <= 63 { + return exclusiveValue + } + + return TransferFullNamespacedNameWithPrefixToLegalValue("", namespace, name) } diff --git a/pkg/utils/hash.go b/pkg/utils/hash.go new file mode 100644 index 00000000000..16536837675 --- /dev/null +++ b/pkg/utils/hash.go @@ -0,0 +1,80 @@ +/* +Copyright 2023 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 utils + +import ( + "bytes" + "encoding/json" + "fmt" + "github.com/pkg/errors" + "hash/fnv" + "io" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/rand" + "strings" +) + +func ComputeHash(object interface{}) (string, error) { + objString, err := json.Marshal(object) + if err != nil { + return "", errors.Wrap(err, "failed to compute hash.") + } + + // hasher := sha1.New() + hasher := fnv.New32() + if _, err := io.Copy(hasher, bytes.NewReader(objString)); err != nil { + return "", errors.Wrapf(err, "failed to compute hash for sha256. [%s]", objString) + } + + sha := hasher.Sum32() + return rand.SafeEncodeString(fmt.Sprint(sha)), nil +} + +func ComputeFullNamespacedNameHashValue(namespace, name string) (string, error) { + return ComputeHash(v1.ObjectMeta{ + Namespace: namespace, + Name: name, + }) +} + +// TransferFullNamespacedNameWithPrefixToLegalValue Transfer a fully namespaced name with a prefix to a legal value which under max length limit. +// If the full namespaced name exceeds 63 characters, it calculates the hash value of the name and truncates the name and namespace, +// then appends the hash value to ensure the name's uniqueness and length constraint. +func TransferFullNamespacedNameWithPrefixToLegalValue(prefix, namespace, name string) (fullNamespacedName string) { + fullNamespacedName = fmt.Sprintf("%s%s-%s", prefix, namespace, name) + + // ensure forward compatibility + if len(fullNamespacedName) < 63 { + return + } + + namespacedNameHashValue, err := ComputeFullNamespacedNameHashValue(namespace, name) + if err != nil { + log.Error(err, "fail to compute hash value for namespacedName, and fall back to the original value which will cause the failure of resource creation.") + return + } + trimMetadata := func(s string) string { + s = strings.ReplaceAll(s, "-", "") + if len(s) <= 8 { + return s + } + return s[:8] + } + fullNamespacedName = fmt.Sprintf("%s%s-%s-%s", prefix, trimMetadata(namespace), trimMetadata(name), namespacedNameHashValue) + + return +} diff --git a/pkg/utils/hash_test.go b/pkg/utils/hash_test.go new file mode 100644 index 00000000000..6a85303e544 --- /dev/null +++ b/pkg/utils/hash_test.go @@ -0,0 +1,66 @@ +/* +Copyright 2023 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 utils + +import "testing" + +func TestComputeHash(t *testing.T) { + type args struct { + object interface{} + } + tests := []struct { + name string + args args + want string + wantErr bool + }{{ + "test1", + args{ + map[string]string{ + "abdc": "bcde", + }, + }, + "58c7f7c8b5", + false, + }, { + "empty_test", + args{ + map[string]string{}, + }, + "5894b84845", + false, + }, { + "nil_test", + args{ + nil, + }, + "cd856cb98", + false, + }} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ComputeHash(tt.args.object) + if (err != nil) != tt.wantErr { + t.Errorf("ComputeHash() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("ComputeHash() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/utils/kubeclient/volume.go b/pkg/utils/kubeclient/volume.go index f3c9b04e40b..cece944670b 100644 --- a/pkg/utils/kubeclient/volume.go +++ b/pkg/utils/kubeclient/volume.go @@ -355,7 +355,7 @@ func IsDatasetPVC(client client.Reader, name string, namespace string) (find boo if err != nil { return } - _, find = pvc.Labels[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+name] + _, find = pvc.Labels[utils.TransferFullNamespacedNameWithPrefixToLegalValue(common.LabelAnnotationStorageCapacityPrefix, namespace, name)] return } @@ -369,7 +369,7 @@ func CheckIfPVCIsDataset(pvc *corev1.PersistentVolumeClaim) (isDataset bool) { if len(namespace) == 0 { namespace = corev1.NamespaceDefault } - _, isDataset = pvc.Labels[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+name] + _, isDataset = pvc.Labels[utils.TransferFullNamespacedNameWithPrefixToLegalValue(common.LabelAnnotationStorageCapacityPrefix, namespace, name)] if _, exists := common.GetManagerDatasetFromLabels(pvc.Labels); exists { isDataset = true diff --git a/pkg/utils/label.go b/pkg/utils/label.go index 404dbb5ca52..b7919f5ae45 100644 --- a/pkg/utils/label.go +++ b/pkg/utils/label.go @@ -114,19 +114,15 @@ func ChangeNodeLabelWithPatchMode(cli client.Client, node *v1.Node, labelsToModi return PatchLabels(cli, node, labelsToModify) } -func GetStoragetLabelName(read common.ReadType, storage common.StorageType, isDeprecated bool, runtimeType string, namespace string, name string) string { +func GetStorageLabelName(read common.ReadType, storage common.StorageType, isDeprecated bool, runtimeType string, namespace string, name string) string { prefix := common.LabelAnnotationStorageCapacityPrefix if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return prefix + - string(read) + - runtimeType + - "-" + - string(storage) + - namespace + - "-" + - name + + prefix = prefix + string(read) + runtimeType + "-" + string(storage) + + return TransferFullNamespacedNameWithPrefixToLegalValue(prefix, namespace, name) } func GetLabelNameForMemory(isDeprecated bool, runtimeType string, namespace string, name string) string { @@ -136,7 +132,7 @@ func GetLabelNameForMemory(isDeprecated bool, runtimeType string, namespace stri read = deprecated.HumanReadType storage = deprecated.MemoryStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name) } func GetLabelNameForDisk(isDeprecated bool, runtimeType string, namespace string, name string) string { @@ -146,7 +142,7 @@ func GetLabelNameForDisk(isDeprecated bool, runtimeType string, namespace string read = deprecated.HumanReadType storage = deprecated.DiskStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name) } func GetLabelNameForTotal(isDeprecated bool, runtimeType string, namespace string, name string) string { @@ -156,7 +152,7 @@ func GetLabelNameForTotal(isDeprecated bool, runtimeType string, namespace strin read = deprecated.HumanReadType storage = deprecated.TotalStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name) } func GetCommonLabelName(isDeprecated bool, namespace string, name string) string { @@ -165,7 +161,7 @@ func GetCommonLabelName(isDeprecated bool, namespace string, name string) string prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return prefix + namespace + "-" + name + return TransferFullNamespacedNameWithPrefixToLegalValue(prefix, namespace, name) } func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace string, name string) string { @@ -173,5 +169,12 @@ func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace string if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return prefix + runtimeType + "-" + namespace + "-" + name + + prefix = prefix + runtimeType + "-" + + return TransferFullNamespacedNameWithPrefixToLegalValue(prefix, namespace, name) +} + +func GetFuseLabelName(namespace, name string) string { + return TransferFullNamespacedNameWithPrefixToLegalValue(common.LabelAnnotationFusePrefix, namespace, name) } diff --git a/pkg/utils/label_test.go b/pkg/utils/label_test.go index be498f65214..f104b597337 100644 --- a/pkg/utils/label_test.go +++ b/pkg/utils/label_test.go @@ -181,3 +181,21 @@ func TestChangeNodeLabelWithPatchModel(t *testing.T) { } } } + +func TestGetFullNamespacedNameWithPrefixValue(t *testing.T) { + tests := []struct { + prefix, namespace, name string + expected string + }{ + {"normal-", "default", "test-dataset", "normal-default-test-dataset"}, + {"overlimit-", "namespace-ajsdjikebnfacdsvwcaxqcackjascnbaksjcnakjscnackjasn", "dataset-demo", "overlimit-namespac-datasetd-58df5bd9cc"}, + {"overlimit-", "namespace-demo", "dataset-ajsdjikebnfacdsvwcaxqcackjascnbaksjcnakjscnackjasn", "overlimit-namespac-dataseta-6dfd85695"}, + } + + for _, test := range tests { + result := TransferFullNamespacedNameWithPrefixToLegalValue(test.prefix, test.namespace, test.name) + if result != test.expected { + t.Errorf("TransferFullNamespacedNameWithPrefixToLegalValue(%v) = %v, want %v", test, result, test.expected) + } + } +}