From 7e5401ad83d1728fa97ca005b72ad67aa0bed3a9 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 * Feature: add datasetIdLabel to all the resources created by fluid Signed-off-by: jiuyu --- charts/alluxio/templates/fuse/daemonset.yaml | 1 + .../alluxio/templates/master/statefulset.yaml | 1 + .../alluxio/templates/worker/statefulset.yaml | 5 +- charts/efc/templates/worker/statefulset.yaml | 5 +- .../alluxio/templates/cronjob.yaml | 1 + .../goosefs/templates/cronjob.yaml | 1 + .../jindo/templates/cronjob.yaml | 1 + .../jindocache/templates/cronjob.yaml | 1 + .../jindofsx/templates/cronjob.yaml | 1 + .../juicefs/templates/cronjob.yaml | 1 + .../juicefs/templates/cronjob.yaml | 1 + .../juicefs/templates/job.yaml | 2 +- .../juicefs/templates/statefulset.yaml | 2 +- .../templates/fuse/client-daemonset.yaml | 1 + charts/goosefs/templates/fuse/daemonset.yaml | 1 + .../goosefs/templates/master/statefulset.yaml | 1 + .../goosefs/templates/worker/statefulset.yaml | 5 +- .../jindocache/templates/fuse/daemonset.yaml | 1 + .../templates/master/statefulset.yaml | 1 + .../templates/worker/statefulset.yaml | 5 +- charts/jindofs/templates/fuse/daemonset.yaml | 1 + .../jindofs/templates/master/statefulset.yaml | 1 + .../jindofs/templates/worker/statefulset.yaml | 5 +- charts/jindofsx/templates/fuse/daemonset.yaml | 1 + .../templates/master/statefulset.yaml | 1 + .../templates/worker/statefulset.yaml | 5 +- charts/juicefs/templates/fuse/daemonset.yaml | 1 + .../juicefs/templates/worker/statefulset.yaml | 5 +- .../library/templates/_recommended_labels.tpl | 1 + charts/thin/templates/fuse/daemonset.yaml | 1 + .../thin/templates/worker/statefuleset.yaml | 5 +- charts/vineyard/templates/fuse/daemonset.yaml | 1 + .../templates/master/statefulset.yaml | 1 + .../templates/worker/statefulset.yaml | 9 +- pkg/application/inject/fuse/injector_test.go | 42 +++---- .../inject/fuse/mutator/mutator_default.go | 2 +- .../fuse/poststart/script_gen_helper.go | 6 + pkg/common/label.go | 8 ++ pkg/controllers/runtime_controller.go | 9 +- pkg/csi/plugins/nodeserver.go | 9 +- pkg/ctrl/fuse.go | 4 +- pkg/databackup/value.go | 21 ++-- pkg/dataload/value.go | 7 +- pkg/datamigrate/value.go | 1 + pkg/ddc/alluxio/backup_data.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/load_data.go | 7 +- pkg/ddc/alluxio/load_data_test.go | 12 +- pkg/ddc/alluxio/master_internal.go | 4 +- pkg/ddc/alluxio/master_internal_test.go | 18 ++- pkg/ddc/alluxio/node_test.go | 2 +- pkg/ddc/alluxio/runtime_info.go | 36 +++--- pkg/ddc/alluxio/shutdown.go | 2 +- pkg/ddc/alluxio/transform.go | 1 + pkg/ddc/alluxio/transform_fuse.go | 2 +- pkg/ddc/alluxio/transform_fuse_test.go | 42 +++++-- pkg/ddc/alluxio/transform_test.go | 22 +++- pkg/ddc/alluxio/types.go | 1 + pkg/ddc/base/label.go | 24 +++- pkg/ddc/base/label_test.go | 4 +- pkg/ddc/base/runtime.go | 37 +++++-- pkg/ddc/efc/create_volume.go | 3 +- pkg/ddc/efc/label.go | 23 ---- pkg/ddc/efc/label_test.go | 50 --------- pkg/ddc/efc/master_internal.go | 4 +- pkg/ddc/efc/master_internal_test.go | 47 +++++--- pkg/ddc/efc/metadata_test.go | 17 ++- pkg/ddc/efc/runtime_info.go | 4 + pkg/ddc/efc/shutdown.go | 2 +- pkg/ddc/efc/transform.go | 3 +- pkg/ddc/efc/transform_test.go | 25 +++-- pkg/ddc/efc/types.go | 1 + pkg/ddc/goosefs/deprecated_label.go | 13 +-- pkg/ddc/goosefs/deprecated_label_test.go | 5 +- pkg/ddc/goosefs/engine.go | 1 + pkg/ddc/goosefs/label.go | 27 ----- pkg/ddc/goosefs/label_test.go | 53 --------- pkg/ddc/goosefs/load_data.go | 7 +- pkg/ddc/goosefs/load_data_test.go | 12 +- pkg/ddc/goosefs/master_internal.go | 4 +- pkg/ddc/goosefs/master_internal_test.go | 33 +++--- pkg/ddc/goosefs/node_test.go | 2 +- pkg/ddc/goosefs/runtime_info.go | 35 +++--- pkg/ddc/goosefs/shutdown.go | 2 +- pkg/ddc/goosefs/transform.go | 1 + pkg/ddc/goosefs/transform_fuse.go | 3 +- pkg/ddc/goosefs/transform_fuse_test.go | 25 ++++- pkg/ddc/goosefs/transform_test.go | 13 ++- pkg/ddc/goosefs/types.go | 1 + 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/load_data.go | 7 +- pkg/ddc/jindo/load_data_test.go | 12 +- pkg/ddc/jindo/master_internal.go | 4 +- pkg/ddc/jindo/master_internal_test.go | 28 +++-- pkg/ddc/jindo/node_test.go | 2 +- pkg/ddc/jindo/runtime_info.go | 38 ++++--- pkg/ddc/jindo/shutdown.go | 2 +- pkg/ddc/jindo/transform.go | 5 +- pkg/ddc/jindo/types.go | 1 + pkg/ddc/jindo/worker.go | 2 +- pkg/ddc/jindo/worker_test.go | 11 +- 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/load_data.go | 7 +- pkg/ddc/jindocache/load_data_test.go | 12 +- pkg/ddc/jindocache/master_internal.go | 4 +- pkg/ddc/jindocache/master_internal_test.go | 28 +++-- pkg/ddc/jindocache/node_test.go | 2 +- pkg/ddc/jindocache/runtime_info.go | 35 +++--- pkg/ddc/jindocache/shutdown.go | 2 +- pkg/ddc/jindocache/transform.go | 5 +- pkg/ddc/jindocache/transform_test.go | 58 ++++++---- pkg/ddc/jindocache/types.go | 1 + 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/load_data.go | 7 +- pkg/ddc/jindofsx/load_data_test.go | 12 +- pkg/ddc/jindofsx/master_internal.go | 4 +- pkg/ddc/jindofsx/master_internal_test.go | 28 +++-- pkg/ddc/jindofsx/node_test.go | 2 +- pkg/ddc/jindofsx/runtime_info.go | 36 +++--- pkg/ddc/jindofsx/shutdown.go | 2 +- pkg/ddc/jindofsx/transform.go | 5 +- pkg/ddc/jindofsx/transform_test.go | 18 ++- pkg/ddc/jindofsx/types.go | 1 + pkg/ddc/juicefs/data_load.go | 7 +- pkg/ddc/juicefs/data_load_test.go | 12 +- pkg/ddc/juicefs/data_migrate.go | 2 +- pkg/ddc/juicefs/data_migrate_test.go | 14 ++- 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/master_internal.go | 4 +- pkg/ddc/juicefs/master_internal_test.go | 25 +++-- pkg/ddc/juicefs/node_test.go | 2 +- pkg/ddc/juicefs/runtime_info.go | 37 ++++--- pkg/ddc/juicefs/shutdown.go | 2 +- pkg/ddc/juicefs/transform.go | 1 + pkg/ddc/juicefs/transform_fuse.go | 2 +- pkg/ddc/juicefs/transform_fuse_test.go | 9 +- pkg/ddc/juicefs/transform_test.go | 11 +- pkg/ddc/juicefs/type.go | 1 + pkg/ddc/thin/label.go | 23 ---- pkg/ddc/thin/label_test.go | 54 --------- pkg/ddc/thin/master_internal.go | 4 +- pkg/ddc/thin/referencedataset/cm.go | 17 ++- pkg/ddc/thin/referencedataset/runtime.go | 4 + pkg/ddc/thin/referencedataset/volume.go | 8 +- pkg/ddc/thin/runtime_info.go | 4 + pkg/ddc/thin/shutdown.go | 2 +- pkg/ddc/thin/transform.go | 1 + pkg/ddc/thin/transform_fuse.go | 2 +- pkg/ddc/thin/transform_fuse_test.go | 28 ++++- pkg/ddc/thin/type.go | 1 + pkg/ddc/vineyard/label.go | 24 ---- pkg/ddc/vineyard/label_test.go | 50 --------- pkg/ddc/vineyard/master_internal.go | 4 +- pkg/ddc/vineyard/master_internal_test.go | 18 ++- pkg/ddc/vineyard/node_test.go | 2 +- pkg/ddc/vineyard/runtime_info.go | 18 ++- pkg/ddc/vineyard/shut_down.go | 2 +- pkg/ddc/vineyard/transform.go | 4 +- pkg/ddc/vineyard/transform_test.go | 22 +++- pkg/ddc/vineyard/type.go | 1 + pkg/utils/crtl_utils.go | 11 ++ pkg/utils/dataset/lifecycle/node.go | 4 +- pkg/utils/dataset/volume/create.go | 6 +- pkg/utils/dataset/volume/get.go | 4 +- pkg/utils/dataset_runtime.go | 3 + pkg/utils/excluisve.go | 33 ------ pkg/utils/excluisve_test.go | 78 ------------- pkg/utils/kubeclient/configmap.go | 11 +- pkg/utils/kubeclient/configmap_test.go | 2 +- pkg/utils/kubeclient/secret.go | 19 ++-- pkg/utils/kubeclient/volume.go | 28 ++--- pkg/utils/kubeclient/volume_claim.go | 2 +- pkg/utils/kubeclient/volume_test.go | 74 ------------- pkg/utils/label.go | 103 ++++++++++++++---- pkg/utils/label_test.go | 18 +++ 190 files changed, 1099 insertions(+), 1426 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 delete mode 100644 pkg/utils/excluisve.go delete mode 100644 pkg/utils/excluisve_test.go diff --git a/charts/alluxio/templates/fuse/daemonset.yaml b/charts/alluxio/templates/fuse/daemonset.yaml index affd0bb6436..1191461a6a1 100644 --- a/charts/alluxio/templates/fuse/daemonset.yaml +++ b/charts/alluxio/templates/fuse/daemonset.yaml @@ -59,6 +59,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: alluxio-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.fuse.labels }} {{- range $key, $val := .Values.fuse.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/alluxio/templates/master/statefulset.yaml b/charts/alluxio/templates/master/statefulset.yaml index afc8c9071e0..a8f6fc28b6e 100644 --- a/charts/alluxio/templates/master/statefulset.yaml +++ b/charts/alluxio/templates/master/statefulset.yaml @@ -67,6 +67,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: alluxio-master + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.master.labels }} {{- range $key, $val := .Values.master.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/alluxio/templates/worker/statefulset.yaml b/charts/alluxio/templates/worker/statefulset.yaml index 8aba50087cc..e3d6224147f 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -60,8 +60,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: alluxio-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/efc/templates/worker/statefulset.yaml b/charts/efc/templates/worker/statefulset.yaml index 1c964bdba00..9a9be4016f9 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -45,8 +45,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: efc-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-dataloader/alluxio/templates/cronjob.yaml b/charts/fluid-dataloader/alluxio/templates/cronjob.yaml index 57618a11953..2e9a2c337e1 100644 --- a/charts/fluid-dataloader/alluxio/templates/cronjob.yaml +++ b/charts/fluid-dataloader/alluxio/templates/cronjob.yaml @@ -55,6 +55,7 @@ spec: app: alluxio cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} {{- if .Values.dataloader.labels }} {{- range $key, $val := .Values.dataloader.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-dataloader/goosefs/templates/cronjob.yaml b/charts/fluid-dataloader/goosefs/templates/cronjob.yaml index d23959a0569..0fe4c456ac5 100644 --- a/charts/fluid-dataloader/goosefs/templates/cronjob.yaml +++ b/charts/fluid-dataloader/goosefs/templates/cronjob.yaml @@ -47,6 +47,7 @@ spec: app: goosefs cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} spec: {{- include "library.fluid.dataload.cronJobCommonTemplateSpec" . | nindent 10 }} containers: diff --git a/charts/fluid-dataloader/jindo/templates/cronjob.yaml b/charts/fluid-dataloader/jindo/templates/cronjob.yaml index 47255ec4d25..c70cb2c08c9 100644 --- a/charts/fluid-dataloader/jindo/templates/cronjob.yaml +++ b/charts/fluid-dataloader/jindo/templates/cronjob.yaml @@ -50,6 +50,7 @@ spec: app: jindofs cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} spec: {{- include "library.fluid.dataload.cronJobCommonTemplateSpec" . | nindent 10 }} containers: diff --git a/charts/fluid-dataloader/jindocache/templates/cronjob.yaml b/charts/fluid-dataloader/jindocache/templates/cronjob.yaml index 0d40402b6b7..51b921ea3e3 100644 --- a/charts/fluid-dataloader/jindocache/templates/cronjob.yaml +++ b/charts/fluid-dataloader/jindocache/templates/cronjob.yaml @@ -55,6 +55,7 @@ spec: app: jindocache cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} {{- if .Values.dataloader.labels }} {{- range $key, $val := .Values.dataloader.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-dataloader/jindofsx/templates/cronjob.yaml b/charts/fluid-dataloader/jindofsx/templates/cronjob.yaml index 1d2d6248aa8..8d325f44d44 100644 --- a/charts/fluid-dataloader/jindofsx/templates/cronjob.yaml +++ b/charts/fluid-dataloader/jindofsx/templates/cronjob.yaml @@ -55,6 +55,7 @@ spec: app: jondofsx cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} {{- if .Values.dataloader.labels }} {{- range $key, $val := .Values.dataloader.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-dataloader/juicefs/templates/cronjob.yaml b/charts/fluid-dataloader/juicefs/templates/cronjob.yaml index 90282ec4cc8..ebe13b38de1 100644 --- a/charts/fluid-dataloader/juicefs/templates/cronjob.yaml +++ b/charts/fluid-dataloader/juicefs/templates/cronjob.yaml @@ -55,6 +55,7 @@ spec: app: juicefs cronjob: {{ printf "%s-job" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.dataloader.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} {{- if .Values.dataloader.labels }} {{- range $key, $val := .Values.dataloader.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-datamigrate/juicefs/templates/cronjob.yaml b/charts/fluid-datamigrate/juicefs/templates/cronjob.yaml index a9673452e32..0bc0848a2c2 100644 --- a/charts/fluid-datamigrate/juicefs/templates/cronjob.yaml +++ b/charts/fluid-datamigrate/juicefs/templates/cronjob.yaml @@ -47,6 +47,7 @@ spec: app: juicefs cronjob: {{ printf "%s-migrate" .Release.Name }} targetDataset: {{ required "targetDataset should be set" .Values.datamigrate.targetDataset }} + {{- include "library.fluid.labels" . | nindent 12 }} {{- if .Values.datamigrate.labels }} {{- range $key, $val := .Values.datamigrate.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/fluid-datamigrate/juicefs/templates/job.yaml b/charts/fluid-datamigrate/juicefs/templates/job.yaml index 73f71244991..0b5a42288ee 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.ownerDatasetId }} {{- 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..cdcb70e792f 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.ownerDatasetId }} spec: containers: - name: worker diff --git a/charts/goosefs/templates/fuse/client-daemonset.yaml b/charts/goosefs/templates/fuse/client-daemonset.yaml index 53d242a60ab..18262d07512 100644 --- a/charts/goosefs/templates/fuse/client-daemonset.yaml +++ b/charts/goosefs/templates/fuse/client-daemonset.yaml @@ -26,6 +26,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-fuse-client + {{- include "library.fluid.labels" . | nindent 8 }} spec: tolerations: - operator: Exists diff --git a/charts/goosefs/templates/fuse/daemonset.yaml b/charts/goosefs/templates/fuse/daemonset.yaml index 0da2decb3f8..e479f4870b6 100644 --- a/charts/goosefs/templates/fuse/daemonset.yaml +++ b/charts/goosefs/templates/fuse/daemonset.yaml @@ -35,6 +35,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-fuse + {{- include "library.fluid.labels" . | nindent 8 }} spec: {{- if .Values.fuse.criticalPod }} priorityClassName: system-node-critical diff --git a/charts/goosefs/templates/master/statefulset.yaml b/charts/goosefs/templates/master/statefulset.yaml index 7026d0c9cbc..1f71aa1fe5e 100644 --- a/charts/goosefs/templates/master/statefulset.yaml +++ b/charts/goosefs/templates/master/statefulset.yaml @@ -44,6 +44,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-master + {{- include "library.fluid.labels" . | nindent 8 }} spec: enableServiceLinks: false hostNetwork: {{ $hostNetwork }} diff --git a/charts/goosefs/templates/worker/statefulset.yaml b/charts/goosefs/templates/worker/statefulset.yaml index 0ec566fed9d..7cf8a592eef 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} spec: @@ -37,8 +37,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: goosefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} spec: enableServiceLinks: false hostNetwork: {{ $hostNetwork }} diff --git a/charts/jindocache/templates/fuse/daemonset.yaml b/charts/jindocache/templates/fuse/daemonset.yaml index fc20a0818a3..63dea011b59 100755 --- a/charts/jindocache/templates/fuse/daemonset.yaml +++ b/charts/jindocache/templates/fuse/daemonset.yaml @@ -45,6 +45,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.fuse.labels }} {{- range $key, $val := .Values.fuse.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/jindocache/templates/master/statefulset.yaml b/charts/jindocache/templates/master/statefulset.yaml index 5ec924ffd98..b34040e3be5 100755 --- a/charts/jindocache/templates/master/statefulset.yaml +++ b/charts/jindocache/templates/master/statefulset.yaml @@ -48,6 +48,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-master + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.master.labels }} {{- range $key, $val := .Values.master.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/jindocache/templates/worker/statefulset.yaml b/charts/jindocache/templates/worker/statefulset.yaml index 7dff6313b15..43618ab13cb 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -49,8 +49,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/jindofs/templates/fuse/daemonset.yaml b/charts/jindofs/templates/fuse/daemonset.yaml index cb5beb68b5f..70540dcd13e 100755 --- a/charts/jindofs/templates/fuse/daemonset.yaml +++ b/charts/jindofs/templates/fuse/daemonset.yaml @@ -41,6 +41,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.labels }} {{ toYaml .Values.labels | trim | indent 8 }} {{- end }} diff --git a/charts/jindofs/templates/master/statefulset.yaml b/charts/jindofs/templates/master/statefulset.yaml index 1e861cea835..2aeafd12287 100755 --- a/charts/jindofs/templates/master/statefulset.yaml +++ b/charts/jindofs/templates/master/statefulset.yaml @@ -43,6 +43,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-master + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.labels }} {{ toYaml .Values.labels | trim | indent 8 }} {{- end }} diff --git a/charts/jindofs/templates/worker/statefulset.yaml b/charts/jindofs/templates/worker/statefulset.yaml index 28e48f5df5a..fa973181eb4 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -44,8 +44,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.labels }} {{ toYaml .Values.labels | trim | indent 8 }} {{- end }} diff --git a/charts/jindofsx/templates/fuse/daemonset.yaml b/charts/jindofsx/templates/fuse/daemonset.yaml index d2f99e1c513..21e7d462f94 100755 --- a/charts/jindofsx/templates/fuse/daemonset.yaml +++ b/charts/jindofsx/templates/fuse/daemonset.yaml @@ -45,6 +45,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.fuse.labels }} {{- range $key, $val := .Values.fuse.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/jindofsx/templates/master/statefulset.yaml b/charts/jindofsx/templates/master/statefulset.yaml index c9b577049ac..f73895c550e 100755 --- a/charts/jindofsx/templates/master/statefulset.yaml +++ b/charts/jindofsx/templates/master/statefulset.yaml @@ -48,6 +48,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-master + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.master.labels }} {{- range $key, $val := .Values.master.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/jindofsx/templates/worker/statefulset.yaml b/charts/jindofsx/templates/worker/statefulset.yaml index d4e2b503de0..dc781923860 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -49,8 +49,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: jindofs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/juicefs/templates/fuse/daemonset.yaml b/charts/juicefs/templates/fuse/daemonset.yaml index 3734ffb8281..a0df9712e96 100644 --- a/charts/juicefs/templates/fuse/daemonset.yaml +++ b/charts/juicefs/templates/fuse/daemonset.yaml @@ -45,6 +45,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: juicefs-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.fuse.labels }} {{- range $key, $val := .Values.fuse.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/juicefs/templates/worker/statefulset.yaml b/charts/juicefs/templates/worker/statefulset.yaml index 9eb09833ce7..f5c4301a73a 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -48,8 +48,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: juicefs-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote}}: {{ $val | quote }} diff --git a/charts/library/templates/_recommended_labels.tpl b/charts/library/templates/_recommended_labels.tpl index da374930aa9..c017f580ceb 100644 --- a/charts/library/templates/_recommended_labels.tpl +++ b/charts/library/templates/_recommended_labels.tpl @@ -8,4 +8,5 @@ app.kubernetes.io/name: {{ .Chart.Name }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} fluid.io/managed-by: fluid +fluid.io/dataset-id: {{ .Values.ownerDatasetId }} {{- end }} diff --git a/charts/thin/templates/fuse/daemonset.yaml b/charts/thin/templates/fuse/daemonset.yaml index fd9a5dfb4c1..625db9ebc15 100644 --- a/charts/thin/templates/fuse/daemonset.yaml +++ b/charts/thin/templates/fuse/daemonset.yaml @@ -38,6 +38,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: thin-fuse + {{- include "library.fluid.labels" . | nindent 8 }} spec: {{- if .Values.fuse.imagePullSecrets }} imagePullSecrets: diff --git a/charts/thin/templates/worker/statefuleset.yaml b/charts/thin/templates/worker/statefuleset.yaml index f3e28923fa1..45f0897e97d 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.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} {{- include "library.fluid.labels" . | nindent 4 }} ownerReferences: @@ -41,8 +41,9 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: thin-worker - fluid.io/dataset: {{ .Release.Namespace }}-{{ .Release.Name }} + fluid.io/dataset: {{ .Values.ownerDatasetId }} fluid.io/dataset-placement: {{ .Values.placement }} + {{- include "library.fluid.labels" . | nindent 8 }} spec: {{- if .Values.worker.imagePullSecrets }} imagePullSecrets: diff --git a/charts/vineyard/templates/fuse/daemonset.yaml b/charts/vineyard/templates/fuse/daemonset.yaml index f2b533b7e61..cc3bebbc8b1 100644 --- a/charts/vineyard/templates/fuse/daemonset.yaml +++ b/charts/vineyard/templates/fuse/daemonset.yaml @@ -57,6 +57,7 @@ spec: chart: {{ $chart }} release: {{ .Release.Name }} role: vineyard-fuse + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.fuse.labels }} {{- range $key, $val := .Values.fuse.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/vineyard/templates/master/statefulset.yaml b/charts/vineyard/templates/master/statefulset.yaml index 9e24bf99d07..52e6f76934d 100644 --- a/charts/vineyard/templates/master/statefulset.yaml +++ b/charts/vineyard/templates/master/statefulset.yaml @@ -66,6 +66,7 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: vineyard-master + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.master.labels }} {{- range $key, $val := .Values.master.labels }} {{ $key | quote }}: {{ $val | quote }} diff --git a/charts/vineyard/templates/worker/statefulset.yaml b/charts/vineyard/templates/worker/statefulset.yaml index 7feada86bf5..83e4a645927 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.ownerDatasetId }} {{- include "library.fluid.labels" . | nindent 4 }} {{- if .Values.owner.enabled }} ownerReferences: @@ -46,7 +46,6 @@ spec: chart: {{ $chart }} release: {{ .Release.Name }} role: vineyard-worker - app.kubernetes.io/instance: {{ .Release.Namespace }}-{{ $fullName }}-worker template: metadata: annotations: @@ -62,8 +61,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.ownerDatasetId }} + {{- include "library.fluid.labels" . | nindent 8 }} {{- if .Values.worker.labels }} {{- range $key, $val := .Values.worker.labels }} {{ $key | quote }}: {{ $val | quote }} @@ -215,5 +214,5 @@ spec: - key: app.kubernetes.io/instance operator: In values: - - {{ .Release.Namespace }}-{{ $fullName }}-worker + - {{ .Values.ownerDatasetId }}-worker topologyKey: "kubernetes.io/hostname" diff --git a/pkg/application/inject/fuse/injector_test.go b/pkg/application/inject/fuse/injector_test.go index 2cceca9865b..8cf0b8a4f21 100644 --- a/pkg/application/inject/fuse/injector_test.go +++ b/pkg/application/inject/fuse/injector_test.go @@ -205,7 +205,7 @@ func TestInjectPod(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate"), }, }, Spec: corev1.PodSpec{ @@ -472,7 +472,7 @@ func TestInjectPod(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset1"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset1"), }, }, Spec: corev1.PodSpec{ @@ -742,7 +742,7 @@ func TestInjectPod(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "customizedenv"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "customizedenv"), }, }, Spec: corev1.PodSpec{ @@ -1015,7 +1015,7 @@ func TestInjectPod(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset-conflict"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset-conflict"), }, }, Spec: corev1.PodSpec{ @@ -1723,7 +1723,7 @@ func TestInjectPodWithMultiplePVC(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate"), }, }, Spec: corev1.PodSpec{ @@ -2126,8 +2126,8 @@ func TestInjectPodWithMultiplePVC(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset1"), - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s_%s", "big-data", "dataset2"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset1"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s-%s", "big-data", "dataset2"), }, }, Spec: corev1.PodSpec{ @@ -2696,7 +2696,7 @@ func TestInjectPodWithDatasetSubPath(t *testing.T) { Namespace: "ref", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "ref", "subpath"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "ref", "subpath"), }, }, Spec: corev1.PodSpec{ @@ -3087,7 +3087,7 @@ func TestInjectPodUnprivileged(t *testing.T) { Labels: map[string]string{ common.InjectFuseSidecar: common.True, common.InjectUnprivilegedFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset"), }, }, Spec: corev1.PodSpec{ @@ -3459,8 +3459,8 @@ func TestInjectPodUnprivileged(t *testing.T) { Labels: map[string]string{ common.InjectFuseSidecar: common.True, common.InjectUnprivilegedFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset1"), - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s_%s", "big-data", "dataset2"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset1"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s-%s", "big-data", "dataset2"), }, }, Spec: corev1.PodSpec{ @@ -3904,8 +3904,8 @@ func TestInjectPodUnprivileged(t *testing.T) { common.InjectFuseSidecar: common.True, common.InjectUnprivilegedFuseSidecar: common.True, common.InjectAppPostStart: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset-a"), - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s_%s", "big-data", "dataset-b"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset-a"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-1"): fmt.Sprintf("%s-%s", "big-data", "dataset-b"), }, }, Spec: corev1.PodSpec{ @@ -4424,7 +4424,7 @@ func TestInjectPodWithInitContainer(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate"), }, }, Spec: corev1.PodSpec{ @@ -4691,8 +4691,8 @@ func TestInjectPodWithInitContainer(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset1"), - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "dataset1"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset1"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "dataset1"), }, }, Spec: corev1.PodSpec{ @@ -5021,8 +5021,8 @@ func TestInjectPodWithInitContainer(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "customizedenv"), - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "customizedenv"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "customizedenv"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "init-fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "customizedenv"), }, }, Spec: corev1.PodSpec{ @@ -5505,7 +5505,7 @@ func TestInjectPodWithEnabledFUSEMetrics(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate"), }, Annotations: map[string]string{ common.AnnotationPrometheusFuseMetricsScrapeKey: common.True, @@ -5782,7 +5782,7 @@ func TestInjectPodWithEnabledFUSEMetrics(t *testing.T) { Namespace: "big-data", Labels: map[string]string{ common.InjectFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate2"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate2"), }, }, Spec: corev1.PodSpec{ @@ -6057,7 +6057,7 @@ func TestInjectPodWithEnabledFUSEMetrics(t *testing.T) { Labels: map[string]string{ common.InjectFuseSidecar: common.True, common.InjectUnprivilegedFuseSidecar: common.True, - fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s_%s", "big-data", "duplicate3"), + fmt.Sprintf("%s%s", common.LabelContainerDatasetMappingKeyPrefix, "fluid-fuse-0"): fmt.Sprintf("%s-%s", "big-data", "duplicate3"), }, Annotations: map[string]string{ common.AnnotationPrometheusFuseMetricsScrapeKey: common.True, diff --git a/pkg/application/inject/fuse/mutator/mutator_default.go b/pkg/application/inject/fuse/mutator/mutator_default.go index 26ecf941a75..b8a918909de 100644 --- a/pkg/application/inject/fuse/mutator/mutator_default.go +++ b/pkg/application/inject/fuse/mutator/mutator_default.go @@ -312,7 +312,7 @@ func (helper *defaultMutatorHelper) prependFuseContainer(asInit bool) error { helper.Specs.MetaObj.Labels = map[string]string{} } containerDatasetMappingLabelKey := common.LabelContainerDatasetMappingKeyPrefix + fuseContainer.Name - helper.Specs.MetaObj.Labels[containerDatasetMappingLabelKey] = fmt.Sprintf("%s_%s", helper.runtimeInfo.GetNamespace(), helper.runtimeInfo.GetName()) + helper.Specs.MetaObj.Labels[containerDatasetMappingLabelKey] = utils.GetDatasetId(helper.runtimeInfo.GetNamespace(), helper.runtimeInfo.GetName(), helper.runtimeInfo.GetOwnerDatasetUID()) return nil } diff --git a/pkg/application/inject/fuse/poststart/script_gen_helper.go b/pkg/application/inject/fuse/poststart/script_gen_helper.go index ffc09fde772..6bdd976f05c 100644 --- a/pkg/application/inject/fuse/poststart/script_gen_helper.go +++ b/pkg/application/inject/fuse/poststart/script_gen_helper.go @@ -23,6 +23,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" + + "github.com/fluid-cloudnative/fluid/pkg/common" + "github.com/fluid-cloudnative/fluid/pkg/utils" ) type scriptGeneratorHelper struct { @@ -41,6 +44,9 @@ func (helper *scriptGeneratorHelper) BuildConfigMap(ownerReference metav1.OwnerR Name: configMapKey.Name, Namespace: configMapKey.Namespace, OwnerReferences: []metav1.OwnerReference{ownerReference}, + Labels: map[string]string{ + common.LabelAnnotationDatasetId: utils.GetDatasetId(configMapKey.Namespace, ownerReference.Name, string(ownerReference.UID)), + }, }, Data: data, } diff --git a/pkg/common/label.go b/pkg/common/label.go index 7d2b86f2c1b..a7708b53e12 100644 --- a/pkg/common/label.go +++ b/pkg/common/label.go @@ -34,6 +34,10 @@ const ( // i.e. fluid.io/dataset LabelAnnotationDataset = LabelAnnotationPrefix + "dataset" + // LabelAnnotationDatasetId indicates the uuid of the dataset + // i.e. fluid.io/dataset-uuid + LabelAnnotationDatasetId = LabelAnnotationDataset + "-id" + // LabelAnnotationDatasetNum indicates the number of the dataset in specific node // i.e. fluid.io/dataset-num LabelAnnotationDatasetNum = LabelAnnotationPrefix + "dataset-num" @@ -46,6 +50,10 @@ const ( // i.e. fluid.io/managed-by LabelAnnotationManagedBy = LabelAnnotationPrefix + "managed-by" + // LabelAnnotationCopyFrom indicates a resource that is copied from another resource + // i.e. fluid.io/copied-from + LabelAnnotationCopyFrom = LabelAnnotationPrefix + "copied-from" + // fluid adminssion webhook inject flag // i.e. fluid.io/enable-injection EnableFluidInjectionFlag = LabelAnnotationPrefix + "enable-injection" diff --git a/pkg/controllers/runtime_controller.go b/pkg/controllers/runtime_controller.go index b410ec73816..d14f7b109c6 100644 --- a/pkg/controllers/runtime_controller.go +++ b/pkg/controllers/runtime_controller.go @@ -139,6 +139,13 @@ func (r *RuntimeReconciler) ReconcileInternal(ctx cruntime.ReconcileRequestConte if !utils.ContainsOwners(objectMeta.GetOwnerReferences(), dataset) { return r.AddOwnerAndRequeue(ctx, dataset) } + + if errs := utils.PatchLabelToObjects(ctx.Client, common.LabelAnnotationDatasetId, + utils.GetDatasetId(dataset.GetNamespace(), dataset.GetName(), string(dataset.UID)), + dataset, runtime); len(errs) > 0 { + return utils.RequeueAfterInterval(time.Duration(5 * time.Second)) + } + if !dataset.CanbeBound(ctx.Name, ctx.Namespace, ctx.Category) { ctx.Log.Info("the dataset can't be bound to the runtime, because it's already bound to another runtime ", "dataset", dataset.Name) @@ -187,7 +194,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..1dce0e7cc38 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, runtimeInfo.GetOwnerDatasetUID()) var labelsToModify common.LabelsToModify labelsToModify.Delete(fuseLabelKey) @@ -401,7 +400,11 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol } // 4. Label node to launch FUSE Pod - fuseLabelKey := common.LabelAnnotationFusePrefix + namespace + "-" + name + runtimeInfo, err := base.GetRuntimeInfo(ns.client, name, namespace) + if err != nil { + return nil, errors.Wrapf(err, "NodeStageVolume: failed to get runtime info for %s/%s", namespace, name) + } + fuseLabelKey := utils.GetFuseLabelName(namespace, name, runtimeInfo.GetOwnerDatasetUID()) var labelsToModify common.LabelsToModify labelsToModify.Add(fuseLabelKey, "true") diff --git a/pkg/ctrl/fuse.go b/pkg/ctrl/fuse.go index 1f8e5d95ade..9ff658535e2 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(), e.runtimeInfo.GetOwnerDatasetUID()) ) 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(), e.runtimeInfo.GetOwnerDatasetUID()) ) labelNames := []string{fuseLabelKey} diff --git a/pkg/databackup/value.go b/pkg/databackup/value.go index c007da755b0..3a5fc9b9651 100644 --- a/pkg/databackup/value.go +++ b/pkg/databackup/value.go @@ -31,16 +31,17 @@ type DataBackupValue struct { // DataBackup defines values used in DataBackup helm chart type DataBackup struct { - Namespace string `yaml:"namespace,omitempty"` - Dataset string `yaml:"dataset,omitempty"` - Name string `yaml:"name,omitempty"` - NodeName string `yaml:"nodeName,omitempty"` - Image string `yaml:"image,omitempty"` - JavaEnv string `yaml:"javaEnv,omitempty"` - Workdir string `yaml:"workdir,omitempty"` - PVCName string `yaml:"pvcName,omitempty"` - Path string `yaml:"path,omitempty"` - RuntimeType string `yaml:"runtimeType,omitempty"` + Namespace string `yaml:"namespace,omitempty"` + Dataset string `yaml:"dataset,omitempty"` + OwnerDatasetId string `yaml:"ownerDatasetId,omitempty"` + Name string `yaml:"name,omitempty"` + NodeName string `yaml:"nodeName,omitempty"` + Image string `yaml:"image,omitempty"` + JavaEnv string `yaml:"javaEnv,omitempty"` + Workdir string `yaml:"workdir,omitempty"` + PVCName string `yaml:"pvcName,omitempty"` + Path string `yaml:"path,omitempty"` + RuntimeType string `yaml:"runtimeType,omitempty"` // image pull secrets ImagePullSecrets []corev1.LocalObjectReference `yaml:"imagePullSecrets,omitempty"` Affinity *corev1.Affinity `yaml:"affinity,omitempty"` diff --git a/pkg/dataload/value.go b/pkg/dataload/value.go index 295b20c09c8..452956a5dbd 100644 --- a/pkg/dataload/value.go +++ b/pkg/dataload/value.go @@ -23,9 +23,10 @@ import ( // DataLoadValue defines the value yaml file used in DataLoad helm chart type DataLoadValue struct { - Name string `json:"name"` - Owner *common.OwnerReference `json:"owner,omitempty"` - DataLoadInfo DataLoadInfo `json:"dataloader"` + Name string `json:"name"` + OwnerDatasetId string `json:"ownerDatasetId"` + Owner *common.OwnerReference `json:"owner,omitempty"` + DataLoadInfo DataLoadInfo `json:"dataloader"` } // DataLoadInfo defines values used in DataLoad helm chart diff --git a/pkg/datamigrate/value.go b/pkg/datamigrate/value.go index f91ff523463..d7c745d469c 100644 --- a/pkg/datamigrate/value.go +++ b/pkg/datamigrate/value.go @@ -25,6 +25,7 @@ import ( type DataMigrateValue struct { Name string `json:"name"` + OwnerDatasetId string `json:"ownerDatasetId"` Owner *common.OwnerReference `json:"owner,omitempty"` DataMigrateInfo DataMigrateInfo `json:"datamigrate"` } diff --git a/pkg/ddc/alluxio/backup_data.go b/pkg/ddc/alluxio/backup_data.go index 8e2f660ee90..ce198fb1718 100644 --- a/pkg/ddc/alluxio/backup_data.go +++ b/pkg/ddc/alluxio/backup_data.go @@ -126,6 +126,13 @@ func (e *AlluxioEngine) generateDataBackupValueFile(ctx cruntime.ReconcileReques RuntimeType: common.AlluxioRuntime, ImagePullSecrets: imagePullSecrets, } + + dataset, err := utils.GetDataset(e.Client, dataBackup.Dataset, dataBackup.Namespace) + if err != nil { + return + } + dataBackup.OwnerDatasetId = utils.GetDatasetId(dataset.Namespace, dataset.Name, string(dataset.UID)) + pvcName, path, err := utils.ParseBackupRestorePath(databackup.Spec.BackupPath) if err != nil { return diff --git a/pkg/ddc/alluxio/deprecated_label.go b/pkg/ddc/alluxio/deprecated_label.go index a4beeeea2f9..c455c4dfbee 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, e.runtimeInfo.GetOwnerDatasetUID()) + 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..9ea840056d0 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/load_data.go b/pkg/ddc/alluxio/load_data.go index dd2a7e81fba..93cd24ab4ce 100644 --- a/pkg/ddc/alluxio/load_data.go +++ b/pkg/ddc/alluxio/load_data.go @@ -162,9 +162,10 @@ func (e *AlluxioEngine) genDataLoadValue(image string, targetDataset *datav1alph } dataloadInfo.TargetPaths = targetPaths dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil diff --git a/pkg/ddc/alluxio/load_data_test.go b/pkg/ddc/alluxio/load_data_test.go index abd443b064c..d95ab8b558b 100644 --- a/pkg/ddc/alluxio/load_data_test.go +++ b/pkg/ddc/alluxio/load_data_test.go @@ -152,7 +152,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -248,7 +249,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -347,7 +349,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -417,7 +420,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/alluxio/master_internal.go b/pkg/ddc/alluxio/master_internal.go index f60e8dea4ac..913e4e4e18e 100644 --- a/pkg/ddc/alluxio/master_internal.go +++ b/pkg/ddc/alluxio/master_internal.go @@ -99,7 +99,9 @@ func (e *AlluxioEngine) generateAlluxioValueFile(runtime *datav1alpha1.AlluxioRu } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/alluxio/master_internal_test.go b/pkg/ddc/alluxio/master_internal_test.go index f4a14ca4531..17071815594 100644 --- a/pkg/ddc/alluxio/master_internal_test.go +++ b/pkg/ddc/alluxio/master_internal_test.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/util/net" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" @@ -85,6 +86,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := AlluxioEngine{ name: "hbase", namespace: "fluid", @@ -100,8 +106,10 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -195,6 +203,11 @@ func TestGenerateAlluxioValueFile(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := AlluxioEngine{ name: "hbase", namespace: "fluid", @@ -210,9 +223,10 @@ func TestGenerateAlluxioValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } 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/runtime_info.go b/pkg/ddc/alluxio/runtime_info.go index 32dbd55e7ba..b970a6e608d 100644 --- a/pkg/ddc/alluxio/runtime_info.go +++ b/pkg/ddc/alluxio/runtime_info.go @@ -43,6 +43,26 @@ func (e *AlluxioEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) if !e.UnitTest { + // Setup with Dataset Info + dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) + return e.runtimeInfo, nil + } + + e.Log.Info("Failed to get dataset when getRuntimeInfo") + return e.runtimeInfo, err + } + + e.runtimeInfo.SetupWithDataset(dataset) + e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) + + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) + // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() if err != nil { @@ -58,22 +78,6 @@ func (e *AlluxioEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetDeprecatedPVName(isPVNameDeprecated) e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) - - // Setup with Dataset Info - dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) - if err != nil { - if utils.IgnoreNotFound(err) == nil { - e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) - return e.runtimeInfo, nil - } - - e.Log.Info("Failed to get dataset when getRuntimeInfo") - return e.runtimeInfo, err - } - - e.runtimeInfo.SetupWithDataset(dataset) - - e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } } diff --git a/pkg/ddc/alluxio/shutdown.go b/pkg/ddc/alluxio/shutdown.go index 43e04950530..faabecf85dc 100644 --- a/pkg/ddc/alluxio/shutdown.go +++ b/pkg/ddc/alluxio/shutdown.go @@ -292,7 +292,7 @@ func (e *AlluxioEngine) destroyWorkers(expectedWorkers int32) (currentWorkers in labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/alluxio/transform.go b/pkg/ddc/alluxio/transform.go index 78b48d890d6..52b48228990 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) // 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..7d6c5bc3b13 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" // parse fuse container network mode value.Fuse.HostNetwork = datav1alpha1.IsHostNetwork(runtime.Spec.Fuse.NetworkMode) diff --git a/pkg/ddc/alluxio/transform_fuse_test.go b/pkg/ddc/alluxio/transform_fuse_test.go index 0fbf61516e5..0c7358818a4 100644 --- a/pkg/ddc/alluxio/transform_fuse_test.go +++ b/pkg/ddc/alluxio/transform_fuse_test.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" ) @@ -62,11 +63,18 @@ func TestTransformFuseWithNoArgs(t *testing.T) { }}, &Alluxio{}, []string{"fuse", "--fuse-opts=kernel_cache,rw,allow_other", "/alluxio/default/test/alluxio-fuse", "/"}, false}, } for _, test := range tests { + runtimeInfo, err := base.BuildRuntimeInfo("test", "default", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := &AlluxioEngine{ - name: "test", - namespace: "default", - Log: fake.NullLogger()} - err := engine.transformFuse(test.runtime, test.dataset, test.alluxioValue) + name: "test", + namespace: "default", + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } + err = engine.transformFuse(test.runtime, test.dataset, test.alluxioValue) if err != nil { t.Errorf("Got err %v", err) } @@ -153,11 +161,18 @@ func TestTransformFuseWithArgs(t *testing.T) { }}, &Alluxio{}, []string{"fuse", "--fuse-opts=kernel_cache,allow_other", "/alluxio/default/test/alluxio-fuse", "/"}, false}, } for _, test := range tests { + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := &AlluxioEngine{ - name: "test", - namespace: "default", - Log: fake.NullLogger()} - err := engine.transformFuse(test.runtime, test.dataset, test.alluxioValue) + name: "test", + namespace: "default", + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } + err = engine.transformFuse(test.runtime, test.dataset, test.alluxioValue) if err != nil { t.Errorf("Got err %v", err) } @@ -230,7 +245,16 @@ func TestTransformFuseWithNetwork(t *testing.T) { }, } - engine := &AlluxioEngine{Log: fake.NullLogger()} + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + + engine := &AlluxioEngine{ + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } ds := &datav1alpha1.Dataset{} for k, v := range testCases { gotValue := &Alluxio{} diff --git a/pkg/ddc/alluxio/transform_test.go b/pkg/ddc/alluxio/transform_test.go index 1639c59793b..cea65454e5b 100755 --- a/pkg/ddc/alluxio/transform_test.go +++ b/pkg/ddc/alluxio/transform_test.go @@ -75,9 +75,16 @@ func TestTransformFuse(t *testing.T) { }, &Alluxio{}, []string{"fuse", "--fuse-opts=kernel_cache,rw,uid=1000,gid=1000,allow_other"}}, } for _, test := range tests { - engine := &AlluxioEngine{} + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &AlluxioEngine{ + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } engine.Log = ctrl.Log - err := engine.transformFuse(test.runtime, test.dataset, test.value) + err = engine.transformFuse(test.runtime, test.dataset, test.value) if err != nil { t.Errorf("error %v", err) } @@ -1012,7 +1019,16 @@ func TestTransformWorkerProperties(t *testing.T) { } func TestTransformFuseProperties(t *testing.T) { - engine := &AlluxioEngine{Log: fake.NullLogger()} + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + + engine := &AlluxioEngine{ + Log: fake.NullLogger(), + Client: fake.NewFakeClientWithScheme(testScheme), + runtimeInfo: runtimeInfo, + } var x int64 = 1000 ctrl.SetLogger(zap.New(func(o *zap.Options) { o.Development = true diff --git a/pkg/ddc/alluxio/types.go b/pkg/ddc/alluxio/types.go index 5a9de0a341a..88117adb621 100644 --- a/pkg/ddc/alluxio/types.go +++ b/pkg/ddc/alluxio/types.go @@ -28,6 +28,7 @@ import ( // The value yaml file type Alluxio struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/base/label.go b/pkg/ddc/base/label.go index 6a7c67a1a1a..c1878926905 100644 --- a/pkg/ddc/base/label.go +++ b/pkg/ddc/base/label.go @@ -17,28 +17,30 @@ limitations under the Licensinfo. package base import ( + "fmt" "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/utils" + "k8s.io/apimachinery/pkg/util/validation" ) func (info *RuntimeInfo) GetLabelNameForMemory() string { - return utils.GetLabelNameForMemory(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name) + return utils.GetLabelNameForMemory(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name, info.ownerDatasetUID) } func (info *RuntimeInfo) GetLabelNameForDisk() string { - return utils.GetLabelNameForDisk(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name) + return utils.GetLabelNameForDisk(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name, info.ownerDatasetUID) } func (info *RuntimeInfo) GetLabelNameForTotal() string { - return utils.GetLabelNameForTotal(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name) + return utils.GetLabelNameForTotal(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name, info.ownerDatasetUID) } func (info *RuntimeInfo) GetCommonLabelName() string { - return utils.GetCommonLabelName(info.IsDeprecatedNodeLabel(), info.namespace, info.name) + return utils.GetCommonLabelName(info.IsDeprecatedNodeLabel(), info.namespace, info.name, info.ownerDatasetUID) } func (info *RuntimeInfo) GetRuntimeLabelName() string { - return utils.GetRuntimeLabelName(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name) + return utils.GetRuntimeLabelName(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name, info.ownerDatasetUID) } // GetDatasetNumLabelname get the label to record how much datasets on a node @@ -48,5 +50,15 @@ 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.GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, info.namespace, info.name, info.ownerDatasetUID) +} + +func (info *RuntimeInfo) GetExclusiveLabelValue() string { + // ensure forward compatibility + exclusiveLabelValue := fmt.Sprintf("%s_%s", info.namespace, info.name) + if len(exclusiveLabelValue) < validation.DNS1035LabelMaxLength { + return exclusiveLabelValue + } + + return utils.GetNamespacedNameValueWithPrefix("", info.namespace, info.name, info.ownerDatasetUID) } diff --git a/pkg/ddc/base/label_test.go b/pkg/ddc/base/label_test.go index 3a2111212cd..21c2dc4e070 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/base/runtime.go b/pkg/ddc/base/runtime.go index b675e828dc7..b2ffce867b6 100644 --- a/pkg/ddc/base/runtime.go +++ b/pkg/ddc/base/runtime.go @@ -21,15 +21,15 @@ import ( "fmt" "strings" + datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/utils" "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - "github.com/fluid-cloudnative/fluid/pkg/common" - "k8s.io/apimachinery/pkg/api/resource" ) // Conventions defines naming convention for all runtime. @@ -53,6 +53,8 @@ type Conventions interface { GetDatasetNumLabelName() string GetWorkerStatefulsetName() string + + GetExclusiveLabelValue() string } // Runtime Information interface defines the interfaces that should be implemented @@ -67,6 +69,8 @@ type RuntimeInfoInterface interface { GetNamespace() string + GetOwnerDatasetUID() string + GetRuntimeType() string IsExclusive() bool @@ -77,6 +81,8 @@ type RuntimeInfoInterface interface { SetupWithDataset(dataset *datav1alpha1.Dataset) + SetOwnerDatasetUID(alias types.UID) + GetFuseNodeSelector() (nodeSelector map[string]string) GetFuseCleanPolicy() datav1alpha1.FuseCleanPolicy @@ -104,9 +110,13 @@ var _ RuntimeInfoInterface = &RuntimeInfo{} // The real Runtime Info should implement type RuntimeInfo struct { - name string - namespace string - runtimeType string + name string + namespace string + // Use owner dataset's UID as ownerDatasetUID, + // ownerDatasetUID is used to identify the owner dataset of the runtime + // when the namespacedName of dataset is over length limit. + ownerDatasetUID string + runtimeType string //tieredstore datav1alpha1.TieredStore tieredstoreInfo TieredStoreInfo @@ -272,6 +282,10 @@ func (info *RuntimeInfo) GetNamespace() string { return info.namespace } +func (info *RuntimeInfo) GetOwnerDatasetUID() string { + return info.ownerDatasetUID +} + // GetRuntimeType gets runtime type func (info *RuntimeInfo) GetRuntimeType() string { return info.runtimeType @@ -287,6 +301,14 @@ func (info *RuntimeInfo) SetupWithDataset(dataset *datav1alpha1.Dataset) { info.exclusive = dataset.IsExclusiveMode() } +// SetupWithDataset determines if need to setup with the info of dataset +func (info *RuntimeInfo) SetOwnerDatasetUID(datasetUID types.UID) { + if datasetUID == "" { + return + } + info.ownerDatasetUID = string(datasetUID) +} + // SetFuseNodeSelector setups the fuse deploy mode func (info *RuntimeInfo) SetFuseNodeSelector(nodeSelector map[string]string) { info.fuse.NodeSelector = nodeSelector @@ -525,6 +547,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R if runtimeInfo != nil { runtimeInfo.SetClient(client) + runtimeInfo.SetOwnerDatasetUID(dataset.UID) } return runtimeInfo, err } diff --git a/pkg/ddc/efc/create_volume.go b/pkg/ddc/efc/create_volume.go index dbdc27e7ff4..f93de221838 100644 --- a/pkg/ddc/efc/create_volume.go +++ b/pkg/ddc/efc/create_volume.go @@ -100,7 +100,8 @@ func (e *EFCEngine) createPersistentVolumeForRuntime(runtime base.RuntimeInfoInt Name: pvName, Namespace: runtime.GetNamespace(), Labels: map[string]string{ - runtime.GetCommonLabelName(): "true", + runtime.GetCommonLabelName(): "true", + common.LabelAnnotationDatasetId: utils.GetDatasetId(runtime.GetNamespace(), runtime.GetName(), runtime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, 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/master_internal.go b/pkg/ddc/efc/master_internal.go index 3a938b0d77b..914fe944866 100644 --- a/pkg/ddc/efc/master_internal.go +++ b/pkg/ddc/efc/master_internal.go @@ -96,7 +96,9 @@ func (e *EFCEngine) generateEFCValueFile(runtime *datav1alpha1.EFCRuntime) (valu } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/efc/master_internal_test.go b/pkg/ddc/efc/master_internal_test.go index bb4f67760b0..50d56b9f25b 100644 --- a/pkg/ddc/efc/master_internal_test.go +++ b/pkg/ddc/efc/master_internal_test.go @@ -20,18 +20,17 @@ import ( "errors" "testing" - "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" - "k8s.io/apimachinery/pkg/util/net" - "github.com/brahma-adshonor/gohook" + datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" + "github.com/fluid-cloudnative/fluid/pkg/utils/helm" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - "github.com/fluid-cloudnative/fluid/pkg/utils/helm" + "k8s.io/apimachinery/pkg/util/net" ) func init() { @@ -100,15 +99,21 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "efc") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := EFCEngine{ - name: "test", - namespace: "fluid", - Client: client, - Log: fake.NullLogger(), - runtime: efcruntime, + name: "test", + namespace: "fluid", + Client: client, + Log: fake.NullLogger(), + runtime: efcruntime, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -196,15 +201,21 @@ func TestGenerateEFCValueFile(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "efc") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := EFCEngine{ - name: "test", - namespace: "fluid", - Client: client, - Log: fake.NullLogger(), - runtime: efcruntime, + name: "test", + namespace: "fluid", + Client: client, + Log: fake.NullLogger(), + runtime: efcruntime, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/ddc/efc/metadata_test.go b/pkg/ddc/efc/metadata_test.go index 06de36e5fe3..a9e75b09f9b 100644 --- a/pkg/ddc/efc/metadata_test.go +++ b/pkg/ddc/efc/metadata_test.go @@ -22,6 +22,7 @@ import ( "github.com/brahma-adshonor/gohook" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -86,14 +87,20 @@ func TestSyncMetadataInternal(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("spark", "fluid", "efc") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &EFCEngine{ - name: "spark", - namespace: "fluid", - Client: client, - Log: fake.NullLogger(), + name: "spark", + namespace: "fluid", + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } - err := gohook.HookMethod(engine, "TotalStorageBytes", mockTotalStorageBytesError, nil) + err = gohook.HookMethod(engine, "TotalStorageBytes", mockTotalStorageBytesError, nil) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/ddc/efc/runtime_info.go b/pkg/ddc/efc/runtime_info.go index 73f1964e312..2b94c93d9c3 100644 --- a/pkg/ddc/efc/runtime_info.go +++ b/pkg/ddc/efc/runtime_info.go @@ -52,6 +52,9 @@ func (e *EFCEngine) getRuntimeInfo() (info base.RuntimeInfoInterface, err error) // Setup with Dataset Info dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) return e.runtimeInfo, nil @@ -62,6 +65,7 @@ func (e *EFCEngine) getRuntimeInfo() (info base.RuntimeInfoInterface, err error) } e.runtimeInfo.SetupWithDataset(dataset) + e.runtimeInfo.SetOwnerDatasetUID(dataset.UID) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } diff --git a/pkg/ddc/efc/shutdown.go b/pkg/ddc/efc/shutdown.go index fe282adec9b..d9f5a00a310 100644 --- a/pkg/ddc/efc/shutdown.go +++ b/pkg/ddc/efc/shutdown.go @@ -272,7 +272,7 @@ func (e *EFCEngine) destroyWorkers(expectedWorkers int32) (currentWorkers int32, labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/efc/transform.go b/pkg/ddc/efc/transform.go index 9abe3f87175..a8e48eecb26 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" // tiered store err = e.transformFuseTieredStore(runtime, value) diff --git a/pkg/ddc/efc/transform_test.go b/pkg/ddc/efc/transform_test.go index d1343e67b33..1587a388703 100644 --- a/pkg/ddc/efc/transform_test.go +++ b/pkg/ddc/efc/transform_test.go @@ -19,14 +19,16 @@ package efc import ( "testing" - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" - "github.com/fluid-cloudnative/fluid/pkg/utils/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/net" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" + + datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" + "github.com/fluid-cloudnative/fluid/pkg/utils/fake" ) func TestEFCEngine_transform(t *testing.T) { @@ -66,17 +68,22 @@ func TestEFCEngine_transform(t *testing.T) { testObjs = append(testObjs, test.dataset.DeepCopy()) client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "efc") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := EFCEngine{ - name: "test", - namespace: "fluid", - Client: client, - Log: fake.NullLogger(), - runtime: test.runtime, + name: "test", + namespace: "fluid", + Client: client, + Log: fake.NullLogger(), + runtime: test.runtime, + runtimeInfo: runtimeInfo, } ctrl.SetLogger(zap.New(func(o *zap.Options) { o.Development = true })) - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/ddc/efc/types.go b/pkg/ddc/efc/types.go index 126cf562898..cddc97a37b9 100644 --- a/pkg/ddc/efc/types.go +++ b/pkg/ddc/efc/types.go @@ -27,6 +27,7 @@ import ( // The value yaml file type EFC struct { FullnameOverride string `yaml:"fullnameOverride"` + OwnerDatasetId string `yaml:"ownerDatasetId"` PlacementMode string `yaml:"placement,omitempty"` Master Master `yaml:"master"` Worker Worker `yaml:"worker"` diff --git a/pkg/ddc/goosefs/deprecated_label.go b/pkg/ddc/goosefs/deprecated_label.go index d0bb66b2d7f..29db93e4f4b 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, e.runtimeInfo.GetOwnerDatasetUID()) + 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..7d9145955d1 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/engine.go b/pkg/ddc/goosefs/engine.go index 3ca5da2cf3c..3da5affe9b2 100644 --- a/pkg/ddc/goosefs/engine.go +++ b/pkg/ddc/goosefs/engine.go @@ -87,6 +87,7 @@ func Build(id string, ctx cruntime.ReconcileRequestContext) (base.Engine, error) if err != nil { return nil, fmt.Errorf("engine %s failed to get runtime info", ctx.Name) } + engine.runtimeInfo = runtimeInfo // Build the helper engine.Helper = ctrl.BuildHelper(runtimeInfo, ctx.Client, engine.Log) 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/load_data.go b/pkg/ddc/goosefs/load_data.go index 54ef280ae82..3e43a001b9c 100644 --- a/pkg/ddc/goosefs/load_data.go +++ b/pkg/ddc/goosefs/load_data.go @@ -157,9 +157,10 @@ func (e *GooseFSEngine) genDataLoadValue(image string, targetDataset *datav1alph } dataloadInfo.TargetPaths = targetPaths dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil diff --git a/pkg/ddc/goosefs/load_data_test.go b/pkg/ddc/goosefs/load_data_test.go index 2c3c770babf..6367bdea919 100644 --- a/pkg/ddc/goosefs/load_data_test.go +++ b/pkg/ddc/goosefs/load_data_test.go @@ -181,7 +181,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -283,7 +284,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -388,7 +390,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -464,7 +467,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/goosefs/master_internal.go b/pkg/ddc/goosefs/master_internal.go index be75b9c258b..e34a49c9316 100644 --- a/pkg/ddc/goosefs/master_internal.go +++ b/pkg/ddc/goosefs/master_internal.go @@ -99,7 +99,9 @@ func (e *GooseFSEngine) generateGooseFSValueFile(runtime *datav1alpha1.GooseFSRu } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/goosefs/master_internal_test.go b/pkg/ddc/goosefs/master_internal_test.go index 7e3193e8d06..5f98e1db33a 100644 --- a/pkg/ddc/goosefs/master_internal_test.go +++ b/pkg/ddc/goosefs/master_internal_test.go @@ -18,26 +18,19 @@ package goosefs import ( "fmt" + "testing" "github.com/brahma-adshonor/gohook" - - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - - "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" - - "github.com/fluid-cloudnative/fluid/pkg/utils/helm" - "github.com/pkg/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/net" + datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" - - "testing" + "github.com/fluid-cloudnative/fluid/pkg/utils/helm" ) func TestSetupMasterInternal(t *testing.T) { @@ -131,6 +124,11 @@ func TestSetupMasterInternal(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "goosefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := GooseFSEngine{ name: "hbase", @@ -156,9 +154,10 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -295,6 +294,11 @@ func TestGenerateGooseFSValueFile(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "goosefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := GooseFSEngine{ name: "hbase", @@ -320,9 +324,10 @@ func TestGenerateGooseFSValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } 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/runtime_info.go b/pkg/ddc/goosefs/runtime_info.go index 59ec62943f6..1ae55b7320c 100644 --- a/pkg/ddc/goosefs/runtime_info.go +++ b/pkg/ddc/goosefs/runtime_info.go @@ -45,6 +45,26 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) if !e.UnitTest { + // Setup with Dataset Info + dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) + return e.runtimeInfo, nil + } + + e.Log.Info("Failed to get dataset when getruntimeInfo") + return e.runtimeInfo, err + } + + e.runtimeInfo.SetupWithDataset(dataset) + e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) + + e.runtimeInfo.SetOwnerDatasetUID(dataset.UID) + // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() if err != nil { @@ -61,21 +81,6 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) - // Setup with Dataset Info - dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) - if err != nil { - if utils.IgnoreNotFound(err) == nil { - e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) - return e.runtimeInfo, nil - } - - e.Log.Info("Failed to get dataset when getruntimeInfo") - return e.runtimeInfo, err - } - - e.runtimeInfo.SetupWithDataset(dataset) - - e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } } diff --git a/pkg/ddc/goosefs/shutdown.go b/pkg/ddc/goosefs/shutdown.go index 577758d115c..1ed891bc791 100644 --- a/pkg/ddc/goosefs/shutdown.go +++ b/pkg/ddc/goosefs/shutdown.go @@ -285,7 +285,7 @@ func (e *GooseFSEngine) destroyWorkers(expectedWorkers int32) (currentWorkers in labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/goosefs/transform.go b/pkg/ddc/goosefs/transform.go index bf28da35d5c..854e4d25270 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) // 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..4994848bd73 100644 --- a/pkg/ddc/goosefs/transform_fuse.go +++ b/pkg/ddc/goosefs/transform_fuse.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/utils" ) // 4. Transform the fuse @@ -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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" value.Fuse.HostNetwork = true value.Fuse.HostPID = common.HostPIDEnabled(runtime.Annotations) value.Fuse.Enabled = true diff --git a/pkg/ddc/goosefs/transform_fuse_test.go b/pkg/ddc/goosefs/transform_fuse_test.go index b0ce174072a..66cfc5a5585 100644 --- a/pkg/ddc/goosefs/transform_fuse_test.go +++ b/pkg/ddc/goosefs/transform_fuse_test.go @@ -20,6 +20,7 @@ import ( "testing" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" ) @@ -41,8 +42,16 @@ func TestTransformFuseWithNoArgs(t *testing.T) { }}, &GooseFS{}, "--fuse-opts=rw,direct_io,allow_other"}, } for _, test := range tests { - engine := &GooseFSEngine{Log: fake.NullLogger()} - err := engine.transformFuse(test.runtime, test.dataset, test.goosefsValue) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "goosefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &GooseFSEngine{ + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } + err = engine.transformFuse(test.runtime, test.dataset, test.goosefsValue) if err != nil { t.Errorf("Got err %v", err) } @@ -77,8 +86,16 @@ func TestTransformFuseWithArgs(t *testing.T) { }}, &GooseFS{}, "--fuse-opts=kernel_cache,allow_other"}, } for _, test := range tests { - engine := &GooseFSEngine{Log: fake.NullLogger()} - err := engine.transformFuse(test.runtime, test.dataset, test.goosefsValue) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "goosefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &GooseFSEngine{ + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } + err = engine.transformFuse(test.runtime, test.dataset, test.goosefsValue) if err != nil { t.Errorf("Got err %v", err) } diff --git a/pkg/ddc/goosefs/transform_test.go b/pkg/ddc/goosefs/transform_test.go index bd753cadf57..890fdcce3e0 100644 --- a/pkg/ddc/goosefs/transform_test.go +++ b/pkg/ddc/goosefs/transform_test.go @@ -20,6 +20,8 @@ import ( "testing" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + fakeutils "github.com/fluid-cloudnative/fluid/pkg/utils/fake" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -55,9 +57,16 @@ func TestTransformFuse(t *testing.T) { }, &GooseFS{}, []string{"fuse", "--fuse-opts=rw,direct_io,uid=1000,gid=1000,allow_other"}}, } for _, test := range tests { - engine := &GooseFSEngine{} + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "goosefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &GooseFSEngine{ + runtimeInfo: runtimeInfo, + Client: fakeutils.NewFakeClientWithScheme(testScheme), + } engine.Log = ctrl.Log - err := engine.transformFuse(test.runtime, test.dataset, test.value) + err = engine.transformFuse(test.runtime, test.dataset, test.value) if err != nil { t.Errorf("error %v", err) } diff --git a/pkg/ddc/goosefs/types.go b/pkg/ddc/goosefs/types.go index 1f20e02ed7c..95590c9371b 100644 --- a/pkg/ddc/goosefs/types.go +++ b/pkg/ddc/goosefs/types.go @@ -27,6 +27,7 @@ import ( // The value yaml file type GooseFS struct { FullnameOverride string `yaml:"fullnameOverride"` + OwnerDatasetId string `yaml:"ownerDatasetId"` 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..6e804eb4f7e 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, e.runtimeInfo.GetOwnerDatasetUID()) + 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..1a53894ece9 100644 --- a/pkg/ddc/jindo/deprecated_label_test.go +++ b/pkg/ddc/jindo/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 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/load_data.go b/pkg/ddc/jindo/load_data.go index b14f19d30ce..60caa549da3 100644 --- a/pkg/ddc/jindo/load_data.go +++ b/pkg/ddc/jindo/load_data.go @@ -187,9 +187,10 @@ func (e *JindoEngine) genDataLoadValue(image string, runtime *datav1alpha1.Jindo dataloadInfo.Options = options dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil } diff --git a/pkg/ddc/jindo/load_data_test.go b/pkg/ddc/jindo/load_data_test.go index 1afbecdafaa..5d682a402bc 100644 --- a/pkg/ddc/jindo/load_data_test.go +++ b/pkg/ddc/jindo/load_data_test.go @@ -189,7 +189,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -301,7 +302,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -416,7 +418,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -502,7 +505,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/jindo/master_internal.go b/pkg/ddc/jindo/master_internal.go index 2c92f335512..565ceb47d0a 100644 --- a/pkg/ddc/jindo/master_internal.go +++ b/pkg/ddc/jindo/master_internal.go @@ -74,7 +74,9 @@ func (e *JindoEngine) generateJindoValueFile() (valueFileName string, err error) return } - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigmapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigmapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/jindo/master_internal_test.go b/pkg/ddc/jindo/master_internal_test.go index 8154c16e802..08ee8699cc5 100644 --- a/pkg/ddc/jindo/master_internal_test.go +++ b/pkg/ddc/jindo/master_internal_test.go @@ -19,18 +19,19 @@ package jindo import ( "testing" - "github.com/fluid-cloudnative/fluid/pkg/common" + "github.com/brahma-adshonor/gohook" + "github.com/pkg/errors" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/net" - "github.com/brahma-adshonor/gohook" 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/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" - "github.com/pkg/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/net" ) func TestSetupMasterInternal(t *testing.T) { @@ -85,6 +86,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindo") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := JindoEngine{ name: "hbase", namespace: "fluid", @@ -97,8 +103,9 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -176,6 +183,10 @@ func TestGenerateJindoValueFile(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindo") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } result := resource.MustParse("20Gi") engine := JindoEngine{ name: "hbase", @@ -197,9 +208,10 @@ func TestGenerateJindoValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } 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..6180775a007 100644 --- a/pkg/ddc/jindo/runtime_info.go +++ b/pkg/ddc/jindo/runtime_info.go @@ -45,25 +45,12 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { // Setup Fuse Deploy Mode e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) - // Check if the runtime is using deprecated labels - isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() - if err != nil { - return e.runtimeInfo, err - } - e.runtimeInfo.SetDeprecatedNodeLabel(isLabelDeprecated) - - // Check if the runtime is using deprecated naming style for PersistentVolumes - isPVNameDeprecated, err := volume.HasDeprecatedPersistentVolumeName(e.Client, e.runtimeInfo, e.Log) - if err != nil { - return e.runtimeInfo, err - } - e.runtimeInfo.SetDeprecatedPVName(isPVNameDeprecated) - - e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) - // Setup with Dataset Info dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) return e.runtimeInfo, nil @@ -74,8 +61,25 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { } e.runtimeInfo.SetupWithDataset(dataset) - e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) + + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) + + // Check if the runtime is using deprecated labels + isLabelDeprecated, err := e.HasDeprecatedCommonLabelName() + if err != nil { + return e.runtimeInfo, err + } + e.runtimeInfo.SetDeprecatedNodeLabel(isLabelDeprecated) + + // Check if the runtime is using deprecated naming style for PersistentVolumes + isPVNameDeprecated, err := volume.HasDeprecatedPersistentVolumeName(e.Client, e.runtimeInfo, e.Log) + if err != nil { + return e.runtimeInfo, err + } + e.runtimeInfo.SetDeprecatedPVName(isPVNameDeprecated) + + e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) } return e.runtimeInfo, nil diff --git a/pkg/ddc/jindo/shutdown.go b/pkg/ddc/jindo/shutdown.go index 7a422348ee7..2708fe5e246 100644 --- a/pkg/ddc/jindo/shutdown.go +++ b/pkg/ddc/jindo/shutdown.go @@ -230,7 +230,7 @@ func (e *JindoEngine) destroyWorkers(expectedWorkers int32) (currentWorkers int3 labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) diff --git a/pkg/ddc/jindo/transform.go b/pkg/ddc/jindo/transform.go index 69248db038d..bc3f086055f 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) + 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" return nil } diff --git a/pkg/ddc/jindo/types.go b/pkg/ddc/jindo/types.go index 0e62a678a08..0d55bac8525 100644 --- a/pkg/ddc/jindo/types.go +++ b/pkg/ddc/jindo/types.go @@ -23,6 +23,7 @@ import ( ) type Jindo struct { + OwnerDatasetId string `json:"ownerDatasetId"` Image string `yaml:"image"` ImageTag string `yaml:"imageTag"` ImagePullPolicy string `yaml:"imagePullPolicy"` diff --git a/pkg/ddc/jindo/worker.go b/pkg/ddc/jindo/worker.go index 2595a84a0d9..77e539a330c 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, e.runtimeInfo.GetOwnerDatasetUID()), Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}, }, diff --git a/pkg/ddc/jindo/worker_test.go b/pkg/ddc/jindo/worker_test.go index 60129acbd82..58708296b38 100644 --- a/pkg/ddc/jindo/worker_test.go +++ b/pkg/ddc/jindo/worker_test.go @@ -814,10 +814,15 @@ func TestBuildWorkersAffinity(t *testing.T) { runtimeObjs = append(runtimeObjs, tt.fields.dataset) runtimeObjs = append(runtimeObjs, tt.fields.worker) mockClient := fake.NewFakeClientWithScheme(s, runtimeObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindo") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } e := &JindoEngine{ - name: tt.fields.dataset.Name, - namespace: tt.fields.dataset.Namespace, - Client: mockClient, + name: tt.fields.dataset.Name, + namespace: tt.fields.dataset.Namespace, + Client: mockClient, + runtimeInfo: runtimeInfo, } want := tt.fields.want diff --git a/pkg/ddc/jindocache/deprecated_label.go b/pkg/ddc/jindocache/deprecated_label.go index d672d4f8ad1..aa8901f1811 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, e.runtimeInfo.GetOwnerDatasetUID()) + 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..d461a80bbbb 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/load_data.go b/pkg/ddc/jindocache/load_data.go index b422bd7f2b3..2a5b5da0e81 100644 --- a/pkg/ddc/jindocache/load_data.go +++ b/pkg/ddc/jindocache/load_data.go @@ -186,9 +186,10 @@ func (e *JindoCacheEngine) genDataLoadValue(image string, runtime *datav1alpha1. dataloadInfo.Options = options dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil diff --git a/pkg/ddc/jindocache/load_data_test.go b/pkg/ddc/jindocache/load_data_test.go index e4f7499cc52..3d382cacce0 100644 --- a/pkg/ddc/jindocache/load_data_test.go +++ b/pkg/ddc/jindocache/load_data_test.go @@ -189,7 +189,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -301,7 +302,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -416,7 +418,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -502,7 +505,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/jindocache/master_internal.go b/pkg/ddc/jindocache/master_internal.go index 30ce1eab936..a3fcda76f6d 100644 --- a/pkg/ddc/jindocache/master_internal.go +++ b/pkg/ddc/jindocache/master_internal.go @@ -74,7 +74,9 @@ func (e *JindoCacheEngine) generateJindoValueFile() (valueFileName string, err e return } - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/jindocache/master_internal_test.go b/pkg/ddc/jindocache/master_internal_test.go index 7f4588ed216..a768a9c8b05 100644 --- a/pkg/ddc/jindocache/master_internal_test.go +++ b/pkg/ddc/jindocache/master_internal_test.go @@ -19,18 +19,19 @@ package jindocache import ( "testing" - "github.com/fluid-cloudnative/fluid/pkg/common" + "github.com/brahma-adshonor/gohook" + "github.com/pkg/errors" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/net" - "github.com/brahma-adshonor/gohook" 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/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" - "github.com/pkg/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/net" ) func TestSetupMasterInternal(t *testing.T) { @@ -85,6 +86,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindocache") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := JindoCacheEngine{ name: "hbase", namespace: "fluid", @@ -97,8 +103,9 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -178,6 +185,10 @@ func TestGenerateJindoValueFile(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindocache") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } result := resource.MustParse("20Gi") engine := JindoCacheEngine{ name: "hbase", @@ -199,9 +210,10 @@ func TestGenerateJindoValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } 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/runtime_info.go b/pkg/ddc/jindocache/runtime_info.go index bcc81b8b719..2182089687b 100644 --- a/pkg/ddc/jindocache/runtime_info.go +++ b/pkg/ddc/jindocache/runtime_info.go @@ -44,6 +44,26 @@ func (e *JindoCacheEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { // Setup Fuse Deploy Mode e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) + // Setup with Dataset Info + dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) + return e.runtimeInfo, nil + } + + e.Log.Info("Failed to get dataset when getruntimeInfo") + return e.runtimeInfo, err + } + + e.runtimeInfo.SetupWithDataset(dataset) + e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) + + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) + // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() if err != nil { @@ -60,21 +80,6 @@ func (e *JindoCacheEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) - // Setup with Dataset Info - dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) - if err != nil { - if utils.IgnoreNotFound(err) == nil { - e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) - return e.runtimeInfo, nil - } - - e.Log.Info("Failed to get dataset when getruntimeInfo") - return e.runtimeInfo, err - } - - e.runtimeInfo.SetupWithDataset(dataset) - - e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } return e.runtimeInfo, nil diff --git a/pkg/ddc/jindocache/shutdown.go b/pkg/ddc/jindocache/shutdown.go index a690abe8e19..8a3827ea17e 100644 --- a/pkg/ddc/jindocache/shutdown.go +++ b/pkg/ddc/jindocache/shutdown.go @@ -230,7 +230,7 @@ func (e *JindoCacheEngine) destroyWorkers(expectedWorkers int32) (currentWorkers labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) diff --git a/pkg/ddc/jindocache/transform.go b/pkg/ddc/jindocache/transform.go index 323452aa827..d357fe9623d 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) + 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" } func (e *JindoCacheEngine) transformNodeSelector(runtime *datav1alpha1.JindoRuntime) map[string]string { diff --git a/pkg/ddc/jindocache/transform_test.go b/pkg/ddc/jindocache/transform_test.go index 76cacbd13fd..7cfe15aeda1 100644 --- a/pkg/ddc/jindocache/transform_test.go +++ b/pkg/ddc/jindocache/transform_test.go @@ -19,12 +19,11 @@ package jindocache import ( "os" "reflect" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log/zap" "testing" 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/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" corev1 "k8s.io/api/core/v1" @@ -32,6 +31,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/net" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) func TestTransformTolerations(t *testing.T) { @@ -636,15 +637,20 @@ func TestJindoCacheEngine_transform(t *testing.T) { s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{}) _ = corev1.AddToScheme(s) client := fake.NewFakeClientWithScheme(s, runtimeObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindocache") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } e := &JindoCacheEngine{ - runtime: tt.fields.runtime, - name: tt.fields.name, - namespace: tt.fields.namespace, - Client: client, - Log: fake.NullLogger(), + runtime: tt.fields.runtime, + name: tt.fields.name, + namespace: tt.fields.namespace, + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } tt.args.runtime = tt.fields.runtime - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatalf("failed to set up runtime port allocator due to %v", err) } @@ -1143,15 +1149,21 @@ func TestJindoCacheEngine_transformPolicy(t *testing.T) { s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{}) _ = corev1.AddToScheme(s) client := fake.NewFakeClientWithScheme(s, runtimeObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jinocache") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + e := &JindoCacheEngine{ - runtime: tt.fields.runtime, - name: tt.fields.name, - namespace: tt.fields.namespace, - Client: client, - Log: fake.NullLogger(), + runtime: tt.fields.runtime, + name: tt.fields.name, + namespace: tt.fields.namespace, + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } tt.args.runtime = tt.fields.runtime - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatalf("failed to set up runtime port allocator due to %v", err) } @@ -1352,15 +1364,21 @@ func TestJindoCacheEngine_transformCacheSet(t *testing.T) { s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{}) _ = corev1.AddToScheme(s) client := fake.NewFakeClientWithScheme(s, runtimeObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindocache") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + e := &JindoCacheEngine{ - runtime: tt.fields.runtime, - name: tt.fields.name, - namespace: tt.fields.namespace, - Client: client, - Log: fake.NullLogger(), + runtime: tt.fields.runtime, + name: tt.fields.name, + namespace: tt.fields.namespace, + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } tt.args.runtime = tt.fields.runtime - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatalf("failed to set up runtime port allocator due to %v", err) } diff --git a/pkg/ddc/jindocache/types.go b/pkg/ddc/jindocache/types.go index a5938426734..38c3846222d 100644 --- a/pkg/ddc/jindocache/types.go +++ b/pkg/ddc/jindocache/types.go @@ -23,6 +23,7 @@ import ( type Jindo struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` Image string `json:"image"` ImageTag string `json:"imageTag"` ImagePullPolicy string `json:"imagePullPolicy"` diff --git a/pkg/ddc/jindofsx/deprecated_label.go b/pkg/ddc/jindofsx/deprecated_label.go index 409c35458e0..7f8956be394 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, e.runtimeInfo.GetOwnerDatasetUID()) + 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..319236ccc50 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/load_data.go b/pkg/ddc/jindofsx/load_data.go index b6b3ac04102..45cc2cd2b65 100644 --- a/pkg/ddc/jindofsx/load_data.go +++ b/pkg/ddc/jindofsx/load_data.go @@ -186,9 +186,10 @@ func (e *JindoFSxEngine) genDataLoadValue(image string, runtime *datav1alpha1.Ji dataloadInfo.Options = options dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil diff --git a/pkg/ddc/jindofsx/load_data_test.go b/pkg/ddc/jindofsx/load_data_test.go index 1e699e0cdb5..fadf4c08ab0 100644 --- a/pkg/ddc/jindofsx/load_data_test.go +++ b/pkg/ddc/jindofsx/load_data_test.go @@ -189,7 +189,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -301,7 +302,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -416,7 +418,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -502,7 +505,8 @@ func Test_genDataLoadValue(t *testing.T) { }, }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/jindofsx/master_internal.go b/pkg/ddc/jindofsx/master_internal.go index 2adff343108..17d7167e040 100644 --- a/pkg/ddc/jindofsx/master_internal.go +++ b/pkg/ddc/jindofsx/master_internal.go @@ -74,7 +74,9 @@ func (e *JindoFSxEngine) generateJindoValueFile() (valueFileName string, err err return } - err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/jindofsx/master_internal_test.go b/pkg/ddc/jindofsx/master_internal_test.go index 088236498ac..10d2980799c 100644 --- a/pkg/ddc/jindofsx/master_internal_test.go +++ b/pkg/ddc/jindofsx/master_internal_test.go @@ -19,18 +19,19 @@ package jindofsx import ( "testing" + "github.com/brahma-adshonor/gohook" "github.com/fluid-cloudnative/fluid/pkg/common" + "github.com/pkg/errors" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/net" - "github.com/brahma-adshonor/gohook" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" - "github.com/pkg/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/net" ) func TestSetupMasterInternal(t *testing.T) { @@ -85,6 +86,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindofsx") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := JindoFSxEngine{ name: "hbase", namespace: "fluid", @@ -97,8 +103,9 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -175,6 +182,12 @@ func TestGenerateJindoValueFile(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "jindofsx") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + result := resource.MustParse("20Gi") engine := JindoFSxEngine{ name: "hbase", @@ -196,9 +209,10 @@ func TestGenerateJindoValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 50}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } 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/runtime_info.go b/pkg/ddc/jindofsx/runtime_info.go index 441ae394994..557a4bf7c65 100644 --- a/pkg/ddc/jindofsx/runtime_info.go +++ b/pkg/ddc/jindofsx/runtime_info.go @@ -44,6 +44,26 @@ func (e *JindoFSxEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { // Setup Fuse Deploy Mode e.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) + // Setup with Dataset Info + dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) + return e.runtimeInfo, nil + } + + e.Log.Info("Failed to get dataset when getruntimeInfo") + return e.runtimeInfo, err + } + + e.runtimeInfo.SetupWithDataset(dataset) + e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) + + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) + // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() if err != nil { @@ -59,22 +79,6 @@ func (e *JindoFSxEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetDeprecatedPVName(isPVNameDeprecated) e.Log.Info("Deprecation check finished", "isLabelDeprecated", e.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", e.runtimeInfo.IsDeprecatedPVName()) - - // Setup with Dataset Info - dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) - if err != nil { - if utils.IgnoreNotFound(err) == nil { - e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) - return e.runtimeInfo, nil - } - - e.Log.Info("Failed to get dataset when getruntimeInfo") - return e.runtimeInfo, err - } - - e.runtimeInfo.SetupWithDataset(dataset) - - e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } return e.runtimeInfo, nil diff --git a/pkg/ddc/jindofsx/shutdown.go b/pkg/ddc/jindofsx/shutdown.go index 0eaa97529e5..da757946d8f 100644 --- a/pkg/ddc/jindofsx/shutdown.go +++ b/pkg/ddc/jindofsx/shutdown.go @@ -230,7 +230,7 @@ func (e *JindoFSxEngine) destroyWorkers(expectedWorkers int32) (currentWorkers i labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) diff --git a/pkg/ddc/jindofsx/transform.go b/pkg/ddc/jindofsx/transform.go index 8310dd0a817..0fe108f509e 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) + 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" } func (e *JindoFSxEngine) transformNodeSelector(runtime *datav1alpha1.JindoRuntime) map[string]string { diff --git a/pkg/ddc/jindofsx/transform_test.go b/pkg/ddc/jindofsx/transform_test.go index 45029f1c018..cfe3f3c485d 100644 --- a/pkg/ddc/jindofsx/transform_test.go +++ b/pkg/ddc/jindofsx/transform_test.go @@ -23,6 +23,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/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" corev1 "k8s.io/api/core/v1" @@ -634,15 +635,20 @@ func TestJindoFSxEngine_transform(t *testing.T) { s.AddKnownTypes(datav1alpha1.GroupVersion, &datav1alpha1.DatasetList{}) _ = corev1.AddToScheme(s) client := fake.NewFakeClientWithScheme(s, runtimeObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "jindofsx") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } e := &JindoFSxEngine{ - runtime: tt.fields.runtime, - name: tt.fields.name, - namespace: tt.fields.namespace, - Client: client, - Log: fake.NullLogger(), + runtime: tt.fields.runtime, + name: tt.fields.name, + namespace: tt.fields.namespace, + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } tt.args.runtime = tt.fields.runtime - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatalf("failed to set up runtime port allocator due to %v", err) } diff --git a/pkg/ddc/jindofsx/types.go b/pkg/ddc/jindofsx/types.go index 9e7a166ced9..0e8650b2eb6 100644 --- a/pkg/ddc/jindofsx/types.go +++ b/pkg/ddc/jindofsx/types.go @@ -23,6 +23,7 @@ import ( type Jindo struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` Image string `json:"image"` ImageTag string `json:"imageTag"` ImagePullPolicy string `json:"imagePullPolicy"` diff --git a/pkg/ddc/juicefs/data_load.go b/pkg/ddc/juicefs/data_load.go index b2a8fd37704..12e656952fc 100644 --- a/pkg/ddc/juicefs/data_load.go +++ b/pkg/ddc/juicefs/data_load.go @@ -208,9 +208,10 @@ func (j *JuiceFSEngine) genDataLoadValue(image string, cacheinfo map[string]stri dataloadInfo.Options = options dataLoadValue := &cdataload.DataLoadValue{ - Name: dataload.Name, - DataLoadInfo: dataloadInfo, - Owner: transformer.GenerateOwnerReferenceFromObject(dataload), + Name: dataload.Name, + OwnerDatasetId: utils.GetDatasetId(targetDataset.Namespace, targetDataset.Name, string(targetDataset.UID)), + DataLoadInfo: dataloadInfo, + Owner: transformer.GenerateOwnerReferenceFromObject(dataload), } return dataLoadValue, nil diff --git a/pkg/ddc/juicefs/data_load_test.go b/pkg/ddc/juicefs/data_load_test.go index 6e1e5333bee..ed67bfec1f7 100644 --- a/pkg/ddc/juicefs/data_load_test.go +++ b/pkg/ddc/juicefs/data_load_test.go @@ -538,7 +538,8 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) { "cache-info-k3": "cache-info-v3", }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -668,7 +669,8 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) { "cache-info-k3": "cache-info-v3", }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -801,7 +803,8 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) { "cache-info-k3": "cache-info-v3", }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, @@ -905,7 +908,8 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) { "cache-info-k3": "cache-info-v3", }, want: &cdataload.DataLoadValue{ - Name: "test-dataload", + Name: "test-dataload", + OwnerDatasetId: "fluid-test-dataset", Owner: &common.OwnerReference{ APIVersion: "/", Enabled: true, diff --git a/pkg/ddc/juicefs/data_migrate.go b/pkg/ddc/juicefs/data_migrate.go index effebc1590a..df9ffcad594 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.OwnerDatasetId = utils.GetDatasetId(j.namespace, j.name, j.runtimeInfo.GetOwnerDatasetUID()) // 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/data_migrate_test.go b/pkg/ddc/juicefs/data_migrate_test.go index b744c16f836..d21c8959a0a 100644 --- a/pkg/ddc/juicefs/data_migrate_test.go +++ b/pkg/ddc/juicefs/data_migrate_test.go @@ -20,6 +20,7 @@ import ( "encoding/base64" "fmt" "github.com/fluid-cloudnative/fluid/pkg/dataoperation" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/utils" "os" "path/filepath" @@ -162,11 +163,16 @@ func TestJuiceFSEngine_generateDataMigrateValueFile(t *testing.T) { } for _, test := range testCases { + runtimeInfo, err := base.BuildRuntimeInfo("juicefs", "fluid", "juicefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := JuiceFSEngine{ - name: "juicefs", - namespace: "fluid", - Client: client, - Log: fake.NullLogger(), + name: "juicefs", + namespace: "fluid", + Client: client, + Log: fake.NullLogger(), + runtimeInfo: runtimeInfo, } fileName, err := engine.generateDataMigrateValueFile(context, &test.dataMigrate) if err != nil { diff --git a/pkg/ddc/juicefs/deprecated_label.go b/pkg/ddc/juicefs/deprecated_label.go index c29b6979732..8dbe9b3f74a 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, j.runtimeInfo.GetOwnerDatasetUID()) + 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..38a3d5dee5b 100644 --- a/pkg/ddc/juicefs/deprecated_label_test.go +++ b/pkg/ddc/juicefs/deprecated_label_test.go @@ -29,6 +29,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" ) func getTestJuiceFSEngine(client client.Client, name string, namespace string) *JuiceFSEngine { @@ -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/master_internal.go b/pkg/ddc/juicefs/master_internal.go index 6d4d794a092..8bc0a958310 100644 --- a/pkg/ddc/juicefs/master_internal.go +++ b/pkg/ddc/juicefs/master_internal.go @@ -98,7 +98,9 @@ func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRu } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(j.Client, j.getHelmValuesConfigMapName(), j.namespace, "data", data) + runtimeInfo := j.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(j.Client, j.getHelmValuesConfigMapName(), j.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/juicefs/master_internal_test.go b/pkg/ddc/juicefs/master_internal_test.go index 8083a34344e..8dc32c3ba4d 100644 --- a/pkg/ddc/juicefs/master_internal_test.go +++ b/pkg/ddc/juicefs/master_internal_test.go @@ -26,16 +26,15 @@ import ( "k8s.io/apimachinery/pkg/util/net" "github.com/brahma-adshonor/gohook" + datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" + "github.com/fluid-cloudnative/fluid/pkg/utils/fake" + "github.com/fluid-cloudnative/fluid/pkg/utils/helm" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - - "github.com/fluid-cloudnative/fluid/pkg/utils/fake" - - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" - "github.com/fluid-cloudnative/fluid/pkg/utils/helm" ) var ( @@ -124,6 +123,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "juicefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := JuiceFSEngine{ name: "test", namespace: "fluid", @@ -134,8 +138,9 @@ func TestSetupMasterInternal(t *testing.T) { Fuse: datav1alpha1.JuiceFSFuseSpec{}, }, }, + runtimeInfo: runtimeInfo, } - err := portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) + err = portallocator.SetupRuntimePortAllocator(client, &net.PortRange{Base: 10, Size: 100}, "bitmap", GetReservedPorts) if err != nil { t.Fatal(err.Error()) } @@ -249,6 +254,11 @@ func TestGenerateJuiceFSValueFile(t *testing.T) { client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "juicefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := JuiceFSEngine{ name: "test", namespace: "fluid", @@ -259,9 +269,10 @@ func TestGenerateJuiceFSValueFile(t *testing.T) { Fuse: datav1alpha1.JuiceFSFuseSpec{}, }, }, + runtimeInfo: runtimeInfo, } - _, err := engine.generateJuicefsValueFile(juicefsruntime) + _, err = engine.generateJuicefsValueFile(juicefsruntime) if err != nil { t.Errorf("fail to exec the function: %v", err) } 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/runtime_info.go b/pkg/ddc/juicefs/runtime_info.go index 7b6847d0a0b..43ea895cb21 100644 --- a/pkg/ddc/juicefs/runtime_info.go +++ b/pkg/ddc/juicefs/runtime_info.go @@ -45,6 +45,27 @@ func (j *JuiceFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { j.runtimeInfo.SetFuseNodeSelector(runtime.Spec.Fuse.NodeSelector) if !j.UnitTest { + // Setup with Dataset Info + dataset, err := utils.GetDataset(j.Client, j.name, j.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + j.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + j.Log.Info("Dataset is notfound", "name", j.name, "namespace", j.namespace) + return j.runtimeInfo, nil + } + + j.Log.Info("Failed to get dataset when getruntimeInfo") + return j.runtimeInfo, err + } + + j.runtimeInfo.SetupWithDataset(dataset) + j.Log.Info("Setup with dataset done", "exclusive", j.runtimeInfo.IsExclusive()) + + j.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) + j.Log.Info("Setup owner dataset-id", "UID", dataset.GetUID()) + // Check if the runtime is using deprecated labels isLabelDeprecated, err := j.HasDeprecatedCommonLabelName() if err != nil { @@ -60,22 +81,6 @@ func (j *JuiceFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { j.runtimeInfo.SetDeprecatedPVName(isPVNameDeprecated) j.Log.Info("Deprecation check finished", "isLabelDeprecated", j.runtimeInfo.IsDeprecatedNodeLabel(), "isPVNameDeprecated", j.runtimeInfo.IsDeprecatedPVName()) - - // Setup with Dataset Info - dataset, err := utils.GetDataset(j.Client, j.name, j.namespace) - if err != nil { - if utils.IgnoreNotFound(err) == nil { - j.Log.Info("Dataset is notfound", "name", j.name, "namespace", j.namespace) - return j.runtimeInfo, nil - } - - j.Log.Info("Failed to get dataset when getruntimeInfo") - return j.runtimeInfo, err - } - - j.runtimeInfo.SetupWithDataset(dataset) - - j.Log.Info("Setup with dataset done", "exclusive", j.runtimeInfo.IsExclusive()) } } diff --git a/pkg/ddc/juicefs/shutdown.go b/pkg/ddc/juicefs/shutdown.go index 1c91587d94b..cf00fb51f51 100644 --- a/pkg/ddc/juicefs/shutdown.go +++ b/pkg/ddc/juicefs/shutdown.go @@ -315,7 +315,7 @@ func (j *JuiceFSEngine) destroyWorkers(expectedWorkers int32) (currentWorkers in labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(j.namespace, j.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/juicefs/transform.go b/pkg/ddc/juicefs/transform.go index 15776d5ca9e..5d40f5f0b4c 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.OwnerDatasetId = utils.GetDatasetId(j.namespace, j.name, j.runtimeInfo.GetOwnerDatasetUID()) 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..9349b7492d4 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, j.runtimeInfo.GetOwnerDatasetUID())] = "true" } // genValue: generate the value of juicefs diff --git a/pkg/ddc/juicefs/transform_fuse_test.go b/pkg/ddc/juicefs/transform_fuse_test.go index 6bb588a5b9e..d941ceb8c4d 100644 --- a/pkg/ddc/juicefs/transform_fuse_test.go +++ b/pkg/ddc/juicefs/transform_fuse_test.go @@ -27,10 +27,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + 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/fake" - - datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" ) func TestTransformFuse(t *testing.T) { @@ -73,6 +73,10 @@ func TestTransformFuse(t *testing.T) { juicefsSecret3.DeepCopy()) client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "juicefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := JuiceFSEngine{ name: "test", namespace: "fluid", @@ -83,6 +87,7 @@ func TestTransformFuse(t *testing.T) { Fuse: datav1alpha1.JuiceFSFuseSpec{}, }, }, + runtimeInfo: runtimeInfo, } var tests = []struct { diff --git a/pkg/ddc/juicefs/transform_test.go b/pkg/ddc/juicefs/transform_test.go index 691be064404..19f2b27567f 100644 --- a/pkg/ddc/juicefs/transform_test.go +++ b/pkg/ddc/juicefs/transform_test.go @@ -23,13 +23,13 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/net" - "sigs.k8s.io/controller-runtime/pkg/client" - "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/net" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log/zap" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" @@ -54,6 +54,10 @@ func TestJuiceFSEngine_transform(t *testing.T) { testObjs = append(testObjs, (*juicefsSecret).DeepCopy()) client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "juicefs") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := JuiceFSEngine{ name: "test", namespace: "fluid", @@ -64,6 +68,7 @@ func TestJuiceFSEngine_transform(t *testing.T) { Fuse: datav1alpha1.JuiceFSFuseSpec{}, }, }, + runtimeInfo: runtimeInfo, } ctrl.SetLogger(zap.New(func(o *zap.Options) { o.Development = true diff --git a/pkg/ddc/juicefs/type.go b/pkg/ddc/juicefs/type.go index a4f87acf903..d4e1ff2426f 100644 --- a/pkg/ddc/juicefs/type.go +++ b/pkg/ddc/juicefs/type.go @@ -26,6 +26,7 @@ import ( // JuiceFS The value json file type JuiceFS struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` Edition string `json:"edition,omitempty"` Source string `json:"source,omitempty"` 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/master_internal.go b/pkg/ddc/thin/master_internal.go index 82c67fda791..014c43d7b9a 100644 --- a/pkg/ddc/thin/master_internal.go +++ b/pkg/ddc/thin/master_internal.go @@ -102,7 +102,9 @@ func (t *ThinEngine) generateThinValueFile(runtime *datav1alpha1.ThinRuntime, pr } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(t.Client, t.getHelmValuesConfigMapName(), t.namespace, "data", data) + runtimeInfo := t.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(t.Client, t.getHelmValuesConfigMapName(), t.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/thin/referencedataset/cm.go b/pkg/ddc/thin/referencedataset/cm.go index 1eba74b697b..11f960b573d 100644 --- a/pkg/ddc/thin/referencedataset/cm.go +++ b/pkg/ddc/thin/referencedataset/cm.go @@ -53,11 +53,18 @@ func copyFuseDaemonSetForRefDataset(client client.Client, refDataset *datav1alph UID: refDataset.UID, } - dsToCreate := &appsv1.DaemonSet{} - dsToCreate.Name = refDataset.Name + "-fuse" - dsToCreate.Namespace = refDataset.Namespace - dsToCreate.OwnerReferences = append(dsToCreate.OwnerReferences, ownerReference) - dsToCreate.Spec = *ds.Spec.DeepCopy() + dsToCreate := &appsv1.DaemonSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: refDataset.Name + "-fuse", + Namespace: refDataset.Namespace, + OwnerReferences: []metav1.OwnerReference{ownerReference}, + Labels: map[string]string{ + common.LabelAnnotationDatasetId: utils.GetDatasetId(refDataset.Namespace, refDataset.Name, string(refDataset.UID)), + }, + }, + Spec: *ds.Spec.DeepCopy(), + } + if len(dsToCreate.Spec.Template.Spec.NodeSelector) == 0 { dsToCreate.Spec.Template.Spec.NodeSelector = map[string]string{} } diff --git a/pkg/ddc/thin/referencedataset/runtime.go b/pkg/ddc/thin/referencedataset/runtime.go index 40ba677e813..249c39676ca 100644 --- a/pkg/ddc/thin/referencedataset/runtime.go +++ b/pkg/ddc/thin/referencedataset/runtime.go @@ -90,6 +90,9 @@ func (e *ReferenceDatasetEngine) getRuntimeInfo() (base.RuntimeInfoInterface, er // Setup with Dataset Info dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) return e.runtimeInfo, nil @@ -102,6 +105,7 @@ func (e *ReferenceDatasetEngine) getRuntimeInfo() (base.RuntimeInfoInterface, er // set exclusive mode // TODO: how to handle the exclusive mode ? e.runtimeInfo.SetupWithDataset(dataset) + e.runtimeInfo.SetOwnerDatasetUID(dataset.UID) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) diff --git a/pkg/ddc/thin/referencedataset/volume.go b/pkg/ddc/thin/referencedataset/volume.go index b5167561304..c3fe89afdc0 100644 --- a/pkg/ddc/thin/referencedataset/volume.go +++ b/pkg/ddc/thin/referencedataset/volume.go @@ -112,6 +112,7 @@ func createFusePersistentVolume(client client.Client, virtualRuntime base.Runtim Name: virtualPvName, Labels: map[string]string{ virtualRuntime.GetCommonLabelName(): "true", + common.LabelAnnotationDatasetId: utils.GetDatasetId(virtualDataset.GetNamespace(), virtualDataset.GetName(), string(virtualDataset.GetUID())), }, Annotations: physicalPV.ObjectMeta.Annotations, }, @@ -171,9 +172,10 @@ 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.GetNamespacedNameValueWithPrefix(common.LabelAnnotationStorageCapacityPrefix, virtualNamespace, virtualName, virtualRuntime.GetOwnerDatasetUID()): "true", + common.LabelAnnotationDatasetReferringName: runtimePVC.Name, + common.LabelAnnotationDatasetReferringNameSpace: runtimePVC.Namespace, + common.LabelAnnotationDatasetId: utils.GetDatasetId(virtualNamespace, virtualName, virtualRuntime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/ddc/thin/runtime_info.go b/pkg/ddc/thin/runtime_info.go index a553f5d1993..f2e2649be61 100644 --- a/pkg/ddc/thin/runtime_info.go +++ b/pkg/ddc/thin/runtime_info.go @@ -62,6 +62,9 @@ func (t *ThinEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { // Setup with Dataset Info dataset, err := utils.GetDataset(t.Client, t.name, t.namespace) if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + t.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } if utils.IgnoreNotFound(err) == nil { t.Log.Info("Dataset is notfound", "name", t.name, "namespace", t.namespace) return t.runtimeInfo, nil @@ -72,6 +75,7 @@ func (t *ThinEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { } t.runtimeInfo.SetupWithDataset(dataset) + t.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) t.Log.Info("Setup with dataset done", "exclusive", t.runtimeInfo.IsExclusive()) } diff --git a/pkg/ddc/thin/shutdown.go b/pkg/ddc/thin/shutdown.go index 45872ea3337..7aface30f5f 100644 --- a/pkg/ddc/thin/shutdown.go +++ b/pkg/ddc/thin/shutdown.go @@ -170,7 +170,7 @@ func (t *ThinEngine) destroyWorkers(expectedWorkers int32) (currentWorkers int32 labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(t.namespace, t.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/thin/transform.go b/pkg/ddc/thin/transform.go index 46ff4cb8364..0fbcde64d73 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.OwnerDatasetId = utils.GetDatasetId(t.namespace, t.name, t.runtimeInfo.GetOwnerDatasetUID()) 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..cbfdfe991df 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, t.runtimeInfo.GetOwnerDatasetUID())] = "true" // 5. ports if len(runtime.Spec.Fuse.Ports) != 0 { diff --git a/pkg/ddc/thin/transform_fuse_test.go b/pkg/ddc/thin/transform_fuse_test.go index 6ee73e08cc3..9ad1b0233d2 100644 --- a/pkg/ddc/thin/transform_fuse_test.go +++ b/pkg/ddc/thin/transform_fuse_test.go @@ -23,6 +23,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/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/testutil" "gopkg.in/yaml.v2" @@ -492,8 +493,19 @@ func TestThinEngine_transformFuse(t1 *testing.T) { }, } value := &ThinValue{} + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "thin") + if err != nil { + t1.Errorf("fail to create the runtimeInfo with error %v", err) + } t1.Run("test", func(t1 *testing.T) { - t := &ThinEngine{Log: fake.NullLogger(), namespace: "fluid", name: "test", runtime: runtime} + t := &ThinEngine{ + Log: fake.NullLogger(), + namespace: "fluid", + name: "test", + runtime: runtime, + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } if err := t.transformFuse(runtime, profile, dataset, value); err != nil { t1.Errorf("transformFuse() error = %v", err) } @@ -712,7 +724,19 @@ func TestThinEngine_transformFuseWithDuplicateOptionKey(t1 *testing.T) { } value := &ThinValue{} t1.Run("test", func(t1 *testing.T) { - t := &ThinEngine{Log: fake.NullLogger(), namespace: "fluid", name: "test", runtime: runtime} + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "thin") + if err != nil { + t1.Errorf("fail to create the runtimeInfo with error %v", err) + } + + t := &ThinEngine{ + Log: fake.NullLogger(), + namespace: "fluid", + name: "test", + runtime: runtime, + runtimeInfo: runtimeInfo, + Client: fake.NewFakeClientWithScheme(testScheme), + } if err := t.transformFuse(runtime, profile, dataset, value); err != nil { t1.Errorf("transformFuse() error = %v", err) } diff --git a/pkg/ddc/thin/type.go b/pkg/ddc/thin/type.go index c51497dfe7c..d7e4971a9fb 100644 --- a/pkg/ddc/thin/type.go +++ b/pkg/ddc/thin/type.go @@ -24,6 +24,7 @@ import ( type ThinValue struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` 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/master_internal.go b/pkg/ddc/vineyard/master_internal.go index e96cc2b9e32..7ff94689f2d 100644 --- a/pkg/ddc/vineyard/master_internal.go +++ b/pkg/ddc/vineyard/master_internal.go @@ -94,7 +94,9 @@ func (e *VineyardEngine) generateVineyardValueFile(runtime *datav1alpha1.Vineyar } //3. Save the configfile into configmap - err = kubeclient.CreateConfigMap(e.Client, e.getConfigmapName(), e.namespace, "data", data) + runtimeInfo := e.runtimeInfo + ownerDatasetId := utils.GetDatasetId(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getConfigmapName(), e.namespace, "data", data, ownerDatasetId) if err != nil { return } diff --git a/pkg/ddc/vineyard/master_internal_test.go b/pkg/ddc/vineyard/master_internal_test.go index 4b4b7b1dfe3..e5c9c807542 100644 --- a/pkg/ddc/vineyard/master_internal_test.go +++ b/pkg/ddc/vineyard/master_internal_test.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/utils/helm" @@ -101,6 +102,11 @@ func TestSetupMasterInternal(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "vineyard", base.WithTieredStore(vineyardruntime.Spec.TieredStore)) + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := VineyardEngine{ name: "hbase", namespace: "fluid", @@ -115,6 +121,7 @@ func TestSetupMasterInternal(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } err = engine.setupMasterInternal() if err == nil { @@ -128,7 +135,7 @@ func TestSetupMasterInternal(t *testing.T) { } err = engine.setupMasterInternal() if err != nil { - t.Errorf("fail to exec check helm release") + t.Errorf("fail to exec check helm release, %v", err) } wrappedUnhookCheckRelease() @@ -167,7 +174,7 @@ func TestSetupMasterInternal(t *testing.T) { } err = engine.setupMasterInternal() if err != nil { - t.Errorf("fail to install release") + t.Errorf("fail to install release, %v", err) } wrappedUnhookInstallRelease() wrappedUnhookCheckRelease() @@ -208,6 +215,10 @@ func TestGenerateVineyardValueFile(t *testing.T) { } client := fake.NewFakeClientWithScheme(testScheme, testObjs...) + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "vineyard", base.WithTieredStore(vineyardruntime.Spec.TieredStore)) + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := VineyardEngine{ name: "hbase", namespace: "fluid", @@ -222,9 +233,10 @@ func TestGenerateVineyardValueFile(t *testing.T) { }, }, }, + runtimeInfo: runtimeInfo, } - _, err := engine.generateVineyardValueFile(vineyardruntime) + _, err = engine.generateVineyardValueFile(vineyardruntime) if err != nil { t.Errorf("fail to generateVineyardValueFile %v", err) } 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/runtime_info.go b/pkg/ddc/vineyard/runtime_info.go index d145f32ea12..2f7a1470e43 100644 --- a/pkg/ddc/vineyard/runtime_info.go +++ b/pkg/ddc/vineyard/runtime_info.go @@ -14,8 +14,8 @@ limitations under the License. package vineyard import ( - "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/utils" ) func (e *VineyardEngine) CheckRuntimeReady() (ready bool) { @@ -45,8 +45,20 @@ func (e *VineyardEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { return e.runtimeInfo, err } - // Setup Fuse Deploy Mode - e.runtimeInfo.SetFuseNodeSelector(common.VineyardFuseNodeSelector) + dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) + if err != nil { + if len(runtime.GetOwnerReferences()) > 0 { + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) + } + if utils.IgnoreNotFound(err) == nil { + e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) + return e.runtimeInfo, nil + } + + e.Log.Info("Failed to get dataset when getruntimeInfo") + return e.runtimeInfo, err + } + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) } return e.runtimeInfo, nil diff --git a/pkg/ddc/vineyard/shut_down.go b/pkg/ddc/vineyard/shut_down.go index 25e4797efd5..890eaca4f00 100644 --- a/pkg/ddc/vineyard/shut_down.go +++ b/pkg/ddc/vineyard/shut_down.go @@ -174,7 +174,7 @@ func (e *VineyardEngine) destroyWorkers(expectedWorkers int32) (currentWorkers i labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(e.namespace, e.name) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := toUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/ddc/vineyard/transform.go b/pkg/ddc/vineyard/transform.go index 8bd5d5a45ad..cde06208df6 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.OwnerDatasetId = utils.GetDatasetId(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) 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, e.runtimeInfo.GetOwnerDatasetUID())] = "true" return nodeSelector } diff --git a/pkg/ddc/vineyard/transform_test.go b/pkg/ddc/vineyard/transform_test.go index 2c066ffca11..926e9c6a4b4 100755 --- a/pkg/ddc/vineyard/transform_test.go +++ b/pkg/ddc/vineyard/transform_test.go @@ -24,6 +24,7 @@ import ( "github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/net" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -83,7 +84,13 @@ func TestTransformFuse(t *testing.T) { if strings.Contains(k, "env") { os.Setenv("VINEYARD_FUSE_IMAGE_ENV", "image-from-env:image-tag-from-env") } - engine := &VineyardEngine{} + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "vineyard") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + engine := &VineyardEngine{ + runtimeInfo: runtimeInfo, + } engine.Log = ctrl.Log engine.transformFuse(test.runtime, test.value) @@ -604,6 +611,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{}, @@ -618,9 +629,14 @@ func TestTransformFuseNodeSelector(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "vineyard") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } engine := &VineyardEngine{ - name: "vineyard", - namespace: "fluid", + name: "vineyard", + namespace: "fluid", + runtimeInfo: runtimeInfo, } actual := engine.transformFuseNodeSelector(tt.runtime) if !reflect.DeepEqual(actual, tt.expected) { diff --git a/pkg/ddc/vineyard/type.go b/pkg/ddc/vineyard/type.go index f5f9ee18e40..0a333f8bbd3 100644 --- a/pkg/ddc/vineyard/type.go +++ b/pkg/ddc/vineyard/type.go @@ -24,6 +24,7 @@ import ( // The value yaml file type Vineyard struct { FullnameOverride string `json:"fullnameOverride"` + OwnerDatasetId string `json:"ownerDatasetId"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/utils/crtl_utils.go b/pkg/utils/crtl_utils.go index 1fa354893fa..6c86d74f0c3 100644 --- a/pkg/utils/crtl_utils.go +++ b/pkg/utils/crtl_utils.go @@ -134,6 +134,17 @@ func ContainsOwners(owners []metav1.OwnerReference, dataset *datav1alpha1.Datase return false } +func ContainsLabel(labels map[string]string, labelKey, labelValue string) bool { + value, exit := labels[labelKey] + if !exit { + return false + } + if value == labelValue { + return true + } + return false +} + // ContainsSelector Determine whether the labels contain the selector func ContainsSelector(labels map[string]string, selector map[string]string) bool { for key, value := range selector { diff --git a/pkg/utils/dataset/lifecycle/node.go b/pkg/utils/dataset/lifecycle/node.go index bf8a0d9ebaf..dae5c772b05 100644 --- a/pkg/utils/dataset/lifecycle/node.go +++ b/pkg/utils/dataset/lifecycle/node.go @@ -241,7 +241,7 @@ func labelCacheNode(nodeToLabel corev1.Node, runtimeInfo base.RuntimeInfoInterfa labelsToModify.Add(commonLabel, "true") if exclusiveness { - exclusiveLabelValue := utils.GetExclusiveValue(runtimeInfo.GetNamespace(), runtimeInfo.GetName()) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() labelsToModify.Add(exclusiveLabel, exclusiveLabelValue) } @@ -359,7 +359,7 @@ func unlabelCacheNode(node corev1.Node, runtimeInfo base.RuntimeInfoInterface, c labelsToModify.Delete(label) } - exclusiveLabelValue := utils.GetExclusiveValue(runtimeInfo.GetNamespace(), runtimeInfo.GetName()) + exclusiveLabelValue := runtimeInfo.GetExclusiveLabelValue() if val, exist := nodeToUpdate.Labels[labelExclusiveName]; exist && val == exclusiveLabelValue { labelsToModify.Delete(labelExclusiveName) } diff --git a/pkg/utils/dataset/volume/create.go b/pkg/utils/dataset/volume/create.go index 4e125c74d86..46485cd2f0b 100644 --- a/pkg/utils/dataset/volume/create.go +++ b/pkg/utils/dataset/volume/create.go @@ -62,7 +62,8 @@ func CreatePersistentVolumeForRuntime(client client.Client, Name: pvName, Namespace: runtime.GetNamespace(), Labels: map[string]string{ - runtime.GetCommonLabelName(): "true", + runtime.GetCommonLabelName(): "true", + common.LabelAnnotationDatasetId: utils.GetDatasetId(runtime.GetNamespace(), runtime.GetName(), runtime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, @@ -207,7 +208,8 @@ func CreatePersistentVolumeClaimForRuntime(client client.Client, Name: runtime.GetName(), Namespace: runtime.GetNamespace(), Labels: map[string]string{ - runtime.GetCommonLabelName(): "true", + runtime.GetCommonLabelName(): "true", + common.LabelAnnotationDatasetId: utils.GetDatasetId(runtime.GetNamespace(), runtime.GetName(), runtime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/utils/dataset/volume/get.go b/pkg/utils/dataset/volume/get.go index a3cf8249f76..b0282f7bb67 100644 --- a/pkg/utils/dataset/volume/get.go +++ b/pkg/utils/dataset/volume/get.go @@ -35,12 +35,12 @@ func GetNamespacedNameByVolumeId(client client.Reader, volumeId string) (namespa namespace = pv.Spec.ClaimRef.Namespace name = pv.Spec.ClaimRef.Name - ok, err := kubeclient.IsDatasetPVC(client, name, namespace) + pvc, err := kubeclient.GetPersistentVolumeClaim(client, name, namespace) if err != nil { return "", "", err } - if !ok { + if !kubeclient.CheckIfPVCIsDataset(pvc) { return "", "", errors.Errorf("pv %s is not bounded with a fluid pvc", volumeId) } diff --git a/pkg/utils/dataset_runtime.go b/pkg/utils/dataset_runtime.go index 73f9fa7aaa4..c485475dac3 100644 --- a/pkg/utils/dataset_runtime.go +++ b/pkg/utils/dataset_runtime.go @@ -80,6 +80,9 @@ func CreateRuntimeForReferenceDatasetIfNotExist(client client.Client, dataset *d Controller: ptr.To(true), }, }, + Labels: map[string]string{ + common.LabelAnnotationDatasetId: GetDatasetId(dataset.GetNamespace(), dataset.GetName(), string(dataset.GetUID())), + }, }, } err = client.Create(context.TODO(), &runtime) diff --git a/pkg/utils/excluisve.go b/pkg/utils/excluisve.go deleted file mode 100644 index d81d9d54153..00000000000 --- a/pkg/utils/excluisve.go +++ /dev/null @@ -1,33 +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 utils - -import ( - "fmt" - - "github.com/fluid-cloudnative/fluid/pkg/common" -) - -// GetExclusiveKey gets exclusive key -func GetExclusiveKey() string { - return common.FluidExclusiveKey -} - -// GetExclusiveValue gets exclusive value -func GetExclusiveValue(namespace, name string) string { - return fmt.Sprintf("%s_%s", namespace, name) -} diff --git a/pkg/utils/excluisve_test.go b/pkg/utils/excluisve_test.go deleted file mode 100644 index db0f1ac8269..00000000000 --- a/pkg/utils/excluisve_test.go +++ /dev/null @@ -1,78 +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 utils - -import ( - "testing" - - "github.com/fluid-cloudnative/fluid/pkg/common" -) - -func TestGetExclusiveKey(t *testing.T) { - tests := []struct { - name string - want string - }{ - { - name: "test for GetExclusiveKey", - want: common.FluidExclusiveKey, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := GetExclusiveKey(); got != tt.want { - t.Errorf("GetExclusiveKey() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestGetExclusiveValue(t *testing.T) { - type args struct { - namespace string - name string - } - tests := []struct { - name string - args args - want string - }{ - { - name: "default test-dataset-1", - args: args{ - name: "test-dataset-1", - namespace: "default", - }, - want: "default_test-dataset-1", - }, - { - name: "otherns test-dataset-2", - args: args{ - name: "test-dataset-2", - namespace: "otherns", - }, - want: "otherns_test-dataset-2", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := GetExclusiveValue(tt.args.namespace, tt.args.name); got != tt.want { - t.Errorf("GetExclusiveValue() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/pkg/utils/kubeclient/configmap.go b/pkg/utils/kubeclient/configmap.go index 504ddf84a96..b6a79bb175c 100644 --- a/pkg/utils/kubeclient/configmap.go +++ b/pkg/utils/kubeclient/configmap.go @@ -19,6 +19,7 @@ package kubeclient import ( "context" "fmt" + "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -130,6 +131,11 @@ func CopyConfigMap(client client.Client, src types.NamespacedName, dst types.Nam Data: copiedConfigMap.Data, } + if dstConfigMap.Labels == nil { + dstConfigMap.Labels = make(map[string]string) + } + dstConfigMap.Labels[common.LabelAnnotationDatasetId] = utils.GetDatasetId(dst.Namespace, dst.Name, string(reference.UID)) + err = client.Create(context.TODO(), dstConfigMap) if err != nil { if otherErr := utils.IgnoreAlreadyExists(err); otherErr != nil { @@ -144,11 +150,14 @@ func UpdateConfigMap(client client.Client, cm *v1.ConfigMap) error { return err } -func CreateConfigMap(client client.Client, name string, namespace string, key string, data []byte) (err error) { +func CreateConfigMap(client client.Client, name string, namespace string, key string, data []byte, ownerDatasetId string) (err error) { configMap := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, + Labels: map[string]string{ + common.LabelAnnotationDatasetId: ownerDatasetId, + }, }, Data: map[string]string{ key: string(data), diff --git a/pkg/utils/kubeclient/configmap_test.go b/pkg/utils/kubeclient/configmap_test.go index ca9cefd0835..e6cee7860e9 100644 --- a/pkg/utils/kubeclient/configmap_test.go +++ b/pkg/utils/kubeclient/configmap_test.go @@ -263,7 +263,7 @@ func TestCreateConfigMapExist(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := CreateConfigMap(client, tt.args.name, tt.args.namespace, tt.args.key, tt.args.data) + err := CreateConfigMap(client, tt.args.name, tt.args.namespace, tt.args.key, tt.args.data, "") if err != nil { t.Errorf("testcase %v CreateConfigMap() err is %v", tt.name, err) } diff --git a/pkg/utils/kubeclient/secret.go b/pkg/utils/kubeclient/secret.go index 6ad79421710..6faa71c48e9 100644 --- a/pkg/utils/kubeclient/secret.go +++ b/pkg/utils/kubeclient/secret.go @@ -66,13 +66,18 @@ func CopySecretToNamespace(client client.Client, from types.NamespacedName, to t return err } - secretToCreate := &v1.Secret{} - secretToCreate.Namespace = to.Namespace - secretToCreate.Name = to.Name - secretToCreate.Data = secret.Data - secretToCreate.StringData = secret.StringData - secretToCreate.Labels = map[string]string{} - secretToCreate.Labels["fluid.io/copied-from"] = fmt.Sprintf("%s_%s", from.Namespace, from.Name) + secretToCreate := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: to.Name, + Namespace: to.Namespace, + Labels: map[string]string{ + common.LabelAnnotationCopyFrom: fmt.Sprintf("%s_%s", from.Namespace, from.Name), + }, + }, + Data: secret.Data, + StringData: secret.StringData, + } + if ownerReference != nil { secretToCreate.OwnerReferences = append(secretToCreate.OwnerReferences, metav1.OwnerReference{ APIVersion: ownerReference.APIVersion, diff --git a/pkg/utils/kubeclient/volume.go b/pkg/utils/kubeclient/volume.go index f3c9b04e40b..31a5e603682 100644 --- a/pkg/utils/kubeclient/volume.go +++ b/pkg/utils/kubeclient/volume.go @@ -19,6 +19,7 @@ package kubeclient import ( "context" "fmt" + "strings" "time" "github.com/fluid-cloudnative/fluid/pkg/common" @@ -345,31 +346,18 @@ func ShouldRemoveProtectionFinalizer(client client.Client, name, namespace strin return } -// IsDatasetPVC check whether the PVC is a dataset PVC -func IsDatasetPVC(client client.Reader, name string, namespace string) (find bool, err error) { - pvc := &corev1.PersistentVolumeClaim{} - err = client.Get(context.TODO(), types.NamespacedName{ - Namespace: namespace, - Name: name, - }, pvc) - if err != nil { - return - } - _, find = pvc.Labels[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+name] - return -} - // CheckIfPVCIsDataset checks if the pvc is dataset func CheckIfPVCIsDataset(pvc *corev1.PersistentVolumeClaim) (isDataset bool) { - if pvc == nil { + if pvc == nil || pvc.Labels == nil { return } - name := pvc.GetName() - namespace := pvc.GetNamespace() - if len(namespace) == 0 { - namespace = corev1.NamespaceDefault + + for labelKey := range pvc.Labels { + if strings.HasPrefix(labelKey, common.LabelAnnotationStorageCapacityPrefix) { + isDataset = true + break + } } - _, isDataset = pvc.Labels[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+name] if _, exists := common.GetManagerDatasetFromLabels(pvc.Labels); exists { isDataset = true diff --git a/pkg/utils/kubeclient/volume_claim.go b/pkg/utils/kubeclient/volume_claim.go index bede75ddb72..ab7b9c77bc1 100644 --- a/pkg/utils/kubeclient/volume_claim.go +++ b/pkg/utils/kubeclient/volume_claim.go @@ -27,7 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func GetPersistentVolumeClaim(client client.Client, name, namespace string) (pvc *v1.PersistentVolumeClaim, err error) { +func GetPersistentVolumeClaim(client client.Reader, name, namespace string) (pvc *v1.PersistentVolumeClaim, err error) { pvc = &v1.PersistentVolumeClaim{} err = client.Get(context.TODO(), types.NamespacedName{ diff --git a/pkg/utils/kubeclient/volume_test.go b/pkg/utils/kubeclient/volume_test.go index 61a6ad66bad..6eaaca38721 100644 --- a/pkg/utils/kubeclient/volume_test.go +++ b/pkg/utils/kubeclient/volume_test.go @@ -574,80 +574,6 @@ func TestShouldRemoveProtectionFinalizer(t *testing.T) { } } -func TestIsDatasetPVC(t *testing.T) { - - namespace := "default" - datasetName := "createdByFluid" - expectFluidAnnotations := common.ExpectedFluidAnnotations - expectFluidAnnotations[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+datasetName] = "true" - testPVCInputs := []*v1.PersistentVolumeClaim{{ - ObjectMeta: metav1.ObjectMeta{Name: "notCreatedByFluid", - Namespace: namespace}, - Spec: v1.PersistentVolumeClaimSpec{}, - }, { - ObjectMeta: metav1.ObjectMeta{Name: "createdByFluid", - Labels: expectFluidAnnotations, - Namespace: namespace}, - Spec: v1.PersistentVolumeClaimSpec{}, - }} - - testPVCs := []runtime.Object{} - - for _, pvc := range testPVCInputs { - testPVCs = append(testPVCs, pvc.DeepCopy()) - } - - client := fake.NewFakeClientWithScheme(testScheme, testPVCs...) - - type args struct { - name string - namespace string - } - tests := []struct { - name string - args args - found bool - }{ - { - name: "volume for dataset doesn't exist", - args: args{ - name: "notExist", - namespace: namespace, - }, - found: false, - }, - { - name: "volume notCreatedByFluid is not created by fluid", - args: args{ - name: "notCreatedByFluid", - namespace: namespace, - }, - found: false, - }, - { - name: "volume is created by fluid", - args: args{ - name: datasetName, - namespace: namespace, - }, - found: true, - }, { - name: "volume is not created by fluid 2", - args: args{ - name: "notCreatedByFluid2", - }, - found: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if found, _ := IsDatasetPVC(client, tt.args.name, tt.args.namespace); found != tt.found { - t.Errorf("testcase %v IsDatasetPVC() = %v, want %v", tt.name, found, tt.found) - } - }) - } -} - func TestGetReferringDatasetPVCInfo(t *testing.T) { type args struct { pvc *v1.PersistentVolumeClaim diff --git a/pkg/utils/label.go b/pkg/utils/label.go index 404dbb5ca52..e498595b2e0 100644 --- a/pkg/utils/label.go +++ b/pkg/utils/label.go @@ -20,12 +20,12 @@ import ( "context" "encoding/json" "fmt" - "github.com/fluid-cloudnative/fluid/pkg/common" "github.com/fluid-cloudnative/fluid/pkg/common/deprecated" "github.com/pkg/errors" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/validation" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -114,64 +114,127 @@ 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, name, ownerDatasetUID 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 GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) } -func GetLabelNameForMemory(isDeprecated bool, runtimeType string, namespace string, name string) string { +func GetLabelNameForMemory(isDeprecated bool, runtimeType string, namespace, name, ownerDatasetUID string) string { read := common.HumanReadType storage := common.MemoryStorageType if isDeprecated { read = deprecated.HumanReadType storage = deprecated.MemoryStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetLabelNameForDisk(isDeprecated bool, runtimeType string, namespace string, name string) string { +func GetLabelNameForDisk(isDeprecated bool, runtimeType string, namespace, name, ownerDatasetUID string) string { read := common.HumanReadType storage := common.DiskStorageType if isDeprecated { read = deprecated.HumanReadType storage = deprecated.DiskStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetLabelNameForTotal(isDeprecated bool, runtimeType string, namespace string, name string) string { +func GetLabelNameForTotal(isDeprecated bool, runtimeType string, namespace, name, ownerDatasetUID string) string { read := common.HumanReadType storage := common.TotalStorageType if isDeprecated { read = deprecated.HumanReadType storage = deprecated.TotalStorageType } - return GetStoragetLabelName(read, storage, isDeprecated, runtimeType, namespace, name) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetCommonLabelName(isDeprecated bool, namespace string, name string) string { +func GetCommonLabelName(isDeprecated bool, namespace, name, ownerDatasetUID string) string { prefix := common.LabelAnnotationStorageCapacityPrefix if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return prefix + namespace + "-" + name + return GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) } -func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace string, name string) string { +func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace, name, ownerDatasetUID string) string { prefix := common.LabelAnnotationStorageCapacityPrefix if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return prefix + runtimeType + "-" + namespace + "-" + name + + prefix = prefix + runtimeType + "-" + + return GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) +} + +func GetFuseLabelName(namespace, name, ownerDatasetUID string) string { + return GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, namespace, name, ownerDatasetUID) +} + +func GetExclusiveKey() string { + return common.FluidExclusiveKey +} + +// GetNamespacedNameValueWithPrefix 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 GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID string) (fullNamespacedNameWithPrefix string) { + namespacedName := fmt.Sprintf("%s-%s", namespace, name) + fullNamespacedNameWithPrefix = fmt.Sprintf("%s%s", prefix, namespacedName) + // ensure forward compatibility + if len(fullNamespacedNameWithPrefix) < validation.DNS1035LabelMaxLength { + return + } + + if ownerDatasetUID == "" { + log.Info("The ownerDatasetUID is absent, fall back to original value which causes the resource creation failed by scheme validation", "key", fmt.Sprintf("%s-%s", namespace, name)) + return fullNamespacedNameWithPrefix + } + + fullNamespacedNameWithPrefix = fmt.Sprintf("%s%s", prefix, ownerDatasetUID) + + return +} + +func GetDatasetId(namespace, name, ownerDatasetUID string) (fullNamespacedNameWithPrefix string) { + return GetNamespacedNameValueWithPrefix("", namespace, name, ownerDatasetUID) +} + +func PatchLabelToObjects(cli client.Client, labelKey, labelValue string, objs ...client.Object) (errs []error) { + for _, obj := range objs { + if obj.GetLabels() == nil || + !ContainsLabel(obj.GetLabels(), common.LabelAnnotationDatasetId, labelValue) { + labelValuePair := map[string]string{ + labelKey: labelValue, + } + + metadata := map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": labelValuePair, + }, + } + + patchByteData, err := json.Marshal(metadata) + if err != nil { + errs = append(errs, err) + continue + } + + err = cli.Patch(context.TODO(), obj, client.RawPatch(types.MergePatchType, patchByteData)) + if err != nil { + log.Error(err, "failed to patch labels", "objKind", obj.GetObjectKind(), "name", obj.GetName(), "labels", obj.GetLabels()) + errs = append(errs, err) + continue + } + } + } + return } diff --git a/pkg/utils/label_test.go b/pkg/utils/label_test.go index be498f65214..6166a1e8a9f 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, ownerDatasetUID string + expected string + }{ + {"normal-", "default", "test-dataset", "", "normal-default-test-dataset"}, + {"overlimit-", "namespace-ajsdjikebnfacdsvwcaxqcackjascnbaksjcnakjscnackjasn", "dataset-demo", "58df5bd9cc", "overlimit-58df5bd9cc"}, + {"overlimit-", "namespace-demo", "dataset-ajsdjikebnfacdsvwcaxqcackjascnbaksjcnakjscnackjasn", "6dfd85695", "overlimit-6dfd85695"}, + } + + for _, test := range tests { + result := GetNamespacedNameValueWithPrefix(test.prefix, test.namespace, test.name, test.ownerDatasetUID) + if result != test.expected { + t.Errorf("GetNamespacedNameValueWithPrefix(%v) = %v, want %v", test, result, test.expected) + } + } +}