Skip to content

Commit f81e343

Browse files
committed
Add resize hook
1 parent 6d864ed commit f81e343

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎packages/apps/vm-disk/templates/dv.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- $existingDV := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" .Release.Namespace .Release.Name }}
12
apiVersion: cdi.kubevirt.io/v1beta1
23
kind: DataVolume
34
metadata:
@@ -6,6 +7,9 @@ metadata:
67
vm-disk.cozystack.io/optical: "{{ .Values.optical }}"
78
name: {{ .Release.Name }}
89
spec:
10+
{{- if $existingDV }}
11+
{{- toYaml $existingDV.spec | nindent 2 }}
12+
{{- else }}
913
contentType: kubevirt
1014
{{- if .Values.source }}
1115
{{- if gt (len .Values.source) 1 }}
@@ -29,3 +33,4 @@ spec:
2933
{{- with .Values.storageClass }}
3034
storageClassName: {{ . }}
3135
{{- end }}
36+
{{- end }}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)