{{- range .Values.cron.jobs }} --- # CronJobのPodは、nginx/php-fpmのDeploymentとは別のReplicaSetに属するため、 # jobTemplate.spec.template.metadata.labels には phpfpm.cron.selectorLabels # (app.kubernetes.io/name: -cron)を使う。ここで通常の # phpfpm.selectorLabels(name: phpfpm)を使ってしまうと、nginx/php-fpm # DeploymentのmatchLabelsと一致するPodが増え、ReplicaSetコントローラーが # replicaCountとの差分調整でCronJob由来のPodを意図せず削除する事故につながる # (Selenium分離(v8.5.10-b)と同じ理由)。 apiVersion: batch/v1 kind: CronJob metadata: name: {{ printf "%s-cron-%s" (include "phpfpm.fullname" $) .name | trunc 52 | trimSuffix "-" }} labels: {{- include "phpfpm.labels" $ | nindent 4 }} app.kubernetes.io/component: cron spec: schedule: {{ .schedule | quote }} {{- if .timeZone }} timeZone: {{ .timeZone | quote }} {{- end }} concurrencyPolicy: {{ .concurrencyPolicy | default "Forbid" }} {{- if hasKey . "suspend" }} suspend: {{ .suspend }} {{- end }} successfulJobsHistoryLimit: {{ .successfulJobsHistoryLimit | default 3 }} failedJobsHistoryLimit: {{ .failedJobsHistoryLimit | default 1 }} jobTemplate: spec: {{- if .activeDeadlineSeconds }} activeDeadlineSeconds: {{ .activeDeadlineSeconds }} {{- end }} template: metadata: labels: {{- include "phpfpm.cron.selectorLabels" $ | nindent 12 }} app.kubernetes.io/component: cron spec: restartPolicy: {{ .restartPolicy | default "OnFailure" }} containers: - name: cron image: "{{ $.Values.image.php.registry }}/{{ $.Values.image.php.repository }}:{{ $.Values.image.php.tag }}" imagePullPolicy: {{ $.Values.image.php.pullPolicy }} command: - sh - -c - | echo "Starting cron job: {{ .name }}" {{- if $.Values.smtp.enabled }} # ======================================== # SMTP設定(msmtp) — templates/deployment.yaml のSMTP設定と同じ内容。 # 変更する場合は両方のファイルを揃えること。 # ======================================== echo "Installing msmtp for mail sending..." apk add --no-cache msmtp ca-certificates cp /etc/smtp-config/msmtprc /etc/msmtprc chmod 644 /etc/msmtprc cat > /usr/local/etc/php/conf.d/99-smtp.ini << 'PHP_SMTP_EOF' sendmail_path = "/usr/bin/msmtp -t" sendmail_from = "{{ $.Values.smtp.from }}" PHP_SMTP_EOF {{- end }} echo "Running: {{ .command }}" {{ .command }} {{- with (.resources | default $.Values.resources.phpfpm) }} resources: {{- toYaml . | nindent 16 }} {{- end }} volumeMounts: # php-fpmコンテナと同様、PVCルートを/var/wwwにマウントする。 # html/ は公開コード、それ以外は非公開ファイルの置き場として利用できる。 - name: app-storage mountPath: /var/www {{- if $.Values.smtp.enabled }} - name: smtp-config mountPath: /etc/smtp-config readOnly: true {{- if and $.Values.smtp.auth.enabled (not $.Values.smtp.existingMsmtprcSecret) }} - name: smtp-secrets mountPath: /etc/smtp-secrets readOnly: true {{- end }} {{- end }} env: {{- if $.Values.externalDatabase.enabled }} - name: DB_HOST value: {{ $.Values.externalDatabase.host | quote }} - name: DB_PORT value: {{ $.Values.externalDatabase.port | quote }} - name: DB_NAME value: {{ $.Values.externalDatabase.database | quote }} - name: DB_USER value: {{ $.Values.externalDatabase.username | quote }} - name: DB_PASS valueFrom: secretKeyRef: name: {{ include "phpfpm.fullname" $ }}-db-secret key: {{ include "phpfpm.fullname" $ }}-db-key {{- end }} {{- range $key, $value := $.Values.phpEnv }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} {{- if $.Values.selenium.enabled }} - name: SELENIUM_URL value: "http://{{ include "phpfpm.fullname" $ }}-selenium:4444/wd/hub" {{- end }} {{- with $.Values.extraEnv }} {{- toYaml . | nindent 16 }} {{- end }} {{- with $.Values.extraEnvFrom }} envFrom: {{- toYaml . | nindent 16 }} {{- end }} dnsPolicy: ClusterFirst dnsConfig: options: - name: ndots value: "1" volumes: - name: app-storage {{- if $.Values.persistence.enabled }} persistentVolumeClaim: claimName: {{ include "phpfpm.fullname" $ }}-pvc {{- else }} emptyDir: {} {{- end }} {{- if $.Values.smtp.enabled }} - name: smtp-config {{- if $.Values.smtp.existingMsmtprcSecret }} secret: secretName: {{ $.Values.smtp.existingMsmtprcSecret }} items: - key: {{ $.Values.smtp.existingMsmtprcSecretKey | default "msmtprc" }} path: msmtprc {{- else }} configMap: name: {{ include "phpfpm.fullname" $ }}-smtp-config items: - key: msmtprc path: msmtprc {{- end }} {{- if and $.Values.smtp.auth.enabled (not $.Values.smtp.existingMsmtprcSecret) }} - name: smtp-secrets secret: secretName: {{ $.Values.smtp.auth.existingSecret | default (printf "%s-smtp" (include "phpfpm.fullname" $)) }} items: - key: {{ $.Values.smtp.auth.existingSecretKey | default "password" }} path: password mode: 0644 {{- end }} {{- end }} {{- end }}