Skip to content

Commit

Permalink
charts/service-deployment: Add support for StatefulSet in deployment.…
Browse files Browse the repository at this point in the history
…Kind (closes #170)
  • Loading branch information
jbeemster committed Mar 28, 2024
1 parent 48ed8e8 commit e6a9a7f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion charts/service-deployment/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: service-deployment
description: A Helm Chart to setup a generic deployment with optional service/hpa bindings
version: 0.17.0
version: 0.18.0
icon: https://raw.githubusercontent.com/snowplow-devops/helm-charts/master/docs/logo/snowplow.png
home: https://github.com/snowplow-devops/helm-charts
sources:
Expand Down
9 changes: 7 additions & 2 deletions charts/service-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This chart attempts to take care of all the most common requirements of launchin
- Mounting config volumes
- Configuring secrets
- Binding service-accounts with cloud specific IAM policies
- Setting up persistent-volumes and binding them

_Note_: This should be a long running process - if you are looking for cron-based execution see our `cron-job` chart.

Expand Down Expand Up @@ -55,6 +56,7 @@ helm delete service-deployment
| config.secrets | object | `{}` | Map of secrets that will be exposed as environment variables within the job |
| config.secretsB64 | object | `{}` | Map of base64-encoded secrets that will be exposed as environment variables within the job |
| configMaps | list | `[]` | List of config maps to mount to the deployment |
| deployment.kind | string | `"Deployment"` | Can be either a "Deployment" or "StatefulSet" |
| deployment.podLabels | object | `{}` | Map of labels that will be added to each pod in the deployment |
| deployment.scaleToZero | bool | `false` | When enabled, disables the HPA and scales the deployment to zero replicas |
| deployment.strategy | object | `{"rollingUpdate":{"maxSurge":"25%","maxUnavailable":"25%"},"type":"RollingUpdate"}` | How to replace existing pods with new ones |
Expand All @@ -80,12 +82,15 @@ helm delete service-deployment
| livenessProbe | object | `{"exec":{"command":[]},"failureThreshold":3,"httpGet":{"path":"","port":""},"initialDelaySeconds":5,"periodSeconds":5,"successThreshold":1,"timeoutSeconds":5}` | livenessProbe is enabled if httpGet.path or exec.command are present |
| livenessProbe.exec.command | list | `[]` | Command/arguments to execute to determine liveness |
| livenessProbe.httpGet.path | string | `""` | Path for health checks to be performed to determine liveness |
| persistentVolume.accessModes | list | `["ReadWriteOnce"]` | Access modes to allow (note: this will impact HPA rules if the volume cannot be bound to all containers) |
| persistentVolume.accessModes | list | `["ReadWriteOnce"]` | Access modes to allow (note: this will impact HPA rules if the volume cannot be bound to all containers when deployment.kind is "Deployment") |
| persistentVolume.annotations | object | `{}` | Persistent Volume annotations |
| persistentVolume.enabled | bool | `false` | Whether to deploy a persistent-volume |
| persistentVolume.enabled | bool | `false` | Whether to deploy a persistent-volume (note: when deployment.kind is "StatefulSet" one volume will be created per replica) |
| persistentVolume.labels | object | `{}` | Persistent Volume labels |
| persistentVolume.mountPath | string | `"/data"` | Persistent Volume mount root path |
| persistentVolume.size | string | `"8Gi"` | Persistent Volume size |
| persistentVolume.statefulSetRetentionPolicy | object | `{"whenDeleted":"Retain","whenScaled":"Delete"}` | Sets the retention policies for the volumes created in "StatefulSet" mode |
| persistentVolume.statefulSetRetentionPolicy.whenDeleted | string | `"Retain"` | What to do with volumes when the StatefulSet is deleted |
| persistentVolume.statefulSetRetentionPolicy.whenScaled | string | `"Delete"` | What to do with volumes when scaling occurs |
| persistentVolume.subPath | string | `""` | Subdirectory of Persistent Volume to mount |
| priorityClassName | string | `""` | PriorityClassName for pods |
| readinessProbe | object | `{"exec":{"command":[]},"failureThreshold":3,"httpGet":{"path":""},"initialDelaySeconds":5,"periodSeconds":5,"successThreshold":2,"timeoutSeconds":5}` | readinessProbe is enabled if httpGet.path or exec.command are present |
Expand Down
40 changes: 37 additions & 3 deletions charts/service-deployment/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.deployment.kind }}
metadata:
name: {{ include "app.fullname" . }}
spec:
Expand Down Expand Up @@ -71,7 +71,7 @@ spec:
optional: false
name: {{ $v.name }}
{{- end }}
{{- if .Values.persistentVolume.enabled }}
{{- if and (.Values.persistentVolume.enabled) (eq .Values.deployment.kind "Deployment") }}
- name: storage-volume
persistentVolumeClaim:
claimName: {{ include "app.fullname" . }}
Expand Down Expand Up @@ -172,8 +172,42 @@ spec:
{{- end }}
name: {{ $v.name }}
{{- end }}
{{- if .Values.persistentVolume.enabled }}
{{- if and (.Values.persistentVolume.enabled) (eq .Values.deployment.kind "Deployment") }}
- name: storage-volume
mountPath: {{ .Values.persistentVolume.mountPath }}
subPath: "{{ .Values.persistentVolume.subPath }}"
{{- end }}
{{- if and (.Values.persistentVolume.enabled) (eq .Values.deployment.kind "StatefulSet") }}
- name: {{ include "app.fullname" . }}
mountPath: {{ .Values.persistentVolume.mountPath }}
subPath: "{{ .Values.persistentVolume.subPath }}"
{{- end }}
{{- if and (.Values.persistentVolume.enabled) (eq .Values.deployment.kind "StatefulSet") }}
persistentVolumeClaimRetentionPolicy:
whenDeleted: {{ .Values.persistentVolume.statefulSetRetentionPolicy.whenDeleted }}
whenScaled: {{ .Values.persistentVolume.statefulSetRetentionPolicy.whenScaled }}
volumeClaimTemplates:
- metadata:
annotations:
{{- with .Values.persistentVolume.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- with .Values.persistentVolume.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
name: {{ include "app.fullname" . }}
spec:
accessModes:
{{ toYaml .Values.persistentVolume.accessModes | indent 6 }}
{{- if .Values.persistentVolume.storageClass }}
{{- if (eq "-" .Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
resources:
requests:
storage: "{{ .Values.persistentVolume.size }}"
{{- end }}
2 changes: 1 addition & 1 deletion charts/service-deployment/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
kind: {{ .Values.deployment.kind }}
name: {{ include "app.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
Expand Down
2 changes: 1 addition & 1 deletion charts/service-deployment/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.persistentVolume.enabled -}}
{{- if and (.Values.persistentVolume.enabled) (eq .Values.deployment.kind "Deployment") }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand Down
14 changes: 11 additions & 3 deletions charts/service-deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ service:
gcp:
# -- Name of the Network Endpoint Group to bind onto
networkEndpointGroupName: ""
# -- Map of annotations to add to the service.
# -- Map of annotations to add to the service
annotations: {}
# -- A map of ingress rules to deploy
ingress: {}
Expand Down Expand Up @@ -152,6 +152,8 @@ cloudserviceaccount:
managedIdentityId: ""

deployment:
# -- Can be either a "Deployment" or "StatefulSet"
kind: "Deployment"
# -- When enabled, disables the HPA and scales the deployment to zero replicas
scaleToZero: false
# -- How to replace existing pods with new ones
Expand Down Expand Up @@ -203,11 +205,17 @@ affinity: {}
# - linux

persistentVolume:
# -- Whether to deploy a persistent-volume
# -- Whether to deploy a persistent-volume (note: when deployment.kind is "StatefulSet" one volume will be created per replica)
enabled: false
# -- Access modes to allow (note: this will impact HPA rules if the volume cannot be bound to all containers)
# -- Access modes to allow (note: this will impact HPA rules if the volume cannot be bound to all containers when deployment.kind is "Deployment")
accessModes:
- ReadWriteOnce
# -- Sets the retention policies for the volumes created in "StatefulSet" mode
statefulSetRetentionPolicy:
# -- What to do with volumes when the StatefulSet is deleted
whenDeleted: "Retain"
# -- What to do with volumes when scaling occurs
whenScaled: "Delete"
# -- Persistent Volume labels
labels: {}
# -- Persistent Volume annotations
Expand Down

0 comments on commit e6a9a7f

Please sign in to comment.