Skip to content

Commit 8513dd6

Browse files
authored
[virtual-machine] Improve check for resizing job (#1688)
Signed-off-by: Andrei Kvapil <[email protected]> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does PVC resizing now only occurs when storage is being increased, preventing unintended storage reduction operations ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [virtual-machine] Improve check for resizing job ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * PVC resizing now only triggers when the requested storage increases, preventing unintended shrink attempts. * **Enhancements** * More robust storage-size comparison and validation to accurately detect growth. * Resize operations now run only when needed, reducing unnecessary jobs. * **New Features** * Added conditional pre-install/pre-upgrade hook workflow to perform controlled PVC resize jobs. * **Chores** * Minor template formatting cleanup. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 349677f + 0bab895 commit 8513dd6

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎packages/apps/virtual-machine/templates/vm-update-hook.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
{{- if and $existingPVC $desiredStorage -}}
2828
{{- $currentStorage := $existingPVC.spec.resources.requests.storage | toString -}}
2929
{{- if not (eq $currentStorage $desiredStorage) -}}
30-
{{- $needResizePVC = true -}}
30+
{{- $oldSize := (include "cozy-lib.resources.toFloat" $currentStorage) | float64 -}}
31+
{{- $newSize := (include "cozy-lib.resources.toFloat" $desiredStorage) | float64 -}}
32+
{{- if gt $newSize $oldSize -}}
33+
{{- $needResizePVC = true -}}
34+
{{- end -}}
3135
{{- end -}}
3236
{{- end -}}
3337

‎packages/apps/vm-disk/templates/pvc-resize-hook.yaml‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{{- $existingPVC := lookup "v1" "PersistentVolumeClaim" .Release.Namespace .Release.Name }}
2-
{{- if and $existingPVC (ne ($existingPVC.spec.resources.requests.storage | toString) .Values.storage) -}}
2+
{{- $shouldResize := false -}}
3+
{{- if and $existingPVC .Values.storage -}}
4+
{{- $currentStorage := $existingPVC.spec.resources.requests.storage | toString -}}
5+
{{- if ne $currentStorage .Values.storage -}}
6+
{{- $oldSize := (include "cozy-lib.resources.toFloat" $currentStorage) | float64 -}}
7+
{{- $newSize := (include "cozy-lib.resources.toFloat" .Values.storage) | float64 -}}
8+
{{- if gt $newSize $oldSize -}}
9+
{{- $shouldResize = true -}}
10+
{{- end -}}
11+
{{- end -}}
12+
{{- end -}}
13+
14+
{{- if $shouldResize -}}
315
apiVersion: batch/v1
416
kind: Job
517
metadata:
@@ -23,6 +35,7 @@ spec:
2335
command: ["sh", "-xec"]
2436
args:
2537
- |
38+
echo "Resizing PVC to {{ .Values.storage }}..."
2639
kubectl patch pvc {{ .Release.Name }} -p '{"spec":{"resources":{"requests":{"storage":"{{ .Values.storage }}"}}}}'
2740
---
2841
apiVersion: v1

0 commit comments

Comments
 (0)