build snapshot cleaner job as workaround
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0357abba92
commit
ea65d83ead
1 changed files with 81 additions and 0 deletions
81
longhorn/snapshot-cleaner.yaml
Normal file
81
longhorn/snapshot-cleaner.yaml
Normal file
|
@ -0,0 +1,81 @@
|
|||
kind: Role
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
namespace: longhorn-system
|
||||
name: snapshot-cleaner
|
||||
rules:
|
||||
- apiGroups:
|
||||
- longhorn.io
|
||||
resources:
|
||||
- backups
|
||||
- snapshots
|
||||
verbs:
|
||||
- 'list'
|
||||
- 'delete'
|
||||
---
|
||||
kind: RoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: snapshot-cleaner
|
||||
namespace: longhorn-system
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: sa-snapshot-cleaner
|
||||
namespace: longhorn-system
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: snapshot-cleaner
|
||||
apiGroup: ""
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: sa-snapshot-cleaner
|
||||
namespace: longhorn-system
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: snapshot-cleaner
|
||||
namespace: longhorn-system
|
||||
spec:
|
||||
concurrencyPolicy: Forbid
|
||||
failedJobsHistoryLimit: 3
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- '-c'
|
||||
- >-
|
||||
comm -3 <(kubectl get backups.longhorn.io -n longhorn-system -o
|
||||
custom-columns=SNAPSHOT:.spec.snapshotName | grep '^snapshot-'
|
||||
| sort | uniq) <(kubectl get snapshot.longhorn.io -n longhorn-system
|
||||
-o custom-columns=SNAPSHOT:.metadata.name | grep '^snapshot-' | sort
|
||||
| uniq) | sed -n '/^\t/p' | sed 's/^\t//' | grep -v '^\n$'
|
||||
| xargs -r kubectl delete snapshot.longhorn.io -n longhorn-system &&
|
||||
comm -3 <(kubectl get snapshot.longhorn.io -n longhorn-system -o
|
||||
custom-columns=SNAPSHOT:.metadata.name | grep '^snapshot-' | sort | uniq)
|
||||
<(kubectl get backups.longhorn.io -n longhorn-system -o
|
||||
custom-columns=SNAPSHOT:.spec.snapshotName | grep '^snapshot-' | sort | uniq)
|
||||
| sed -n '/^\t/p' | sed 's/^\t//' | grep -v '^\n$' | while IFS= read -r snapshot;
|
||||
do kubectl get backups.longhorn.io -n longhorn-system -o
|
||||
jsonpath='{.items[?(@.spec.snapshotName=="'$snapshot'")].metadata.name}' | tr ' ' '\n'
|
||||
| xargs -r -I {} kubectl delete backups.longhorn.io -n longhorn-system {}; done
|
||||
command:
|
||||
- /bin/bash
|
||||
image: bitnami/kubectl:latest
|
||||
imagePullPolicy: Always
|
||||
name: snapshot-cleaner
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: OnFailure
|
||||
schedulerName: default-scheduler
|
||||
serviceAccount: sa-snapshot-cleaner
|
||||
serviceAccountName: sa-snapshot-cleaner
|
||||
terminationGracePeriodSeconds: 1800
|
||||
schedule: '40 */2 * * *'
|
||||
successfulJobsHistoryLimit: 1
|
||||
suspend: false
|
Loading…
Reference in a new issue