-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add Cron and OnEvent policy support to DataProcess #5969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7358b02
745137e
1259d80
8076671
d330bef
ed9b599
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| {{- if eq (lower .Values.dataProcess.policy) "cron" }} | ||
| apiVersion: {{ ternary "batch/v1" "batch/v1beta1" (.Capabilities.APIVersions.Has "batch/v1/CronJob") }} | ||
| kind: CronJob | ||
| metadata: | ||
| name: {{ printf "%s-job" .Release.Name }} | ||
| labels: | ||
| release: {{ .Release.Name }} | ||
| role: dataprocess-cronjob | ||
| app: fluid-dataprocess | ||
| targetDataset: {{ required "targetDataset should be set" .Values.dataProcess.targetDataset }} | ||
| fluid.io/jobPolicy: cron | ||
| {{- include "library.fluid.labels" . | nindent 4 }} | ||
| ownerReferences: | ||
| {{- if .Values.owner.enabled }} | ||
| - apiVersion: {{ .Values.owner.apiVersion }} | ||
| blockOwnerDeletion: {{ .Values.owner.blockOwnerDeletion }} | ||
| controller: {{ .Values.owner.controller }} | ||
| kind: {{ .Values.owner.kind }} | ||
| name: {{ .Values.owner.name }} | ||
| uid: {{ .Values.owner.uid }} | ||
| {{- end }} | ||
| spec: | ||
| schedule: "{{ .Values.dataProcess.schedule }}" | ||
| jobTemplate: | ||
| spec: | ||
| backoffLimit: 3 | ||
| completions: 1 | ||
| parallelism: 1 | ||
| template: | ||
| metadata: | ||
| name: {{ printf "%s-process" .Release.Name }} | ||
| annotations: | ||
| sidecar.istio.io/inject: "false" | ||
| {{- if .Values.dataProcess.annotations }} | ||
| {{ toYaml .Values.dataProcess.annotations | nindent 12 }} | ||
| {{- end }} | ||
| labels: | ||
| release: {{ .Release.Name }} | ||
| role: dataprocess-pod | ||
| app: fluid-dataprocess | ||
| cronjob: {{ printf "%s-job" .Release.Name }} | ||
| targetDataset: {{ required "targetDataset should be set" .Values.dataProcess.targetDataset }} | ||
| {{- include "library.fluid.labels" . | nindent 12 }} | ||
| {{- if .Values.dataProcess.labels }} | ||
| {{ toYaml .Values.dataProcess.labels | nindent 12 }} | ||
| {{- end }} | ||
| spec: | ||
| {{- if .Values.dataProcess.serviceAccountName }} | ||
| serviceAccountName: {{ .Values.dataProcess.serviceAccountName | quote }} | ||
| {{- end }} | ||
| {{- if .Values.dataProcess.jobProcessor.podSpec }} | ||
| {{- toYaml .Values.dataProcess.jobProcessor.podSpec | nindent 10 }} | ||
| {{- else if .Values.dataProcess.scriptProcessor }} | ||
| restartPolicy: {{ .Values.dataProcess.scriptProcessor.restartPolicy | default "Never" | quote }} | ||
| containers: | ||
| - name: script-processor | ||
| image: {{ required "DataProcess image should be set" .Values.dataProcess.scriptProcessor.image }} | ||
| imagePullPolicy: {{ .Values.dataProcess.scriptProcessor.imagePullPolicy }} | ||
| {{- if .Values.dataProcess.scriptProcessor.command }} | ||
| command: | ||
| {{ toYaml .Values.dataProcess.scriptProcessor.command | nindent 14 }} | ||
| {{- end }} | ||
| args: ["/fluid-scripts/preprocess.sh"] | ||
| {{- if .Values.dataProcess.scriptProcessor.resources}} | ||
|
Check warning on line 64 in charts/fluid-dataprocess/common/templates/cronjob.yaml
|
||
| resources: | ||
| {{- toYaml .Values.dataProcess.scriptProcessor.resources | nindent 16}} | ||
|
Check warning on line 66 in charts/fluid-dataprocess/common/templates/cronjob.yaml
|
||
| {{- end }} | ||
| {{- if .Values.dataProcess.scriptProcessor.envs }} | ||
| env: | ||
| {{ toYaml .Values.dataProcess.scriptProcessor.envs | nindent 14 }} | ||
| {{- end }} | ||
| volumeMounts: | ||
| - name: script-cm-vol | ||
| mountPath: /fluid-scripts/preprocess.sh | ||
| subPath: preprocess.sh | ||
| {{- if .Values.dataProcess.scriptProcessor.volumeMounts }} | ||
| {{- toYaml .Values.dataProcess.scriptProcessor.volumeMounts | nindent 16 }} | ||
| {{- end }} | ||
| {{- if .Values.dataProcess.scriptProcessor.affinity }} | ||
| affinity: | ||
| {{ toYaml .Values.dataProcess.scriptProcessor.affinity | indent 12 }} | ||
| {{- end }} | ||
| volumes: | ||
| - name: script-cm-vol | ||
| configMap: | ||
| name: {{ .Release.Name }}-scripts | ||
| {{- if .Values.dataProcess.scriptProcessor.volumes }} | ||
| {{- toYaml .Values.dataProcess.scriptProcessor.volumes | nindent 12 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -201,6 +201,27 @@ func (r *dataProcessOperation) Validate(ctx runtime.ReconcileRequestContext) ([] | |||||||||||||||||||||||||||||||||||||||||||||
| }, err | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // DataProcess with Cron policy must specify a non-empty schedule | ||||||||||||||||||||||||||||||||||||||||||||||
| if dataProcess.Spec.Policy == datav1alpha1.Cron && dataProcess.Spec.Schedule == "" { | ||||||||||||||||||||||||||||||||||||||||||||||
| r.Recorder.Eventf(dataProcess, | ||||||||||||||||||||||||||||||||||||||||||||||
| corev1.EventTypeWarning, | ||||||||||||||||||||||||||||||||||||||||||||||
| common.DataProcessScheduleNotSpecified, | ||||||||||||||||||||||||||||||||||||||||||||||
| "DataProcess(%s)'s policy is Cron but spec.schedule is not specified", | ||||||||||||||||||||||||||||||||||||||||||||||
| dataProcess.Name, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| err := fmt.Errorf("DataProcess(%s/%s)'s policy is Cron but spec.schedule is not specified", dataProcess.Namespace, dataProcess.Name) | ||||||||||||||||||||||||||||||||||||||||||||||
| now := time.Now() | ||||||||||||||||||||||||||||||||||||||||||||||
| return []datav1alpha1.Condition{ | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| Type: common.Failed, | ||||||||||||||||||||||||||||||||||||||||||||||
| Status: corev1.ConditionTrue, | ||||||||||||||||||||||||||||||||||||||||||||||
| Reason: common.DataProcessScheduleNotSpecified, | ||||||||||||||||||||||||||||||||||||||||||||||
| Message: "DataProcess's policy is Cron but spec.schedule is not specified", | ||||||||||||||||||||||||||||||||||||||||||||||
| LastProbeTime: metav1.NewTime(now), | ||||||||||||||||||||||||||||||||||||||||||||||
| LastTransitionTime: metav1.NewTime(now), | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, err | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return nil, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -219,15 +240,38 @@ func (r *dataProcessOperation) RemoveTargetDatasetStatusInProgress(dataset *data | |||||||||||||||||||||||||||||||||||||||||||||
| // DataProcess does not need to recover Dataset status after execution. | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // GetStatusHandler implements dataoperation.OperationInterface. | ||||||||||||||||||||||||||||||||||||||||||||||
| // Unlike DataLoad, which returns nil for an unrecognized policy, this defaults | ||||||||||||||||||||||||||||||||||||||||||||||
| // to OnceStatusHandler since policy is optional with a kubebuilder default of | ||||||||||||||||||||||||||||||||||||||||||||||
| // Once, so an empty value should be treated the same as Once. | ||||||||||||||||||||||||||||||||||||||||||||||
| func (r *dataProcessOperation) GetStatusHandler() dataoperation.StatusHandler { | ||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: Support dataProcess.Spec.Policy | ||||||||||||||||||||||||||||||||||||||||||||||
| return &OnceStatusHandler{Client: r.Client, dataProcess: r.dataProcess} | ||||||||||||||||||||||||||||||||||||||||||||||
| policy := r.dataProcess.Spec.Policy | ||||||||||||||||||||||||||||||||||||||||||||||
| switch policy { | ||||||||||||||||||||||||||||||||||||||||||||||
| case datav1alpha1.Cron: | ||||||||||||||||||||||||||||||||||||||||||||||
| return &CronStatusHandler{Client: r.Client, dataProcess: r.dataProcess} | ||||||||||||||||||||||||||||||||||||||||||||||
| case datav1alpha1.OnEvent: | ||||||||||||||||||||||||||||||||||||||||||||||
| return &OnEventStatusHandler{Client: r.Client, dataProcess: r.dataProcess} | ||||||||||||||||||||||||||||||||||||||||||||||
| case datav1alpha1.Once: | ||||||||||||||||||||||||||||||||||||||||||||||
| fallthrough | ||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||
| return &OnceStatusHandler{Client: r.Client, dataProcess: r.dataProcess} | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+248
to
+258
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // GetTTL implements dataoperation.OperationInterface. | ||||||||||||||||||||||||||||||||||||||||||||||
| // GetTTL implements dataoperation.OperationInterface. | ||||||||||||||||||||||||||||||||||||||||||||||
| // Cron and OnEvent policies are recurring/event-driven operations and should | ||||||||||||||||||||||||||||||||||||||||||||||
| // not be cleaned up via TTL; only Once (and the default/empty policy, which | ||||||||||||||||||||||||||||||||||||||||||||||
| // behaves like Once, see GetStatusHandler) uses TTLSecondsAfterFinished. | ||||||||||||||||||||||||||||||||||||||||||||||
| func (r *dataProcessOperation) GetTTL() (ttl *int32, err error) { | ||||||||||||||||||||||||||||||||||||||||||||||
| dataProcess := r.dataProcess | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ttl = r.dataProcess.Spec.TTLSecondsAfterFinished | ||||||||||||||||||||||||||||||||||||||||||||||
| switch dataProcess.Spec.Policy { | ||||||||||||||||||||||||||||||||||||||||||||||
| case datav1alpha1.Cron, datav1alpha1.OnEvent: | ||||||||||||||||||||||||||||||||||||||||||||||
| ttl = nil | ||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||
| ttl = dataProcess.Spec.TTLSecondsAfterFinished | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
Policyis set toCron, theSchedulefield must be non-empty and contain a valid cron expression. Currently there is no validation for this indataProcessOperation.Validate()inimplement.go. Please add validation to check:policy == Cron,schedulemust not be empty