我目前在使用 helm 时遇到问题。 我编写了一个包含 CroneJob 的值模板,如下所示:
...
custom_pipeline:
schedule: "0 21 * * *"
steps:
- name: test-cj
volume: True # True or False mount in "/app/persistent"
mountPath: "/app/ccc/"
image: test_cj
tag: "0.0.0"
env:
- name: DEBUG
valueFrom:
configMapKeyRef:
name: test-cj-config
key: DEBUG
...
当我更改 CroneJob (custom_pipeline) 的值并应用它们时:
helm upgrade --install test-cj . --values=./helm_values/values_test_cj.yml -n test-cj
即使我指定了固定的时间表,CroneJob 也会自动触发。
更改了restartPolicy设置,但没有用。
当前使用的Helm模板如下:
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Release.Name }}-custom-pipeline
namespace: {{ .Release.Namespace }}
spec:
schedule: {{ .Values.custom_pipeline.schedule | default "0 0 * * 1" | quote }}
concurrencyPolicy: {{ .Values.cron_job_concurrencyPolicy | default "Allow" | quote }}
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
parallelism: 1
template:
spec:
volumes:
{{- range $index, $step := .Values.custom_pipeline.steps }}
{{- if or $step.volume (not (eq ($step.volume | toString) "<nil>")) }}
- name: {{ $.Release.Name }}-{{ $step.name }}-data
persistentVolumeClaim:
claimName: {{ $.Release.Name }}-{{ $step.name }}-data-claim
{{- end }}
{{- end }}
{{- if or .Values.imagePullSecrets (eq (.Values.imagePullSecrets | toString) "<nil>") }}
imagePullSecrets:
- name: regcred
{{- end }}
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
initContainers:
{{- range $index, $step := .Values.custom_pipeline.steps }}
- name: {{ $.Release.Name }}-{{ $step.name }}
image: "{{ default "mydockerhub/" $.Values.custom_registry }}{{ $step.image }}:{{ default "latest" $step.tag }}"
imagePullPolicy: Always
{{ if or $step.volume (not (eq ($step.volume | toString) "<nil>"))}}
volumeMounts:
- name: {{ $.Release.Name }}-{{ $step.name }}-data
mountPath: {{ default "/app/persistent" $step.mountPath}}
{{ end }}
{{ if $step.env }}
env:
{{- toYaml $step.env | nindent 14 }}
{{ end }}
{{- end }}
containers:
- name: {{ .Release.Name }}-job-done
image: busybox
command: ['sh', '-c', 'echo "custom pipeline completed"']
restartPolicy: Never
{{ end }}
[解决方案]: 按照建议,我在 CroneJob 的 helm 模板中的规范下添加了
startingDeadlineSeconds: 200
,现在它仅在计划时启动。
此行为是预期的,请参阅 https://github.com/kubernetes/kubernetes/issues/63371
您唯一能做的就是将
.spec.startingDeadlineSeconds
字段设置为较小的值,例如 200 秒。在这种情况下,如果在配置的计划之后更新超过 200 秒,则 cronjob 将不会运行。