Skip to content
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

Add support for mc-backup using restic with rclone #179

Merged
merged 12 commits into from
Nov 24, 2023
4 changes: 3 additions & 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.11.0
version: 4.12.0
appVersion: SeeValues
home: https://minecraft.net/
description: Minecraft server
Expand All @@ -16,6 +16,8 @@ maintainers:
email: [email protected]
- name: itzg
email: [email protected]
- name: bibz87
email: [email protected]
annotations:
artifacthub.io/links: |
- name: Image source
Expand Down
2 changes: 2 additions & 0 deletions charts/minecraft/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ approvers:
- gtaylor
- itzg
- billimek
- bibz87
reviewers:
- gtaylor
- itzg
- billimek
- bibz87
18 changes: 18 additions & 0 deletions charts/minecraft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ kubectl cp ${NAMESPACE}/${POD_ID}:/data .
kubectl exec --namespace ${NAMESPACE} ${POD_ID} rcon-cli save-on
```

### Known issues

`rclone` can attempt to update its configuration file when there is data to be
modified, such as missing configuration entries or tokens. As this configuration
file will most likely be stored in a ConfigMap or a Secret, it will be read-only
and the container will generate errors like this one:

``` text
rclone: 2023/11/22 21:41:18 ERROR : Failed to save config after 10 tries: failed to create temp file for new config: open /config/rclone/rclone.conf4086229703: read-only file system
```

In that case, double-check if there are missing entries in your `rclone`
configuration as this might be the reason why `rclone` throws an error. This
might not solve all cases, though.

For more information, see this GitHub
[issue](https://github.com/rclone/rclone/issues/3655)

## Tutorials

For a quickstart guide to setting up a Kubernetes cluster and deploying
Expand Down
10 changes: 10 additions & 0 deletions charts/minecraft/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- $value }}
{{- end }}
{{- end -}}

{{- define "isResticWithRclone" -}}
{{- if .Values.mcbackup -}}
{{- if and (eq .Values.mcbackup.backupMethod "restic") (hasPrefix "rclone" .Values.mcbackup.resticRepository) }}
{{- printf "true" }}
{{- else }}
{{- printf "false" }}
{{- end }}
{{- end }}
{{- end -}}
16 changes: 12 additions & 4 deletions charts/minecraft/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ spec:
{{- template "minecraft.envMap" list "RESTIC_REPOSITORY" .Values.mcbackup.resticRepository }}
{{- template "minecraft.envMap" list "RESTIC_ADDITIONAL_TAGS" .Values.mcbackup.resticAdditionalTags }}
{{- template "minecraft.envMap" list "PRUNE_RESTIC_RETENTION" .Values.mcbackup.pruneResticRetention }}
{{- range $key, $value := .Values.mcbackup.resticEnvs }}
{{- range $key, $value := .Values.mcbackup.resticEnvs }}
{{- if kindIs "map" $value }}
{{- if hasKey $value "valueFrom" }}
- name: {{ $key }}
valueFrom:
{{- $value.valueFrom | toYaml | nindent 12 }}
{{- end }}
{{- else }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- range $key, $value := .Values.mcbackup.extraEnv }}
Expand All @@ -137,7 +145,7 @@ spec:
readOnly: true
- name: backupdir
mountPath: {{ default "/backups" .Values.mcbackup.destDir }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
{{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
- name: rclone-config
mountPath: /config/rclone
{{- end }}
Expand Down Expand Up @@ -447,7 +455,7 @@ spec:
- name: backupdir
emptyDir: {}
{{- end }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
{{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
- name: rclone-config
secret:
{{- if .Values.mcbackup.rcloneConfigExistingSecret }}
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft/templates/rclone-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if and .Values.mcbackup.enabled .Values.minecraftServer.rcon.enabled (not .Values.mcbackup.rcloneConfigExistingSecret) }}
{{- if eq .Values.mcbackup.backupMethod "rclone" }}
{{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
16 changes: 16 additions & 0 deletions charts/minecraft/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@
"required": [
"eula"
]
},
"mcbackup": {
"type": "object",
"properties": {
"backupMethod": {
"type": "string",
"enum": [
"tar",
"restic",
"rclone"
]
},
"resticRepository": {
"type": "string"
}
}
}
}
}
6 changes: 3 additions & 3 deletions charts/minecraft/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,15 @@ mcbackup:
# if you prefer to create a secret from file (e.g. kubectl create secret generic my-rclone-config --from-file=~/.config/rclone/rclone.conf)
# rcloneConfigExistingSecret: my-rclone-config

resticRepository:
resticRepository: ""
# variable to define a space separated list of additional restic tags. see https://hub.docker.com/r/itzg/mc-backup
resticAdditionalTags: "mc_backups"
# see https://restic.readthedocs.io/en/latest/060_forget.html
pruneResticRetention: "--keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75"

# At least one of RESTIC_PASSWORD* env variables need to be defined, see https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html
resticEnvs:
[]
{}
# RESTIC_PASSWORD: restic-password

## Additional minecraft container environment variables
Expand All @@ -498,7 +498,7 @@ mcbackup:
# fieldRef:
# fieldPath: status.hostIP

## Additional environment variables to add to the minecraft container from
## Additional environment variables to add to the mc-backup container from
## ConfigMaps and Secrets
##
envFrom: []
Expand Down
Loading