1
1
{{- $v := .Values }}
2
2
{{- $otomiAdmin := "otomi-admin" }}
3
3
{{- $obj := $v.obj.provider }}
4
+ {{- $giteaBackupConfig := $v.platformBackups.gitea }}
4
5
5
6
resources:
6
7
{{- if $v._derived.untrustedCA }}
@@ -19,6 +20,7 @@ resources:
19
20
data:
20
21
username: "{{ "gitea" | b64enc }}"
21
22
password: "{{ $v.apps.gitea.postgresqlPassword | b64enc }}"
23
+ # DB / app backup resources
22
24
{{- if eq $obj.type "minioLocal" }}
23
25
- apiVersion: v1
24
26
kind: Secret
@@ -37,3 +39,104 @@ resources:
37
39
S3_STORAGE_ACCOUNT: "{{ $obj.linode.accessKeyId | b64enc }}"
38
40
S3_STORAGE_KEY: "{{ $obj.linode.secretAccessKey | b64enc }}"
39
41
{{- end }}
42
+ # Application backup resources
43
+ - apiVersion: v1
44
+ kind: PersistentVolumeClaim
45
+ metadata:
46
+ name: gitea-backup
47
+ spec:
48
+ accessModes:
49
+ - ReadWriteOnce
50
+ resources:
51
+ requests:
52
+ {{- if eq $v.cluster.provider "vultr" }}
53
+ storage: 10Gi
54
+ {{- else }}
55
+ storage: 1Gi
56
+ {{- end }}
57
+ {{- if $giteaBackupConfig.enabled }}
58
+ - apiVersion: v1
59
+ kind: ServiceAccount
60
+ metadata:
61
+ name: gitea-backup
62
+ - apiVersion: rbac.authorization.k8s.io/v1
63
+ kind: Role
64
+ metadata:
65
+ name: gitea-backup-operator
66
+ rules:
67
+ - apiGroups: [""]
68
+ resources: ["pods"]
69
+ verbs: ["get", "watch", "list"]
70
+ - apiGroups: [""]
71
+ resources: ["pods/exec"]
72
+ verbs: ["create"]
73
+ - apiVersion: rbac.authorization.k8s.io/v1
74
+ kind: RoleBinding
75
+ metadata:
76
+ name: gitea-backup
77
+ subjects:
78
+ - kind: ServiceAccount
79
+ name: gitea-backup
80
+ roleRef:
81
+ kind: Role
82
+ name: gitea-backup-operator
83
+ apiGroup: rbac.authorization.k8s.io
84
+ - apiVersion: batch/v1
85
+ kind: CronJob
86
+ metadata:
87
+ name: gitea-backup-job
88
+ spec:
89
+ schedule: {{ $giteaBackupConfig.schedule | quote }}
90
+ concurrencyPolicy: Forbid
91
+ jobTemplate:
92
+ spec:
93
+ template:
94
+ metadata:
95
+ annotations:
96
+ sidecar.istio.io/inject: "false"
97
+ spec:
98
+ serviceAccountName: gitea-backup
99
+ containers:
100
+ - image: bitnami/kubectl:1.30
101
+ name: kubectl
102
+ command:
103
+ - /bin/sh
104
+ - -ec
105
+ - >-
106
+ kubectl exec gitea-0 -- /bin/sh -ec "
107
+ if [ ! -f '/backup/.bin/rclone' ]; then
108
+ echo 'Installing RClone...' &&
109
+ mkdir -p /backup/.bin &&
110
+ cd /backup/.bin &&
111
+ curl -fsSL -o rclone.zip https://github.com/rclone/rclone/releases/download/v1.68.0/rclone-v1.68.0-linux-amd64.zip &&
112
+ echo '2fd93c246c72fa6bb192d33b0447013b31a982f9daaaa1f9c0b85e99f4233ee47c089e8b3f7f994dfe21090dab8e2adaec2e62c68aed0c7dadbac9bcce4e1706 rclone.zip' | sha512sum -c - &&
113
+ unzip -oj rclone.zip
114
+ fi &&
115
+ cd /backup &&
116
+ echo 'Creating backup...' &&
117
+ gitea dump --type tar.bz2 &&
118
+ echo '5d20f5562609695b565d696980bbee91ec0503ed946410eb2e6024a8b6850ebd5b587d5c71488f471012ea39e6bf440d843840165e8ac75cd0ec737defa2a749 .bin/rclone' | sha512sum -c - &&
119
+ echo 'Uploading to object storage...' &&
120
+ .bin/rclone copy --exclude '\.*/**' /backup gitea:/\$BUCKET_NAME &&
121
+ echo 'Removing old backups from object storage...' &&
122
+ .bin/rclone sync --min-age $RETENTION_TIME --exclude '\.*/**' /backup gitea:/\$BUCKET_NAME &&
123
+ echo 'Cleaning up local backups...' &&
124
+ find . -type f -iname '*.tar.bz2' -ctime +1 -delete"
125
+ resources:
126
+ limits:
127
+ cpu: 250m
128
+ memory: 256Mi
129
+ requests:
130
+ cpu: 100m
131
+ memory: 128Mi
132
+ env:
133
+ - name: RETENTION_TIME
134
+ value: {{ $giteaBackupConfig.retentionPolicy }}
135
+ securityContext:
136
+ runAsNonRoot: true
137
+ runAsUser: 65535
138
+ runAsGroup: 65535
139
+ restartPolicy: Never
140
+ securityContext:
141
+ fsGroup: 65535
142
+ {{- end }}
0 commit comments