Skip to content

Option to deploy server as StatefulSet #172

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

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/minecraft-bedrock/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: minecraft-bedrock
version: 2.1.2
version: 2.2.0
appVersion: SeeValues
home: https://minecraft.net/
description: Minecraft server
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft-bedrock/templates/datadir-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim ) -}}
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim ) (not .Values.workloadAsStatefulSet) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
Expand Down
54 changes: 49 additions & 5 deletions charts/minecraft-bedrock/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if ne (printf "%s" .Values.minecraftServer.eula) "FALSE" }}
apiVersion: apps/v1
kind: Deployment
kind: {{ ternary "StatefulSet" "Deployment" .Values.workloadAsStatefulSet }}
metadata:
name: {{ template "minecraft.fullname" . }}
{{- if .Values.deploymentAnnotations }}
Expand All @@ -15,8 +15,14 @@ metadata:
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
{{- if .Values.workloadAsStatefulSet }}
serviceName: {{ template "minecraft.fullname" . }}
updateStrategy:
type: {{ .Values.strategyType }}
{{- else }}
strategy:
type: {{ .Values.strategyType }}
{{- end }}
selector:
matchLabels:
app: {{ template "minecraft.fullname" . }}
Expand Down Expand Up @@ -155,15 +161,19 @@ spec:
volumes:
- name: tmp
emptyDir: {}
- name: datadir
{{- if .Values.persistence.dataDir.enabled }}
{{- if .Values.persistence.dataDir.existingClaim }}
- name: datadir
persistentVolumeClaim:
{{- if .Values.persistence.dataDir.existingClaim }}
claimName: {{ .Values.persistence.dataDir.existingClaim }}
{{- else }}
{{- else if (not .Values.workloadAsStatefulSet) }}
- name: datadir
persistentVolumeClaim:
claimName: {{ template "minecraft.fullname" . }}-datadir
{{- end }}
{{- end -}}
{{/* if persistence enabled in stateful set without existing claim, a volume claim template will be defined */}}
{{- else }}
- name: datadir
emptyDir: {}
{{- end }}
{{- range .Values.extraVolumes }}
Expand All @@ -181,4 +191,38 @@ spec:
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
{{- if .Values.workloadAsStatefulSet }}
volumeClaimTemplates:
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim) }}
- metadata:
name: datadir
labels:
app: {{ template "minecraft.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
{{- with .Values.persistence.annotations }}
{{ toYaml . | nindent 10 }}
{{- end }}
{{- if .Values.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.persistence.dataDir.Size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{ end }}
11 changes: 10 additions & 1 deletion charts/minecraft-bedrock/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ resources:
memory: 512Mi
cpu: 500m

# upgrade strategy type (e.g. Recreate or RollingUpdate)
# If true the workload is defined as a StatefulSet instead of a Deployment.
# Make sure to also update the strategyType!
# All configuration options for the Deployment (e.g. annotations) are used for the StatefulSet.
# Regarding persistence: When an existing PVC is provided it will be shared between all Pods.
# Otherwise the PVC configuration is used as a template to create PVCs for each replica.
workloadAsStatefulSet: false

# upgrade strategy type, depending on workload type:
# - for Deployment sets strategy: Recreate or RollingUpdate
# - for StatefulSet sets updateStrategy: OnDelete or RollingUpdate
strategyType: Recreate

nodeSelector: {}
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: minecraft
version: 4.9.6
version: 4.10.0
appVersion: SeeValues
home: https://minecraft.net/
description: Minecraft server
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft/templates/backupdir-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.mcbackup.persistence.backupDir.enabled (not .Values.mcbackup.persistence.backupDir.existingClaim ) -}}
{{- if and .Values.mcbackup.persistence.backupDir.enabled (not .Values.mcbackup.persistence.backupDir.existingClaim ) (not .Values.workloadAsStatefulSet) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft/templates/datadir-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim ) -}}
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim ) (not .Values.workloadAsStatefulSet) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
Expand Down
103 changes: 94 additions & 9 deletions charts/minecraft/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if ne (printf "%s" .Values.minecraftServer.eula) "FALSE" }}
apiVersion: apps/v1
kind: Deployment
kind: {{ ternary "StatefulSet" "Deployment" .Values.workloadAsStatefulSet }}
metadata:
name: {{ template "minecraft.fullname" . }}
{{- if .Values.deploymentAnnotations }}
Expand All @@ -24,8 +24,14 @@ metadata:
{{- end }}
spec:
replicas: {{ default 1 .Values.replicaCount }}
{{- if .Values.workloadAsStatefulSet }}
serviceName: {{ template "minecraft.fullname" . }}
updateStrategy:
type: {{ .Values.strategyType }}
{{- else }}
strategy:
type: {{ .Values.strategyType }}
{{- end }}
selector:
matchLabels:
app: {{ template "minecraft.fullname" . }}
Expand Down Expand Up @@ -411,26 +417,34 @@ spec:
volumes:
- name: tmp
emptyDir: {}
- name: datadir
{{- if .Values.persistence.dataDir.enabled }}
{{- if .Values.persistence.dataDir.existingClaim }}
- name: datadir
persistentVolumeClaim:
{{- if .Values.persistence.dataDir.existingClaim }}
claimName: {{ .Values.persistence.dataDir.existingClaim }}
{{- else }}
{{- else if (not .Values.workloadAsStatefulSet) }}
- name: datadir
persistentVolumeClaim:
claimName: {{ template "minecraft.fullname" . }}-datadir
{{- end }}
{{- end -}}
{{/* if persistence enabled in stateful set without existing claim, a volume claim template will be defined */}}
{{- else }}
- name: datadir
emptyDir: {}
{{- end }}
- name: backupdir
{{- if and .Values.mcbackup.persistence.backupDir.enabled .Values.mcbackup.enabled }}
{{- if .Values.mcbackup.persistence.backupDir.existingClaim }}
- name: backupdir
persistentVolumeClaim:
{{- if .Values.mcbackup.persistence.backupDir.existingClaim }}
claimName: {{ .Values.mcbackup.persistence.backupDir.existingClaim }}
{{- else }}
{{- else if (not .Values.workloadAsStatefulSet) }}
- name: backupdir
persistentVolumeClaim:
claimName: {{ template "minecraft.fullname" . }}-backupdir
{{- end }}
{{- end -}}
{{/* if persistence enabled in stateful set without existing claim, a volume claim template will be defined */}}
{{- else }}
- name: backupdir
emptyDir: {}
{{- end }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
Expand Down Expand Up @@ -462,4 +476,75 @@ spec:
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
{{- if .Values.workloadAsStatefulSet }}
volumeClaimTemplates:
{{- if and .Values.persistence.dataDir.enabled (not .Values.persistence.dataDir.existingClaim) }}
- metadata:
name: datadir
labels:
app: {{ template "minecraft.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
app.kubernetes.io/name: "{{ .Chart.Name }}"
app.kubernetes.io/instance: {{ template "minecraft.fullname" . }}
app.kubernetes.io/version: "{{ .Chart.Version }}"
annotations:
{{- with .Values.persistence.annotations }}
{{ toYaml . | nindent 10 }}
{{- end }}
{{- if .Values.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.persistence.dataDir.Size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
{{- if and .Values.mcbackup.persistence.backupDir.enabled (not .Values.mcbackup.persistence.backupDir.existingClaim) }}
- metadata:
name: backupdir
labels:
app: {{ template "minecraft.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
app.kubernetes.io/name: "{{ .Chart.Name }}"
app.kubernetes.io/instance: {{ template "minecraft.fullname" . }}
app.kubernetes.io/version: "{{ .Chart.Version }}"
annotations:
{{- with .Values.mcbackup.persistence.annotations }}
{{ toYaml . | nindent 10 }}
{{- end }}
{{- if .Values.mcbackup.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.mcbackup.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.mcbackup.persistence.backupDir.Size | quote }}
{{- if .Values.mcbackup.persistence.storageClass }}
{{- if (eq "-" .Values.mcbackup.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.mcbackup.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{ end }}
11 changes: 10 additions & 1 deletion charts/minecraft/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ lifecycle:
postStart: []
preStop: []

# upgrade strategy type (e.g. Recreate or RollingUpdate)
# If true the workload is defined as a StatefulSet instead of a Deployment.
# Make sure to also update the strategyType!
# All configuration options for the Deployment (e.g. annotations) are used for the StatefulSet.
# Regarding persistence: When an existing PVC is provided it will be shared between all Pods.
# Otherwise the PVC configuration is used as a template to create PVCs for each replica.
workloadAsStatefulSet: false

# upgrade strategy type, depending on workload type:
# - for Deployment sets strategy: Recreate or RollingUpdate
# - for StatefulSet sets updateStrategy: OnDelete or RollingUpdate
strategyType: Recreate

nodeSelector: {}
Expand Down