From abc1417814acb144725f6db9036b5f893127c25b Mon Sep 17 00:00:00 2001 From: jiuyu Date: Thu, 16 Jan 2025 11:52:14 +0800 Subject: [PATCH] Feature: add datasetReferenceLabel 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 | 7 ++ pkg/csi/plugins/nodeserver.go | 4 +- pkg/ctrl/fuse.go | 4 +- pkg/databackup/value.go | 21 +++--- pkg/dataload/value.go | 7 +- pkg/datamigrate/value.go | 2 +- pkg/ddc/alluxio/backup_data.go | 7 ++ pkg/ddc/alluxio/deprecated_label.go | 2 +- 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/runtime_info.go | 4 +- pkg/ddc/alluxio/transform.go | 2 +- pkg/ddc/alluxio/transform_fuse.go | 2 +- pkg/ddc/alluxio/types.go | 2 +- pkg/ddc/base/label.go | 14 ++-- pkg/ddc/base/runtime.go | 27 ++++---- pkg/ddc/efc/create_volume.go | 3 +- pkg/ddc/efc/master_internal.go | 4 +- pkg/ddc/efc/runtime_info.go | 4 +- pkg/ddc/efc/transform.go | 4 +- pkg/ddc/efc/types.go | 2 +- pkg/ddc/goosefs/deprecated_label.go | 2 +- 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/runtime_info.go | 4 +- pkg/ddc/goosefs/transform.go | 2 +- pkg/ddc/goosefs/transform_fuse.go | 2 +- pkg/ddc/goosefs/types.go | 2 +- pkg/ddc/jindo/deprecated_label.go | 2 +- 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/runtime_info.go | 4 +- pkg/ddc/jindo/transform.go | 4 +- pkg/ddc/jindo/types.go | 2 +- pkg/ddc/jindo/worker.go | 2 +- pkg/ddc/jindocache/deprecated_label.go | 2 +- 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/runtime_info.go | 4 +- pkg/ddc/jindocache/transform.go | 4 +- pkg/ddc/jindocache/types.go | 2 +- pkg/ddc/jindofsx/deprecated_label.go | 2 +- 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/runtime_info.go | 4 +- pkg/ddc/jindofsx/transform.go | 4 +- pkg/ddc/jindofsx/types.go | 2 +- 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/deprecated_label.go | 2 +- pkg/ddc/juicefs/master_internal.go | 4 +- pkg/ddc/juicefs/runtime_info.go | 4 +- pkg/ddc/juicefs/transform.go | 2 +- pkg/ddc/juicefs/transform_fuse.go | 2 +- pkg/ddc/juicefs/type.go | 2 +- pkg/ddc/thin/master_internal.go | 4 +- pkg/ddc/thin/referencedataset/cm.go | 17 +++-- pkg/ddc/thin/referencedataset/runtime.go | 2 +- pkg/ddc/thin/referencedataset/volume.go | 6 +- pkg/ddc/thin/runtime_info.go | 4 +- pkg/ddc/thin/transform.go | 2 +- pkg/ddc/thin/transform_fuse.go | 2 +- pkg/ddc/thin/type.go | 2 +- pkg/ddc/vineyard/master_internal.go | 4 +- pkg/ddc/vineyard/runtime_info.go | 4 +- pkg/ddc/vineyard/transform.go | 4 +- pkg/ddc/vineyard/type.go | 2 +- pkg/utils/crtl_utils.go | 5 ++ pkg/utils/dataset/volume/create.go | 6 +- pkg/utils/dataset_runtime.go | 3 + pkg/utils/kubeclient/configmap.go | 11 ++- pkg/utils/kubeclient/configmap_test.go | 2 +- pkg/utils/kubeclient/secret.go | 19 ++++-- pkg/utils/label.go | 68 ++++++++++++++----- pkg/utils/label_test.go | 6 +- 119 files changed, 404 insertions(+), 227 deletions(-) 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 f3700202e86..a646b331cff 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 1e7c5912fa7..383c9d58f77 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 a5f47bf2017..46589366c76 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-{{ .Values.fullNamespacedNameOverride }} + fluid.io/operation: migrate-{{ .Values.ownerDatasetIdentification }} {{- 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 e83699c44e7..325261a46b9 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-{{ .Values.fullNamespacedNameOverride }} + fluid.io/operation: migrate-{{ .Values.ownerDatasetIdentification }} 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 bf7033936cd..74004e2ec8f 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 9709a0490a5..f6d7a8d135e 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 538f28f9e26..993a043f137 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 9c2a2b9f687..6941a8efd51 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 b123bd43ed8..c1f6e5f1d5a 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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..de7f8d3f875 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-identification: {{ .Values.ownerDatasetIdentification }} {{- 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 b11b6647d21..6200737a6b1 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} 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 b6e06109674..6d5dda15a6b 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: {{ .Values.fullNamespacedNameOverride }} + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} {{- 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: {{ .Values.fullNamespacedNameOverride }}-worker template: metadata: annotations: @@ -62,8 +61,8 @@ spec: release: {{ .Release.Name }} heritage: {{ .Release.Service }} role: vineyard-worker - fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }} - app.kubernetes.io/instance: {{ .Values.fullNamespacedNameOverride }}-worker + fluid.io/dataset: {{ .Values.ownerDatasetIdentification }} + {{- 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: - - {{ .Values.fullNamespacedNameOverride }}-worker + - {{ .Values.ownerDatasetIdentification }}-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..0607fbfab08 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.GetDatasetIdentification(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..cf1a8887bc3 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.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(configMapKey.Namespace, ownerReference.Name, string(ownerReference.UID)), + }, }, Data: data, } diff --git a/pkg/common/label.go b/pkg/common/label.go index 7d2b86f2c1b..6fd420ef9ff 100644 --- a/pkg/common/label.go +++ b/pkg/common/label.go @@ -34,6 +34,10 @@ const ( // i.e. fluid.io/dataset LabelAnnotationDataset = LabelAnnotationPrefix + "dataset" + // LabelAnnotationDatasetIdentification indicates the uuid of the dataset + // i.e. fluid.io/dataset-uuid + LabelAnnotationDatasetIdentification = LabelAnnotationDataset + "-identification" + // 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 55624b9807b..323db6104fc 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.PatchDatasetLabelToObjects(ctx.Client, + utils.GetDatasetIdentification(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) diff --git a/pkg/csi/plugins/nodeserver.go b/pkg/csi/plugins/nodeserver.go index 189fef5d3fc..1dce0e7cc38 100644 --- a/pkg/csi/plugins/nodeserver.go +++ b/pkg/csi/plugins/nodeserver.go @@ -344,7 +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. - fuseLabelKey := utils.GetFuseLabelName(namespace, name, runtimeInfo.GetNamespacedNameAlias()) + fuseLabelKey := utils.GetFuseLabelName(namespace, name, runtimeInfo.GetOwnerDatasetUID()) var labelsToModify common.LabelsToModify labelsToModify.Delete(fuseLabelKey) @@ -404,7 +404,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol 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.GetNamespacedNameAlias()) + 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 bfc43ae7fe1..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 = utils.GetFuseLabelName(e.runtimeInfo.GetNamespace(), e.runtimeInfo.GetName(), e.runtimeInfo.GetNamespacedNameAlias()) + 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 = utils.GetFuseLabelName(e.runtimeInfo.GetNamespace(), e.runtimeInfo.GetName(), e.runtimeInfo.GetNamespacedNameAlias()) + 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..8e6cb880ab6 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"` + OwnerDatasetIdentification string `yaml:"ownerDatasetIdentification,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..e55a4714ef4 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"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` + 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 bbf25f6c3ac..0282fed4536 100644 --- a/pkg/datamigrate/value.go +++ b/pkg/datamigrate/value.go @@ -25,7 +25,7 @@ import ( type DataMigrateValue struct { Name string `json:"name"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` 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..c735594c2a9 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.OwnerDatasetIdentification = utils.GetDatasetIdentification(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 29e4db5692e..c455c4dfbee 100644 --- a/pkg/ddc/alluxio/deprecated_label.go +++ b/pkg/ddc/alluxio/deprecated_label.go @@ -50,7 +50,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + 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", deprecatedCommonLabelName) diff --git a/pkg/ddc/alluxio/load_data.go b/pkg/ddc/alluxio/load_data.go index dd2a7e81fba..c867f28da4e 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..3e0ef5e497b 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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..4351fbeca3c 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/alluxio/runtime_info.go b/pkg/ddc/alluxio/runtime_info.go index 67e203ee7b5..b970a6e608d 100644 --- a/pkg/ddc/alluxio/runtime_info.go +++ b/pkg/ddc/alluxio/runtime_info.go @@ -47,7 +47,7 @@ func (e *AlluxioEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -61,7 +61,7 @@ func (e *AlluxioEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetupWithDataset(dataset) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) - e.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() diff --git a/pkg/ddc/alluxio/transform.go b/pkg/ddc/alluxio/transform.go index 68dff9c6759..d8efc3dc316 100644 --- a/pkg/ddc/alluxio/transform.go +++ b/pkg/ddc/alluxio/transform.go @@ -50,7 +50,7 @@ func (e *AlluxioEngine) transform(runtime *datav1alpha1.AlluxioRuntime) (value * } value.FullnameOverride = e.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(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 f84d143f870..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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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/types.go b/pkg/ddc/alluxio/types.go index 9baca9bd975..05dc4c5fd2b 100644 --- a/pkg/ddc/alluxio/types.go +++ b/pkg/ddc/alluxio/types.go @@ -28,7 +28,7 @@ import ( // The value yaml file type Alluxio struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/base/label.go b/pkg/ddc/base/label.go index 61a11c47ea1..c1878926905 100644 --- a/pkg/ddc/base/label.go +++ b/pkg/ddc/base/label.go @@ -24,23 +24,23 @@ import ( ) func (info *RuntimeInfo) GetLabelNameForMemory() string { - return utils.GetLabelNameForMemory(info.IsDeprecatedNodeLabel(), info.runtimeType, info.namespace, info.name, info.overLimitNamespacedNameAlias) + 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, info.overLimitNamespacedNameAlias) + 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, info.overLimitNamespacedNameAlias) + 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, info.overLimitNamespacedNameAlias) + 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, info.overLimitNamespacedNameAlias) + 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 @@ -50,7 +50,7 @@ func (info *RuntimeInfo) GetDatasetNumLabelName() string { // GetFuseLabelName gets the label indicating a fuse running on some node. func (info *RuntimeInfo) GetFuseLabelName() string { - return utils.GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, info.namespace, info.name, info.overLimitNamespacedNameAlias) + return utils.GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, info.namespace, info.name, info.ownerDatasetUID) } func (info *RuntimeInfo) GetExclusiveLabelValue() string { @@ -60,5 +60,5 @@ func (info *RuntimeInfo) GetExclusiveLabelValue() string { return exclusiveLabelValue } - return utils.GetNamespacedNameValueWithPrefix("", info.namespace, info.name, info.overLimitNamespacedNameAlias) + return utils.GetNamespacedNameValueWithPrefix("", info.namespace, info.name, info.ownerDatasetUID) } diff --git a/pkg/ddc/base/runtime.go b/pkg/ddc/base/runtime.go index b3cfcaf5272..b2ffce867b6 100644 --- a/pkg/ddc/base/runtime.go +++ b/pkg/ddc/base/runtime.go @@ -69,7 +69,7 @@ type RuntimeInfoInterface interface { GetNamespace() string - GetNamespacedNameAlias() string + GetOwnerDatasetUID() string GetRuntimeType() string @@ -81,7 +81,7 @@ type RuntimeInfoInterface interface { SetupWithDataset(dataset *datav1alpha1.Dataset) - SetNamespacedNameAlias(alias types.UID) + SetOwnerDatasetUID(alias types.UID) GetFuseNodeSelector() (nodeSelector map[string]string) @@ -110,10 +110,13 @@ var _ RuntimeInfoInterface = &RuntimeInfo{} // The real Runtime Info should implement type RuntimeInfo struct { - name string - namespace string - overLimitNamespacedNameAlias 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 @@ -279,8 +282,8 @@ func (info *RuntimeInfo) GetNamespace() string { return info.namespace } -func (info *RuntimeInfo) GetNamespacedNameAlias() string { - return info.overLimitNamespacedNameAlias +func (info *RuntimeInfo) GetOwnerDatasetUID() string { + return info.ownerDatasetUID } // GetRuntimeType gets runtime type @@ -299,11 +302,11 @@ func (info *RuntimeInfo) SetupWithDataset(dataset *datav1alpha1.Dataset) { } // SetupWithDataset determines if need to setup with the info of dataset -func (info *RuntimeInfo) SetNamespacedNameAlias(alias types.UID) { - if alias == "" { +func (info *RuntimeInfo) SetOwnerDatasetUID(datasetUID types.UID) { + if datasetUID == "" { return } - info.overLimitNamespacedNameAlias = string(alias) + info.ownerDatasetUID = string(datasetUID) } // SetFuseNodeSelector setups the fuse deploy mode @@ -544,7 +547,7 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (runtimeInfo R if runtimeInfo != nil { runtimeInfo.SetClient(client) - runtimeInfo.SetNamespacedNameAlias(dataset.UID) + 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..274a9a53776 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.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(runtime.GetNamespace(), runtime.GetName(), runtime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/ddc/efc/master_internal.go b/pkg/ddc/efc/master_internal.go index 3a938b0d77b..f5a372983ea 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/efc/runtime_info.go b/pkg/ddc/efc/runtime_info.go index 33033a49a88..2b94c93d9c3 100644 --- a/pkg/ddc/efc/runtime_info.go +++ b/pkg/ddc/efc/runtime_info.go @@ -53,7 +53,7 @@ func (e *EFCEngine) getRuntimeInfo() (info base.RuntimeInfoInterface, err error) dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -65,7 +65,7 @@ func (e *EFCEngine) getRuntimeInfo() (info base.RuntimeInfoInterface, err error) } e.runtimeInfo.SetupWithDataset(dataset) - e.runtimeInfo.SetNamespacedNameAlias(dataset.UID) + e.runtimeInfo.SetOwnerDatasetUID(dataset.UID) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) } diff --git a/pkg/ddc/efc/transform.go b/pkg/ddc/efc/transform.go index 4e31cc7024f..cb6a6cd3f9a 100644 --- a/pkg/ddc/efc/transform.go +++ b/pkg/ddc/efc/transform.go @@ -47,7 +47,7 @@ func (e *EFCEngine) transform(runtime *datav1alpha1.EFCRuntime) (value *EFC, err } value.FullnameOverride = e.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) err = e.transformMasters(runtime, dataset, value) if err != nil { @@ -217,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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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/types.go b/pkg/ddc/efc/types.go index f7f7dd6e615..34ed0c47777 100644 --- a/pkg/ddc/efc/types.go +++ b/pkg/ddc/efc/types.go @@ -27,7 +27,7 @@ import ( // The value yaml file type EFC struct { FullnameOverride string `yaml:"fullnameOverride"` - FullNamespacedNameOverride string `yaml:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `yaml:"ownerDatasetIdentification"` 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 ac66126df9f..29db93e4f4b 100644 --- a/pkg/ddc/goosefs/deprecated_label.go +++ b/pkg/ddc/goosefs/deprecated_label.go @@ -50,7 +50,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + 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", deprecatedCommonLabelName) diff --git a/pkg/ddc/goosefs/load_data.go b/pkg/ddc/goosefs/load_data.go index 54ef280ae82..32c899882fb 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..192c9aec19a 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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..cbd8416d35b 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/goosefs/runtime_info.go b/pkg/ddc/goosefs/runtime_info.go index 560bd58b291..1ae55b7320c 100644 --- a/pkg/ddc/goosefs/runtime_info.go +++ b/pkg/ddc/goosefs/runtime_info.go @@ -49,7 +49,7 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -63,7 +63,7 @@ func (e *GooseFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetupWithDataset(dataset) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) - e.runtimeInfo.SetNamespacedNameAlias(dataset.UID) + e.runtimeInfo.SetOwnerDatasetUID(dataset.UID) // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() diff --git a/pkg/ddc/goosefs/transform.go b/pkg/ddc/goosefs/transform.go index 3e87baa9d79..beac52cb9d9 100644 --- a/pkg/ddc/goosefs/transform.go +++ b/pkg/ddc/goosefs/transform.go @@ -45,7 +45,7 @@ func (e *GooseFSEngine) transform(runtime *datav1alpha1.GooseFSRuntime) (value * value = &GooseFS{} value.FullnameOverride = e.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(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 70ba98d5c33..4994848bd73 100644 --- a/pkg/ddc/goosefs/transform_fuse.go +++ b/pkg/ddc/goosefs/transform_fuse.go @@ -87,7 +87,7 @@ func (e *GooseFSEngine) transformFuse(runtime *datav1alpha1.GooseFSRuntime, data value.Fuse.NodeSelector = map[string]string{} } - value.Fuse.NodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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/types.go b/pkg/ddc/goosefs/types.go index 969a6570989..010aa60bdc2 100644 --- a/pkg/ddc/goosefs/types.go +++ b/pkg/ddc/goosefs/types.go @@ -27,7 +27,7 @@ import ( // The value yaml file type GooseFS struct { FullnameOverride string `yaml:"fullnameOverride"` - FullNamespacedNameOverride string `yaml:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `yaml:"ownerDatasetIdentification"` 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 5c697819352..6e804eb4f7e 100644 --- a/pkg/ddc/jindo/deprecated_label.go +++ b/pkg/ddc/jindo/deprecated_label.go @@ -49,7 +49,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + 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", deprecatedCommonLabelName) diff --git a/pkg/ddc/jindo/load_data.go b/pkg/ddc/jindo/load_data.go index b14f19d30ce..98193b85604 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..79219d6e232 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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..7eaf010df80 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigmapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/jindo/runtime_info.go b/pkg/ddc/jindo/runtime_info.go index db6fcb32cb0..6180775a007 100644 --- a/pkg/ddc/jindo/runtime_info.go +++ b/pkg/ddc/jindo/runtime_info.go @@ -49,7 +49,7 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -63,7 +63,7 @@ func (e *JindoEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetupWithDataset(dataset) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) - e.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelName() diff --git a/pkg/ddc/jindo/transform.go b/pkg/ddc/jindo/transform.go index ef573721012..fd7ede575dd 100644 --- a/pkg/ddc/jindo/transform.go +++ b/pkg/ddc/jindo/transform.go @@ -120,7 +120,7 @@ func (e *JindoEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *Jind }, } - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) @@ -464,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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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 6bbf4948782..3d91b703dee 100644 --- a/pkg/ddc/jindo/types.go +++ b/pkg/ddc/jindo/types.go @@ -23,7 +23,7 @@ import ( ) type Jindo struct { - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` 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 a361c0c50ac..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: utils.GetFuseLabelName(e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()), + Key: utils.GetFuseLabelName(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()), Operator: corev1.NodeSelectorOpIn, Values: []string{"true"}, }, diff --git a/pkg/ddc/jindocache/deprecated_label.go b/pkg/ddc/jindocache/deprecated_label.go index 90577c4a6ef..aa8901f1811 100644 --- a/pkg/ddc/jindocache/deprecated_label.go +++ b/pkg/ddc/jindocache/deprecated_label.go @@ -50,7 +50,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + 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", deprecatedCommonLabelName) diff --git a/pkg/ddc/jindocache/load_data.go b/pkg/ddc/jindocache/load_data.go index b422bd7f2b3..1e8536afeff 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..c244feca2f7 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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..1fe41d037d7 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/jindocache/runtime_info.go b/pkg/ddc/jindocache/runtime_info.go index 34456378d9f..2182089687b 100644 --- a/pkg/ddc/jindocache/runtime_info.go +++ b/pkg/ddc/jindocache/runtime_info.go @@ -48,7 +48,7 @@ func (e *JindoCacheEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -62,7 +62,7 @@ func (e *JindoCacheEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetupWithDataset(dataset) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) - e.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() diff --git a/pkg/ddc/jindocache/transform.go b/pkg/ddc/jindocache/transform.go index d0cfde5c086..b40689cb93b 100644 --- a/pkg/ddc/jindocache/transform.go +++ b/pkg/ddc/jindocache/transform.go @@ -154,7 +154,7 @@ func (e *JindoCacheEngine) transform(runtime *datav1alpha1.JindoRuntime) (value }, } - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) @@ -907,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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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/types.go b/pkg/ddc/jindocache/types.go index 01c5736e5c0..2c4d9bf768c 100644 --- a/pkg/ddc/jindocache/types.go +++ b/pkg/ddc/jindocache/types.go @@ -23,7 +23,7 @@ import ( type Jindo struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` 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 49fac5663a3..7f8956be394 100644 --- a/pkg/ddc/jindofsx/deprecated_label.go +++ b/pkg/ddc/jindofsx/deprecated_label.go @@ -50,7 +50,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + 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", deprecatedCommonLabelName) diff --git a/pkg/ddc/jindofsx/load_data.go b/pkg/ddc/jindofsx/load_data.go index b6b3ac04102..47b4e4e6364 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..e958898c7a2 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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..6886093014b 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/jindofsx/runtime_info.go b/pkg/ddc/jindofsx/runtime_info.go index 8cb5279880b..557a4bf7c65 100644 --- a/pkg/ddc/jindofsx/runtime_info.go +++ b/pkg/ddc/jindofsx/runtime_info.go @@ -48,7 +48,7 @@ func (e *JindoFSxEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -62,7 +62,7 @@ func (e *JindoFSxEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.runtimeInfo.SetupWithDataset(dataset) e.Log.Info("Setup with dataset done", "exclusive", e.runtimeInfo.IsExclusive()) - e.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) // Check if the runtime is using deprecated labels isLabelDeprecated, err := e.HasDeprecatedCommonLabelname() diff --git a/pkg/ddc/jindofsx/transform.go b/pkg/ddc/jindofsx/transform.go index 2ae0b5ce96f..dbc761cbf04 100644 --- a/pkg/ddc/jindofsx/transform.go +++ b/pkg/ddc/jindofsx/transform.go @@ -154,7 +154,7 @@ func (e *JindoFSxEngine) transform(runtime *datav1alpha1.JindoRuntime) (value *J }, } - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(e.namespace, e.name, e.runtimeInfo.GetOwnerDatasetUID()) e.transformNetworkMode(runtime, value) err = e.transformHadoopConfig(runtime, value) @@ -791,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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "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/types.go b/pkg/ddc/jindofsx/types.go index 4a7e4ef8b13..c91d743ace5 100644 --- a/pkg/ddc/jindofsx/types.go +++ b/pkg/ddc/jindofsx/types.go @@ -23,7 +23,7 @@ import ( type Jindo struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` 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..162fe35a00c 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, + OwnerDatasetIdentification: utils.GetDatasetIdentification(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..76a2a3ec09a 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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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", + OwnerDatasetIdentification: "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 a28b0081f2d..5a55224b307 100644 --- a/pkg/ddc/juicefs/data_migrate.go +++ b/pkg/ddc/juicefs/data_migrate.go @@ -174,7 +174,7 @@ func (j *JuiceFSEngine) generateDataMigrateValueFile(r cruntime.ReconcileRequest DataMigrateInfo: dataMigrateInfo, } dataMigrateValue.Owner = transformer.GenerateOwnerReferenceFromObject(dataMigrate) - dataMigrateValue.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", j.namespace, j.name, j.runtimeInfo.GetNamespacedNameAlias()) + dataMigrateValue.OwnerDatasetIdentification = utils.GetDatasetIdentification(j.namespace, j.name, j.runtimeInfo.GetOwnerDatasetUID()) // 6. create the value file data, err := yaml.Marshal(dataMigrateValue) diff --git a/pkg/ddc/juicefs/deprecated_label.go b/pkg/ddc/juicefs/deprecated_label.go index 13cdd557f11..8dbe9b3f74a 100644 --- a/pkg/ddc/juicefs/deprecated_label.go +++ b/pkg/ddc/juicefs/deprecated_label.go @@ -44,7 +44,7 @@ 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) - deprecatedCommonLabelName := utils.GetCommonLabelName(true, j.namespace, j.name, j.runtimeInfo.GetNamespacedNameAlias()) + 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) diff --git a/pkg/ddc/juicefs/master_internal.go b/pkg/ddc/juicefs/master_internal.go index 6d4d794a092..8bcf2d13e48 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(j.Client, j.getHelmValuesConfigMapName(), j.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/juicefs/runtime_info.go b/pkg/ddc/juicefs/runtime_info.go index 8bff1896419..54521d331e4 100644 --- a/pkg/ddc/juicefs/runtime_info.go +++ b/pkg/ddc/juicefs/runtime_info.go @@ -49,7 +49,7 @@ func (j *JuiceFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(j.Client, j.name, j.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - j.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + j.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { j.Log.Info("Dataset is notfound", "name", j.name, "namespace", j.namespace) @@ -63,7 +63,7 @@ func (j *JuiceFSEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { j.runtimeInfo.SetupWithDataset(dataset) j.Log.Info("Setup with dataset done", "exclusive", j.runtimeInfo.IsExclusive()) - j.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + j.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) // Check if the runtime is using deprecated labels isLabelDeprecated, err := j.HasDeprecatedCommonLabelName() diff --git a/pkg/ddc/juicefs/transform.go b/pkg/ddc/juicefs/transform.go index 36bf84b7ac1..55117dcb666 100644 --- a/pkg/ddc/juicefs/transform.go +++ b/pkg/ddc/juicefs/transform.go @@ -52,7 +52,7 @@ func (j *JuiceFSEngine) transform(runtime *datav1alpha1.JuiceFSRuntime) (value * } value.FullnameOverride = j.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", j.namespace, j.name, j.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(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 911fbb7f2f9..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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, j.runtimeInfo.GetNamespacedNameAlias())] = "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/type.go b/pkg/ddc/juicefs/type.go index a08c3114611..9ed2a40e419 100644 --- a/pkg/ddc/juicefs/type.go +++ b/pkg/ddc/juicefs/type.go @@ -26,7 +26,7 @@ import ( // JuiceFS The value json file type JuiceFS struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` Edition string `json:"edition,omitempty"` Source string `json:"source,omitempty"` diff --git a/pkg/ddc/thin/master_internal.go b/pkg/ddc/thin/master_internal.go index 82c67fda791..f6fa9fe5bce 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(t.Client, t.getHelmValuesConfigMapName(), t.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/thin/referencedataset/cm.go b/pkg/ddc/thin/referencedataset/cm.go index 1eba74b697b..97a183aa894 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.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(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 4539715d48c..f7894ec20a6 100644 --- a/pkg/ddc/thin/referencedataset/runtime.go +++ b/pkg/ddc/thin/referencedataset/runtime.go @@ -102,7 +102,7 @@ func (e *ReferenceDatasetEngine) getRuntimeInfo() (base.RuntimeInfoInterface, er // set exclusive mode // TODO: how to handle the exclusive mode ? e.runtimeInfo.SetupWithDataset(dataset) - e.runtimeInfo.SetNamespacedNameAlias(dataset.UID) + 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 f9580671f91..095ab905b96 100644 --- a/pkg/ddc/thin/referencedataset/volume.go +++ b/pkg/ddc/thin/referencedataset/volume.go @@ -111,7 +111,8 @@ func createFusePersistentVolume(client client.Client, virtualRuntime base.Runtim ObjectMeta: metav1.ObjectMeta{ Name: virtualPvName, Labels: map[string]string{ - virtualRuntime.GetCommonLabelName(): "true", + virtualRuntime.GetCommonLabelName(): "true", + common.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(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 - utils.GetNamespacedNameValueWithPrefix(common.LabelAnnotationStorageCapacityPrefix, virtualNamespace, virtualName, virtualRuntime.GetNamespacedNameAlias()): "true", + utils.GetNamespacedNameValueWithPrefix(common.LabelAnnotationStorageCapacityPrefix, virtualNamespace, virtualName, virtualRuntime.GetOwnerDatasetUID()): "true", common.LabelAnnotationDatasetReferringName: runtimePVC.Name, common.LabelAnnotationDatasetReferringNameSpace: runtimePVC.Namespace, + common.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(virtualNamespace, virtualName, virtualRuntime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/ddc/thin/runtime_info.go b/pkg/ddc/thin/runtime_info.go index 72d73ffa4bc..f2e2649be61 100644 --- a/pkg/ddc/thin/runtime_info.go +++ b/pkg/ddc/thin/runtime_info.go @@ -63,7 +63,7 @@ func (t *ThinEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(t.Client, t.name, t.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - t.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + t.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { t.Log.Info("Dataset is notfound", "name", t.name, "namespace", t.namespace) @@ -75,7 +75,7 @@ func (t *ThinEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { } t.runtimeInfo.SetupWithDataset(dataset) - t.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + t.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) t.Log.Info("Setup with dataset done", "exclusive", t.runtimeInfo.IsExclusive()) } diff --git a/pkg/ddc/thin/transform.go b/pkg/ddc/thin/transform.go index f0d7b1df6bd..ee4ddff294f 100644 --- a/pkg/ddc/thin/transform.go +++ b/pkg/ddc/thin/transform.go @@ -51,7 +51,7 @@ func (t *ThinEngine) transform(runtime *datav1alpha1.ThinRuntime, profile *datav } value.FullnameOverride = t.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", t.namespace, t.name, t.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(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 7dd70171e22..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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, t.runtimeInfo.GetNamespacedNameAlias())] = "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/type.go b/pkg/ddc/thin/type.go index d2f6f662add..fe05beacc52 100644 --- a/pkg/ddc/thin/type.go +++ b/pkg/ddc/thin/type.go @@ -24,7 +24,7 @@ import ( type ThinValue struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/ddc/vineyard/master_internal.go b/pkg/ddc/vineyard/master_internal.go index e96cc2b9e32..41a4fec48e2 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 + ownerDatasetIdentification := utils.GetDatasetIdentification(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetOwnerDatasetUID()) + err = kubeclient.CreateConfigMap(e.Client, e.getConfigmapName(), e.namespace, "data", data, ownerDatasetIdentification) if err != nil { return } diff --git a/pkg/ddc/vineyard/runtime_info.go b/pkg/ddc/vineyard/runtime_info.go index e4f72b56e57..2f7a1470e43 100644 --- a/pkg/ddc/vineyard/runtime_info.go +++ b/pkg/ddc/vineyard/runtime_info.go @@ -48,7 +48,7 @@ func (e *VineyardEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { dataset, err := utils.GetDataset(e.Client, e.name, e.namespace) if err != nil { if len(runtime.GetOwnerReferences()) > 0 { - e.runtimeInfo.SetNamespacedNameAlias(runtime.GetOwnerReferences()[0].UID) + e.runtimeInfo.SetOwnerDatasetUID(runtime.GetOwnerReferences()[0].UID) } if utils.IgnoreNotFound(err) == nil { e.Log.Info("Dataset is notfound", "name", e.name, "namespace", e.namespace) @@ -58,7 +58,7 @@ func (e *VineyardEngine) getRuntimeInfo() (base.RuntimeInfoInterface, error) { e.Log.Info("Failed to get dataset when getruntimeInfo") return e.runtimeInfo, err } - e.runtimeInfo.SetNamespacedNameAlias(dataset.GetUID()) + e.runtimeInfo.SetOwnerDatasetUID(dataset.GetUID()) } return e.runtimeInfo, nil diff --git a/pkg/ddc/vineyard/transform.go b/pkg/ddc/vineyard/transform.go index 1e6b77cc1cf..25d8694b9e6 100644 --- a/pkg/ddc/vineyard/transform.go +++ b/pkg/ddc/vineyard/transform.go @@ -41,7 +41,7 @@ func (e *VineyardEngine) transform(runtime *datav1alpha1.VineyardRuntime) (value Owner: transformer.GenerateOwnerReferenceFromObject(runtime), } value.FullnameOverride = e.name - value.FullNamespacedNameOverride = utils.GetNamespacedNameValueWithPrefix("", e.namespace, e.name, e.runtimeInfo.GetNamespacedNameAlias()) + value.OwnerDatasetIdentification = utils.GetDatasetIdentification(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[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetNamespacedNameAlias())] = "true" + nodeSelector[utils.GetFuseLabelName(runtime.Namespace, runtime.Name, e.runtimeInfo.GetOwnerDatasetUID())] = "true" return nodeSelector } diff --git a/pkg/ddc/vineyard/type.go b/pkg/ddc/vineyard/type.go index bb4b73c8f71..58219d00695 100644 --- a/pkg/ddc/vineyard/type.go +++ b/pkg/ddc/vineyard/type.go @@ -24,7 +24,7 @@ import ( // The value yaml file type Vineyard struct { FullnameOverride string `json:"fullnameOverride"` - FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"` + OwnerDatasetIdentification string `json:"ownerDatasetIdentification"` common.ImageInfo `json:",inline"` common.UserInfo `json:",inline"` diff --git a/pkg/utils/crtl_utils.go b/pkg/utils/crtl_utils.go index 1fa354893fa..08b959ac43b 100644 --- a/pkg/utils/crtl_utils.go +++ b/pkg/utils/crtl_utils.go @@ -134,6 +134,11 @@ func ContainsOwners(owners []metav1.OwnerReference, dataset *datav1alpha1.Datase return false } +func ContainsLabel(labels map[string]string, labelKey string) bool { + _, exit := labels[labelKey] + return exit +} + // 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/volume/create.go b/pkg/utils/dataset/volume/create.go index 4e125c74d86..aa4e4c1c08b 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.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(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.LabelAnnotationDatasetIdentification: utils.GetDatasetIdentification(runtime.GetNamespace(), runtime.GetName(), runtime.GetOwnerDatasetUID()), }, Annotations: common.ExpectedFluidAnnotations, }, diff --git a/pkg/utils/dataset_runtime.go b/pkg/utils/dataset_runtime.go index 73f9fa7aaa4..67433683201 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.LabelAnnotationDatasetIdentification: GetDatasetIdentification(dataset.GetNamespace(), dataset.GetName(), string(dataset.GetUID())), + }, }, } err = client.Create(context.TODO(), &runtime) diff --git a/pkg/utils/kubeclient/configmap.go b/pkg/utils/kubeclient/configmap.go index 504ddf84a96..9f8f3162f65 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.LabelAnnotationDatasetIdentification] = utils.GetDatasetIdentification(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, ownerDatasetIdentification string) (err error) { configMap := &v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, + Labels: map[string]string{ + common.LabelAnnotationDatasetIdentification: ownerDatasetIdentification, + }, }, 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/label.go b/pkg/utils/label.go index cbc759eb83c..56c49fb8c30 100644 --- a/pkg/utils/label.go +++ b/pkg/utils/label.go @@ -114,7 +114,7 @@ func ChangeNodeLabelWithPatchMode(cli client.Client, node *v1.Node, labelsToModi return PatchLabels(cli, node, labelsToModify) } -func GetStorageLabelName(read common.ReadType, storage common.StorageType, isDeprecated bool, runtimeType string, namespace, name, overLimitNamespacedNameAlias 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 @@ -122,49 +122,49 @@ func GetStorageLabelName(read common.ReadType, storage common.StorageType, isDep prefix = prefix + string(read) + runtimeType + "-" + string(storage) - return GetNamespacedNameValueWithPrefix(prefix, namespace, name, overLimitNamespacedNameAlias) + return GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) } -func GetLabelNameForMemory(isDeprecated bool, runtimeType string, namespace, name, overLimitNamespacedNameAlias 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 GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, overLimitNamespacedNameAlias) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetLabelNameForDisk(isDeprecated bool, runtimeType string, namespace, name, overLimitNamespacedNameAlias 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 GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, overLimitNamespacedNameAlias) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetLabelNameForTotal(isDeprecated bool, runtimeType string, namespace, name, overLimitNamespacedNameAlias 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 GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, overLimitNamespacedNameAlias) + return GetStorageLabelName(read, storage, isDeprecated, runtimeType, namespace, name, ownerDatasetUID) } -func GetCommonLabelName(isDeprecated bool, namespace, name, overLimitNamespacedNameAlias string) string { +func GetCommonLabelName(isDeprecated bool, namespace, name, ownerDatasetUID string) string { prefix := common.LabelAnnotationStorageCapacityPrefix if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix } - return GetNamespacedNameValueWithPrefix(prefix, namespace, name, overLimitNamespacedNameAlias) + return GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) } -func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace, name, overLimitNamespacedNameAlias string) string { +func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace, name, ownerDatasetUID string) string { prefix := common.LabelAnnotationStorageCapacityPrefix if isDeprecated { prefix = deprecated.LabelAnnotationStorageCapacityPrefix @@ -172,11 +172,11 @@ func GetRuntimeLabelName(isDeprecated bool, runtimeType string, namespace, name, prefix = prefix + runtimeType + "-" - return GetNamespacedNameValueWithPrefix(prefix, namespace, name, overLimitNamespacedNameAlias) + return GetNamespacedNameValueWithPrefix(prefix, namespace, name, ownerDatasetUID) } -func GetFuseLabelName(namespace, name, overLimitNamespacedNameAlias string) string { - return GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, namespace, name, overLimitNamespacedNameAlias) +func GetFuseLabelName(namespace, name, ownerDatasetUID string) string { + return GetNamespacedNameValueWithPrefix(common.LabelAnnotationFusePrefix, namespace, name, ownerDatasetUID) } func GetExclusiveKey() string { @@ -186,7 +186,7 @@ func GetExclusiveKey() string { // 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, overLimitNamespacedNameAlias string) (fullNamespacedNameWithPrefix string) { +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 @@ -194,12 +194,44 @@ func GetNamespacedNameValueWithPrefix(prefix, namespace, name, overLimitNamespac return } - if overLimitNamespacedNameAlias == "" { - log.Info("The overLimitNamespacedNameAlias is absent, fall back to original value which causes the resource creation failed by scheme validation", "key", fmt.Sprintf("%s-%s", namespace, name)) + 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, overLimitNamespacedNameAlias) + fullNamespacedNameWithPrefix = fmt.Sprintf("%s%s", prefix, ownerDatasetUID) return } + +func GetDatasetIdentification(namespace, name, ownerDatasetUID string) (fullNamespacedNameWithPrefix string) { + return GetNamespacedNameValueWithPrefix("", namespace, name, ownerDatasetUID) +} + +func PatchDatasetLabelToObjects(cli client.Client, datasetLabelValue string, objs ...client.Object) (errs []error) { + for _, obj := range objs { + if !ContainsLabel(obj.GetLabels(), common.LabelAnnotationDatasetIdentification) { + labelValuePair := map[string]string{ + common.LabelAnnotationDatasetIdentification: datasetLabelValue, + } + + metadata := map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": labelValuePair, + }, + } + + patchByteData, err := json.Marshal(metadata) + if err != nil { + errs = append(errs, err) + } + + 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) + } + } + } + return +} diff --git a/pkg/utils/label_test.go b/pkg/utils/label_test.go index 69abf139cae..6166a1e8a9f 100644 --- a/pkg/utils/label_test.go +++ b/pkg/utils/label_test.go @@ -184,8 +184,8 @@ func TestChangeNodeLabelWithPatchModel(t *testing.T) { func TestGetFullNamespacedNameWithPrefixValue(t *testing.T) { tests := []struct { - prefix, namespace, name, overLimitNamespacedNameAlias string - expected string + prefix, namespace, name, ownerDatasetUID string + expected string }{ {"normal-", "default", "test-dataset", "", "normal-default-test-dataset"}, {"overlimit-", "namespace-ajsdjikebnfacdsvwcaxqcackjascnbaksjcnakjscnackjasn", "dataset-demo", "58df5bd9cc", "overlimit-58df5bd9cc"}, @@ -193,7 +193,7 @@ func TestGetFullNamespacedNameWithPrefixValue(t *testing.T) { } for _, test := range tests { - result := GetNamespacedNameValueWithPrefix(test.prefix, test.namespace, test.name, test.overLimitNamespacedNameAlias) + 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) }