Skip to content

Commit 2f53363

Browse files
authored
Add hooks to update instanceType, instanceProfile, and storage (#590)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added update hook for Virtual Machine configurations - Enhanced version management for virtual machine and VM instance packages - **Version Updates** - Virtual Machine package version updated from 0.6.0 to 0.7.0 - VM Instance package version updated from 0.3.0 to 0.4.0 - **Improvements** - Introduced dynamic configuration update mechanisms for Kubernetes deployments - Added service account and role permissions for VM configuration management <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent af58018 commit 2f53363

6 files changed

Lines changed: 226 additions & 11 deletions

File tree

‎packages/apps/versions_map‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ virtual-machine 0.2.0 5ca8823
106106
virtual-machine 0.3.0 b908400
107107
virtual-machine 0.4.0 4746d51
108108
virtual-machine 0.5.0 cad9cde
109-
virtual-machine 0.6.0 HEAD
109+
virtual-machine 0.6.0 0e728870
110+
virtual-machine 0.7.0 HEAD
110111
vm-disk 0.1.0 HEAD
111112
vm-instance 0.1.0 ced8e5b9
112113
vm-instance 0.2.0 4f767ee3
113-
vm-instance 0.3.0 HEAD
114+
vm-instance 0.3.0 0e728870
115+
vm-instance 0.4.0 HEAD
114116
vpn 0.1.0 f642698
115117
vpn 0.2.0 7151424
116118
vpn 0.3.0 a2bcf100

‎packages/apps/virtual-machine/Chart.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type: application
1717
# This is the chart version. This version number should be incremented each time you make changes
1818
# to the chart and its templates, including the app version.
1919
# Versions are expected to follow Semantic Versioning (https://semver.org/)
20-
version: 0.6.0
20+
version: 0.7.0
2121

2222
# This is the version number of the application being deployed. This version number should be
2323
# incremented each time you make changes to the application. Versions are not expected to
2424
# follow Semantic Versioning. They should reflect the version the application is using.
2525
# It is recommended to use it with quotes.
26-
appVersion: "1.16.1"
26+
appVersion: "0.7.0"
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{{- $vmName := include "virtual-machine.fullname" . -}}
2+
{{- $namespace := .Release.Namespace -}}
3+
4+
{{- $existingVM := lookup "kubevirt.io/v1" "VirtualMachine" $namespace $vmName -}}
5+
{{- $existingPVC := lookup "v1" "PersistentVolumeClaim" $namespace $vmName -}}
6+
7+
{{- $instanceType := .Values.instanceType | default "" -}}
8+
{{- $instanceProfile := .Values.instanceProfile | default "" -}}
9+
{{- $desiredStorage := .Values.systemDisk.storage | default "" -}}
10+
11+
{{- $needUpdateType := false -}}
12+
{{- $needUpdateProfile := false -}}
13+
{{- $needResizePVC := false -}}
14+
15+
{{- if and $existingVM $instanceType -}}
16+
{{- if not (eq $existingVM.spec.instancetype.name $instanceType) -}}
17+
{{- $needUpdateType = true -}}
18+
{{- end -}}
19+
{{- end -}}
20+
21+
{{- if and $existingVM $instanceProfile -}}
22+
{{- if not (eq $existingVM.spec.preference.name $instanceProfile) -}}
23+
{{- $needUpdateProfile = true -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{- if and $existingPVC $desiredStorage -}}
28+
{{- $currentStorage := $existingPVC.spec.resources.requests.storage | toString -}}
29+
{{- if not (eq $currentStorage $desiredStorage) -}}
30+
{{- $needResizePVC = true -}}
31+
{{- end -}}
32+
{{- end -}}
33+
34+
{{- if or $needUpdateType $needUpdateProfile $needResizePVC }}
35+
apiVersion: batch/v1
36+
kind: Job
37+
metadata:
38+
name: "{{ $.Release.Name }}-update-hook"
39+
annotations:
40+
helm.sh/hook: pre-install,pre-upgrade
41+
helm.sh/hook-weight: "0"
42+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
43+
spec:
44+
template:
45+
metadata:
46+
labels:
47+
app: "{{ $.Release.Name }}-update-hook"
48+
spec:
49+
serviceAccountName: {{ $.Release.Name }}-update-hook
50+
restartPolicy: Never
51+
containers:
52+
- name: update-resources
53+
image: bitnami/kubectl:latest
54+
command: ["sh", "-exc"]
55+
args:
56+
- |
57+
{{- if $needUpdateType }}
58+
echo "Patching VirtualMachine for instancetype update..."
59+
kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \
60+
--type merge \
61+
-p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}'
62+
{{- end }}
63+
64+
{{- if $needUpdateProfile }}
65+
echo "Patching VirtualMachine for preference update..."
66+
kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \
67+
--type merge \
68+
-p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}'
69+
{{- end }}
70+
71+
{{- if $needResizePVC }}
72+
echo "Patching PVC for storage resize..."
73+
kubectl patch pvc {{ $vmName }} -n {{ $namespace }} \
74+
--type merge \
75+
-p '{"spec":{"resources":{"requests":{"storage":"{{ $desiredStorage }}"}}}}'
76+
{{- end }}
77+
---
78+
apiVersion: v1
79+
kind: ServiceAccount
80+
metadata:
81+
name: {{ $.Release.Name }}-update-hook
82+
annotations:
83+
helm.sh/hook: pre-install,pre-upgrade
84+
helm.sh/hook-weight: "-5"
85+
helm.sh/hook-delete-policy: before-hook-creation
86+
---
87+
apiVersion: rbac.authorization.k8s.io/v1
88+
kind: Role
89+
metadata:
90+
name: {{ $.Release.Name }}-update-hook
91+
annotations:
92+
helm.sh/hook: pre-install,pre-upgrade
93+
helm.sh/hook-weight: "-5"
94+
helm.sh/hook-delete-policy: before-hook-creation
95+
rules:
96+
- apiGroups: ["kubevirt.io"]
97+
resources: ["virtualmachines"]
98+
verbs: ["patch", "get", "list", "watch"]
99+
- apiGroups: [""]
100+
resources: ["persistentvolumeclaims"]
101+
verbs: ["patch", "get", "list", "watch"]
102+
---
103+
apiVersion: rbac.authorization.k8s.io/v1
104+
kind: RoleBinding
105+
metadata:
106+
name: {{ $.Release.Name }}-update-hook
107+
annotations:
108+
helm.sh/hook: pre-install,pre-upgrade
109+
helm.sh/hook-weight: "-5"
110+
helm.sh/hook-delete-policy: before-hook-creation
111+
subjects:
112+
- kind: ServiceAccount
113+
name: {{ $.Release.Name }}-update-hook
114+
roleRef:
115+
kind: Role
116+
name: {{ $.Release.Name }}-update-hook
117+
apiGroup: rbac.authorization.k8s.io
118+
{{- end }}

‎packages/apps/vm-instance/Chart.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type: application
1717
# This is the chart version. This version number should be incremented each time you make changes
1818
# to the chart and its templates, including the app version.
1919
# Versions are expected to follow Semantic Versioning (https://semver.org/)
20-
version: 0.3.0
20+
version: 0.4.0
2121

2222
# This is the version number of the application being deployed. This version number should be
2323
# incremented each time you make changes to the application. Versions are not expected to
2424
# follow Semantic Versioning. They should reflect the version the application is using.
2525
# It is recommended to use it with quotes.
26-
appVersion: "0.2.0"
26+
appVersion: "0.4.0"
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{{- $vmName := include "virtual-machine.fullname" . -}}
2+
{{- $namespace := .Release.Namespace -}}
3+
4+
{{- $existingVM := lookup "kubevirt.io/v1" "VirtualMachine" $namespace $vmName -}}
5+
6+
{{- $instanceType := .Values.instanceType | default "" -}}
7+
{{- $instanceProfile := .Values.instanceProfile | default "" -}}
8+
9+
{{- $needUpdateType := false -}}
10+
{{- $needUpdateProfile := false -}}
11+
12+
{{- if and $existingVM $instanceType -}}
13+
{{- if not (eq $existingVM.spec.instancetype.name $instanceType) -}}
14+
{{- $needUpdateType = true -}}
15+
{{- end -}}
16+
{{- end -}}
17+
18+
{{- if and $existingVM $instanceProfile -}}
19+
{{- if not (eq $existingVM.spec.preference.name $instanceProfile) -}}
20+
{{- $needUpdateProfile = true -}}
21+
{{- end -}}
22+
{{- end -}}
23+
24+
{{- if or $needUpdateType $needUpdateProfile }}
25+
apiVersion: batch/v1
26+
kind: Job
27+
metadata:
28+
name: "{{ $.Release.Name }}-update-hook"
29+
annotations:
30+
helm.sh/hook: pre-install,pre-upgrade
31+
helm.sh/hook-weight: "0"
32+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
33+
spec:
34+
template:
35+
metadata:
36+
labels:
37+
app: "{{ $.Release.Name }}-update-hook"
38+
spec:
39+
serviceAccountName: {{ $.Release.Name }}-update-hook
40+
restartPolicy: Never
41+
containers:
42+
- name: update-resources
43+
image: bitnami/kubectl:latest
44+
command: ["sh", "-exc"]
45+
args:
46+
- |
47+
{{- if $needUpdateType }}
48+
echo "Patching VirtualMachine for instancetype update..."
49+
kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \
50+
--type merge \
51+
-p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}'
52+
{{- end }}
53+
54+
{{- if $needUpdateProfile }}
55+
echo "Patching VirtualMachine for preference update..."
56+
kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \
57+
--type merge \
58+
-p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}'
59+
{{- end }}
60+
---
61+
apiVersion: v1
62+
kind: ServiceAccount
63+
metadata:
64+
name: {{ $.Release.Name }}-update-hook
65+
annotations:
66+
helm.sh/hook: pre-install,pre-upgrade
67+
helm.sh/hook-weight: "-5"
68+
helm.sh/hook-delete-policy: before-hook-creation
69+
---
70+
apiVersion: rbac.authorization.k8s.io/v1
71+
kind: Role
72+
metadata:
73+
name: {{ $.Release.Name }}-update-hook
74+
annotations:
75+
helm.sh/hook: pre-install,pre-upgrade
76+
helm.sh/hook-weight: "-5"
77+
helm.sh/hook-delete-policy: before-hook-creation
78+
rules:
79+
- apiGroups: ["kubevirt.io"]
80+
resources: ["virtualmachines"]
81+
verbs: ["patch", "get", "list", "watch"]
82+
---
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
kind: RoleBinding
85+
metadata:
86+
name: {{ $.Release.Name }}-update-hook
87+
annotations:
88+
helm.sh/hook: pre-install,pre-upgrade
89+
helm.sh/hook-weight: "-5"
90+
helm.sh/hook-delete-policy: before-hook-creation
91+
subjects:
92+
- kind: ServiceAccount
93+
name: {{ $.Release.Name }}-update-hook
94+
roleRef:
95+
kind: Role
96+
name: {{ $.Release.Name }}-update-hook
97+
apiGroup: rbac.authorization.k8s.io
98+
{{- end }}

‎packages/apps/vm-instance/templates/vm.yaml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ spec:
1717
instancetype:
1818
kind: VirtualMachineClusterInstancetype
1919
name: {{ . }}
20-
revisionName: null
21-
{{- end }}
20+
{{- end }}
2221
{{- with .Values.instanceProfile }}
2322
preference:
2423
kind: VirtualMachineClusterPreference
2524
name: {{ . }}
26-
revisionName: null
27-
{{- end }}
28-
25+
{{- end }}
2926
template:
3027
metadata:
3128
annotations:

0 commit comments

Comments
 (0)