Skip to content

Commit

Permalink
Add resize hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps committed Oct 16, 2024
1 parent 6d864ed commit f81e343
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/apps/vm-disk/templates/dv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $existingDV := lookup "cdi.kubevirt.io/v1beta1" "DataVolume" .Release.Namespace .Release.Name }}
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
Expand All @@ -6,6 +7,9 @@ metadata:
vm-disk.cozystack.io/optical: "{{ .Values.optical }}"
name: {{ .Release.Name }}
spec:
{{- if $existingDV }}
{{- toYaml $existingDV.spec | nindent 2 }}
{{- else }}
contentType: kubevirt
{{- if .Values.source }}
{{- if gt (len .Values.source) 1 }}
Expand All @@ -29,3 +33,4 @@ spec:
{{- with .Values.storageClass }}
storageClassName: {{ . }}
{{- end }}
{{- end }}
68 changes: 68 additions & 0 deletions packages/apps/vm-disk/templates/pvc-resize-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{- $existingPVC := lookup "v1" "PersistentVolumeClaim" .Release.Namespace .Release.Name }}
{{- if and $existingPVC (ne ($existingPVC.spec.resources.requests.storage | toString) .Values.storage) -}}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-volume-resize-hook"
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
spec:
template:
metadata:
labels:
policy.cozystack.io/allow-to-apiserver: "true"
spec:
serviceAccountName: {{ .Release.Name }}-volume-resize-hook
restartPolicy: Never
backoffLimit: 1
containers:
- name: resize
image: bitnami/kubectl
command: ["sh", "-xec"]
args:
- |
kubectl patch pvc {{ .Release.Name }} -p '{"spec":{"resources":{"requests":{"storage":"{{ .Values.storage }}"}}}}'
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-volume-resize-hook
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-5"
helm.sh/hook-delete-policy: before-hook-creation
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Release.Name }}-volume-resize-hook
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-5"
helm.sh/hook-delete-policy: before-hook-creation
rules:
- apiGroups: ["apps"]
resources: ["statefulsets"]
verbs: ["delete", "get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["patch", "get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}-volume-resize-hook
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-5"
helm.sh/hook-delete-policy: before-hook-creation
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-volume-resize-hook
roleRef:
kind: Role
name: {{ .Release.Name }}-volume-resize-hook
apiGroup: rbac.authorization.k8s.io
{{- end }}

0 comments on commit f81e343

Please sign in to comment.