Skip to content

Commit

Permalink
Feature: add datasetReferenceLabel to all the resources created by fluid
Browse files Browse the repository at this point in the history
Signed-off-by: jiuyu <guotongyu.gty@alibaba-inc.com>
  • Loading branch information
jiuyu committed Jan 16, 2025
1 parent 228af51 commit 56fba58
Show file tree
Hide file tree
Showing 71 changed files with 299 additions and 190 deletions.
1 change: 1 addition & 0 deletions charts/alluxio/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/alluxio/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/alluxio/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: alluxio-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -60,8 +59,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: alluxio-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/efc/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: efc-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -45,7 +44,7 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: efc-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset: {{ .Values.OwnedDatasetReference }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- if .Values.worker.labels }}
{{- range $key, $val := .Values.worker.labels }}
Expand Down
2 changes: 1 addition & 1 deletion charts/fluid-datamigrate/juicefs/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.OwnedDatasetReference }}
{{- include "library.fluid.labels" . | nindent 8 }}
{{- if .Values.datamigrate.labels }}
{{- range $key, $val := .Values.datamigrate.labels }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
metadata:
labels:
app: {{ printf "%s-workers" .Release.Name }}
fluid.io/operation: migrate-{{ .Values.fullNamespacedNameOverride }}
fluid.io/operation: migrate-{{ .Values.OwnedDatasetReference }}
spec:
containers:
- name: worker
Expand Down
1 change: 1 addition & 0 deletions charts/goosefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions charts/goosefs/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/goosefs/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: goosefs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
spec:
Expand All @@ -37,8 +36,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: goosefs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 8 }}
spec:
enableServiceLinks: false
hostNetwork: {{ $hostNetwork }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindocache/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindocache/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/jindocache/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -49,8 +48,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindofs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindofs/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/jindofs/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -44,8 +43,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 8 }}
{{- if .Values.labels }}
{{ toYaml .Values.labels | trim | indent 8 }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindofsx/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/jindofsx/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/jindofsx/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -49,8 +48,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: jindofs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/juicefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions charts/juicefs/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: juicefs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -48,8 +47,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: juicefs-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/library/templates/_recommended_labels.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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: {{ .Values.OwnedDatasetReference }}
{{- end }}
1 change: 1 addition & 0 deletions charts/thin/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions charts/thin/templates/worker/statefuleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: thin-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 4 }}
ownerReferences:
Expand Down Expand Up @@ -41,8 +40,8 @@ spec:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: thin-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
fluid.io/dataset-placement: {{ .Values.placement }}
{{- include "library.fluid.labels" . | nindent 8 }}
spec:
{{- if .Values.worker.imagePullSecrets }}
imagePullSecrets:
Expand Down
1 change: 1 addition & 0 deletions charts/vineyard/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/vineyard/templates/master/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 4 additions & 5 deletions charts/vineyard/templates/worker/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: vineyard-worker
fluid.io/dataset: {{ .Values.fullNamespacedNameOverride }}
{{- include "library.fluid.labels" . | nindent 4 }}
{{- if .Values.owner.enabled }}
ownerReferences:
Expand All @@ -46,7 +45,7 @@ spec:
chart: {{ $chart }}
release: {{ .Release.Name }}
role: vineyard-worker
app.kubernetes.io/instance: {{ .Values.fullNamespacedNameOverride }}-worker
app.kubernetes.io/instance: {{ .Values.OwnedDatasetReference }}-worker
template:
metadata:
annotations:
Expand All @@ -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
app.kubernetes.io/instance: {{ .Values.OwnedDatasetReference }}-worker
{{- include "library.fluid.labels" . | nindent 8 }}
{{- if .Values.worker.labels }}
{{- range $key, $val := .Values.worker.labels }}
{{ $key | quote }}: {{ $val | quote }}
Expand Down Expand Up @@ -215,5 +214,5 @@ spec:
- key: app.kubernetes.io/instance
operator: In
values:
- {{ .Values.fullNamespacedNameOverride }}-worker
- {{ .Values.OwnedDatasetReference }}-worker
topologyKey: "kubernetes.io/hostname"
1 change: 0 additions & 1 deletion pkg/application/inject/fuse/poststart/check_fuse_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package poststart

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
Expand Down
5 changes: 5 additions & 0 deletions pkg/application/inject/fuse/poststart/script_gen_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package poststart

import (
"github.com/fluid-cloudnative/fluid/pkg/common"
"github.com/fluid-cloudnative/fluid/pkg/utils"
"strings"

corev1 "k8s.io/api/core/v1"
Expand All @@ -41,6 +43,9 @@ func (helper *scriptGeneratorHelper) BuildConfigMap(ownerReference metav1.OwnerR
Name: configMapKey.Name,
Namespace: configMapKey.Namespace,
OwnerReferences: []metav1.OwnerReference{ownerReference},
Labels: map[string]string{
common.LabelAnnotationDataset: utils.GetDatasetReferenceValue(configMapKey.Namespace, ownerReference.Name, string(ownerReference.UID)),
},
},
Data: data,
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/common/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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"
Expand Down
8 changes: 8 additions & 0 deletions pkg/controllers/runtime_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetDatasetReferenceValue(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)
Expand Down Expand Up @@ -332,6 +339,7 @@ func (r *RuntimeReconciler) AddOwnerAndRequeue(ctx cruntime.ReconcileRequestCont
Name: dataset.Name,
UID: dataset.UID,
}))

if err := r.Update(ctx, ctx.Runtime); err != nil {
ctx.Log.Error(err, "Failed to add ownerreference", "StatusUpdateError", ctx)
return utils.RequeueIfError(err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/datamigrate/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
)

type DataMigrateValue struct {
Name string `json:"name"`
FullNamespacedNameOverride string `json:"fullNamespacedNameOverride"`
Owner *common.OwnerReference `json:"owner,omitempty"`
DataMigrateInfo DataMigrateInfo `json:"datamigrate"`
Name string `json:"name"`
OwnedDatasetReference string `json:"ownedDatasetReference"`
Owner *common.OwnerReference `json:"owner,omitempty"`
DataMigrateInfo DataMigrateInfo `json:"datamigrate"`
}

type DataMigrateInfo struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/ddc/alluxio/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
referenceDatasetLabelValue := utils.GetDatasetReferenceValue(runtimeInfo.GetNamespace(), runtimeInfo.GetName(), runtimeInfo.GetNamespacedNameAlias())
err = kubeclient.CreateConfigMap(e.Client, e.getHelmValuesConfigMapName(), e.namespace, "data", data, referenceDatasetLabelValue)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 56fba58

Please sign in to comment.