Skip to content

Commit

Permalink
Producer App can be deployed as k8s Deployment (#175)
Browse files Browse the repository at this point in the history
Suitable for "endless" producers like observers/notifiers.
  • Loading branch information
mkcode92 committed Mar 15, 2023
1 parent 2934290 commit fdcb37a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions charts/producer-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Alternatively, a YAML file that specifies the values for the parameters can be p
| `labels` | Map of custom labels to attach to the pod spec. | `{}` |
| `tolerations` | Array containing taint references. When defined, pods can run on nodes, which would otherwise deny scheduling. Further information can be found in the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) | `{}` |
| `nodeAffinity` | Map to configure [pod affinities](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity). | `{}` |
| `deployment` | Deploy the producer as a Kubernetes Deployment (thereby ignoring Job-related configurations) | false |
| `restartPolicy` | [Restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) to use for the job. | `OnFailure` |
| `schedule` | Cron expression to denote a schedule this producer app should be run on. It will then be deployed as a [CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) instead of a [Job](https://kubernetes.io/docs/concepts/workloads/controllers/job/). | |
| `suspend` | Whether to suspend the execution of the cron job. | `false` |
Expand Down
32 changes: 32 additions & 0 deletions charts/producer-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.deployment }}
{{- $root := . -}}
{{- if .Capabilities.APIVersions.Has "apps/v1" }}
apiVersion: apps/v1
{{- else }}
apiVersion: apps/v1beta1
{{- end }}
kind: Deployment
metadata:
name: {{ template "producer-app.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- range $key, $value := .Values.annotations }}
{{ $key | quote }}: {{ $value | quote }}
{{- end }}
{{- end }}
labels:
app: {{ template "producer-app.name" . }}
chart: {{ template "producer-app.chart" . }}
release: {{ .Release.Name }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "producer-app.name" . }}
release: {{ .Release.Name }}
template:
{{ include "producer-app.podTemplate" . | indent 4 }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/producer-app/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.deployment -}}
{{- $root := . -}}
{{- if .Values.schedule -}}
{{- if .Capabilities.APIVersions.Has "batch/v1/CronJob" }}
Expand Down Expand Up @@ -42,3 +43,4 @@ spec:
{{ include "producer-app.podTemplate" . | indent 4 }}
backoffLimit: {{ .Values.backoffLimit }}
{{- end -}}
{{- end }}
2 changes: 2 additions & 0 deletions charts/producer-app/templates/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ metadata:
{{ $key }}: {{ $value }}
{{- end }}
spec:
{{- if not .Values.deployment }}
restartPolicy: {{ .Values.restartPolicy }}
{{- end }}
{{- if .Values.serviceAccountName }}
serviceAccountName: {{ .Values.serviceAccountName }}
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions charts/producer-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ imagePullPolicy: Always

imagePullSecrets: []

# if true, deploy as kubernetes deployment instead of CronJob/Job
deployment: false
# Optional, applied for deployment:
# replicaCount: 1

restartPolicy: OnFailure

configurationEnvPrefix: "APP"
Expand Down

0 comments on commit fdcb37a

Please sign in to comment.