|
| 1 | +{{- $existingPVC := lookup "v1" "PersistentVolumeClaim" .Release.Namespace .Release.Name }} |
| 2 | +{{- if and $existingPVC (ne ($existingPVC.spec.resources.requests.storage | toString) .Values.storage) -}} |
| 3 | +apiVersion: batch/v1 |
| 4 | +kind: Job |
| 5 | +metadata: |
| 6 | + name: "{{ .Release.Name }}-volume-resize-hook" |
| 7 | + annotations: |
| 8 | + helm.sh/hook: pre-install,pre-upgrade |
| 9 | + helm.sh/hook-weight: "0" |
| 10 | + helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation |
| 11 | +spec: |
| 12 | + template: |
| 13 | + metadata: |
| 14 | + labels: |
| 15 | + policy.cozystack.io/allow-to-apiserver: "true" |
| 16 | + spec: |
| 17 | + serviceAccountName: {{ .Release.Name }}-volume-resize-hook |
| 18 | + restartPolicy: Never |
| 19 | + backoffLimit: 1 |
| 20 | + containers: |
| 21 | + - name: resize |
| 22 | + image: bitnami/kubectl |
| 23 | + command: ["sh", "-xec"] |
| 24 | + args: |
| 25 | + - | |
| 26 | + kubectl patch pvc {{ .Release.Name }} -p '{"spec":{"resources":{"requests":{"storage":"{{ .Values.storage }}"}}}}' |
| 27 | +--- |
| 28 | +apiVersion: v1 |
| 29 | +kind: ServiceAccount |
| 30 | +metadata: |
| 31 | + name: {{ .Release.Name }}-volume-resize-hook |
| 32 | + annotations: |
| 33 | + helm.sh/hook: pre-install,pre-upgrade |
| 34 | + helm.sh/hook-weight: "-5" |
| 35 | + helm.sh/hook-delete-policy: before-hook-creation |
| 36 | +--- |
| 37 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 38 | +kind: Role |
| 39 | +metadata: |
| 40 | + name: {{ .Release.Name }}-volume-resize-hook |
| 41 | + annotations: |
| 42 | + helm.sh/hook: pre-install,pre-upgrade |
| 43 | + helm.sh/hook-weight: "-5" |
| 44 | + helm.sh/hook-delete-policy: before-hook-creation |
| 45 | +rules: |
| 46 | + - apiGroups: ["apps"] |
| 47 | + resources: ["statefulsets"] |
| 48 | + verbs: ["delete", "get", "list", "watch"] |
| 49 | + - apiGroups: [""] |
| 50 | + resources: ["persistentvolumeclaims"] |
| 51 | + verbs: ["patch", "get", "list", "watch"] |
| 52 | +--- |
| 53 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 54 | +kind: RoleBinding |
| 55 | +metadata: |
| 56 | + name: {{ .Release.Name }}-volume-resize-hook |
| 57 | + annotations: |
| 58 | + helm.sh/hook: pre-install,pre-upgrade |
| 59 | + helm.sh/hook-weight: "-5" |
| 60 | + helm.sh/hook-delete-policy: before-hook-creation |
| 61 | +subjects: |
| 62 | + - kind: ServiceAccount |
| 63 | + name: {{ .Release.Name }}-volume-resize-hook |
| 64 | +roleRef: |
| 65 | + kind: Role |
| 66 | + name: {{ .Release.Name }}-volume-resize-hook |
| 67 | + apiGroup: rbac.authorization.k8s.io |
| 68 | +{{- end }} |
0 commit comments