diff --git a/packages/apps/versions_map b/packages/apps/versions_map index 438874635..8fe11ebac 100644 --- a/packages/apps/versions_map +++ b/packages/apps/versions_map @@ -106,11 +106,13 @@ virtual-machine 0.2.0 5ca8823 virtual-machine 0.3.0 b908400 virtual-machine 0.4.0 4746d51 virtual-machine 0.5.0 cad9cde -virtual-machine 0.6.0 HEAD +virtual-machine 0.6.0 0e728870 +virtual-machine 0.7.0 HEAD vm-disk 0.1.0 HEAD vm-instance 0.1.0 ced8e5b9 vm-instance 0.2.0 4f767ee3 -vm-instance 0.3.0 HEAD +vm-instance 0.3.0 0e728870 +vm-instance 0.4.0 HEAD vpn 0.1.0 f642698 vpn 0.2.0 7151424 vpn 0.3.0 a2bcf100 diff --git a/packages/apps/virtual-machine/Chart.yaml b/packages/apps/virtual-machine/Chart.yaml index ffff00a80..442002a39 100644 --- a/packages/apps/virtual-machine/Chart.yaml +++ b/packages/apps/virtual-machine/Chart.yaml @@ -17,10 +17,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.6.0 +version: 0.7.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.16.1" +appVersion: "0.7.0" diff --git a/packages/apps/virtual-machine/templates/vm-update-hook.yaml b/packages/apps/virtual-machine/templates/vm-update-hook.yaml new file mode 100644 index 000000000..0efb21762 --- /dev/null +++ b/packages/apps/virtual-machine/templates/vm-update-hook.yaml @@ -0,0 +1,118 @@ +{{- $vmName := include "virtual-machine.fullname" . -}} +{{- $namespace := .Release.Namespace -}} + +{{- $existingVM := lookup "kubevirt.io/v1" "VirtualMachine" $namespace $vmName -}} +{{- $existingPVC := lookup "v1" "PersistentVolumeClaim" $namespace $vmName -}} + +{{- $instanceType := .Values.instanceType | default "" -}} +{{- $instanceProfile := .Values.instanceProfile | default "" -}} +{{- $desiredStorage := .Values.systemDisk.storage | default "" -}} + +{{- $needUpdateType := false -}} +{{- $needUpdateProfile := false -}} +{{- $needResizePVC := false -}} + +{{- if and $existingVM $instanceType -}} + {{- if not (eq $existingVM.spec.instancetype.name $instanceType) -}} + {{- $needUpdateType = true -}} + {{- end -}} +{{- end -}} + +{{- if and $existingVM $instanceProfile -}} + {{- if not (eq $existingVM.spec.preference.name $instanceProfile) -}} + {{- $needUpdateProfile = true -}} + {{- end -}} +{{- end -}} + +{{- if and $existingPVC $desiredStorage -}} + {{- $currentStorage := $existingPVC.spec.resources.requests.storage | toString -}} + {{- if not (eq $currentStorage $desiredStorage) -}} + {{- $needResizePVC = true -}} + {{- end -}} +{{- end -}} + +{{- if or $needUpdateType $needUpdateProfile $needResizePVC }} +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ $.Release.Name }}-update-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: + app: "{{ $.Release.Name }}-update-hook" + spec: + serviceAccountName: {{ $.Release.Name }}-update-hook + restartPolicy: Never + containers: + - name: update-resources + image: bitnami/kubectl:latest + command: ["sh", "-exc"] + args: + - | + {{- if $needUpdateType }} + echo "Patching VirtualMachine for instancetype update..." + kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \ + --type merge \ + -p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}' + {{- end }} + + {{- if $needUpdateProfile }} + echo "Patching VirtualMachine for preference update..." + kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \ + --type merge \ + -p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}' + {{- end }} + + {{- if $needResizePVC }} + echo "Patching PVC for storage resize..." + kubectl patch pvc {{ $vmName }} -n {{ $namespace }} \ + --type merge \ + -p '{"spec":{"resources":{"requests":{"storage":"{{ $desiredStorage }}"}}}}' + {{- end }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $.Release.Name }}-update-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 }}-update-hook + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-5" + helm.sh/hook-delete-policy: before-hook-creation +rules: + - apiGroups: ["kubevirt.io"] + resources: ["virtualmachines"] + verbs: ["patch", "get", "list", "watch"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["patch", "get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ $.Release.Name }}-update-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 }}-update-hook +roleRef: + kind: Role + name: {{ $.Release.Name }}-update-hook + apiGroup: rbac.authorization.k8s.io +{{- end }} diff --git a/packages/apps/vm-instance/Chart.yaml b/packages/apps/vm-instance/Chart.yaml index 055a0bd5c..7194e2270 100644 --- a/packages/apps/vm-instance/Chart.yaml +++ b/packages/apps/vm-instance/Chart.yaml @@ -17,10 +17,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.3.0 +version: 0.4.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.2.0" +appVersion: "0.4.0" diff --git a/packages/apps/vm-instance/templates/vm-update-hook.yaml b/packages/apps/vm-instance/templates/vm-update-hook.yaml new file mode 100644 index 000000000..437d5c05f --- /dev/null +++ b/packages/apps/vm-instance/templates/vm-update-hook.yaml @@ -0,0 +1,98 @@ +{{- $vmName := include "virtual-machine.fullname" . -}} +{{- $namespace := .Release.Namespace -}} + +{{- $existingVM := lookup "kubevirt.io/v1" "VirtualMachine" $namespace $vmName -}} + +{{- $instanceType := .Values.instanceType | default "" -}} +{{- $instanceProfile := .Values.instanceProfile | default "" -}} + +{{- $needUpdateType := false -}} +{{- $needUpdateProfile := false -}} + +{{- if and $existingVM $instanceType -}} + {{- if not (eq $existingVM.spec.instancetype.name $instanceType) -}} + {{- $needUpdateType = true -}} + {{- end -}} +{{- end -}} + +{{- if and $existingVM $instanceProfile -}} + {{- if not (eq $existingVM.spec.preference.name $instanceProfile) -}} + {{- $needUpdateProfile = true -}} + {{- end -}} +{{- end -}} + +{{- if or $needUpdateType $needUpdateProfile }} +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ $.Release.Name }}-update-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: + app: "{{ $.Release.Name }}-update-hook" + spec: + serviceAccountName: {{ $.Release.Name }}-update-hook + restartPolicy: Never + containers: + - name: update-resources + image: bitnami/kubectl:latest + command: ["sh", "-exc"] + args: + - | + {{- if $needUpdateType }} + echo "Patching VirtualMachine for instancetype update..." + kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \ + --type merge \ + -p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}' + {{- end }} + + {{- if $needUpdateProfile }} + echo "Patching VirtualMachine for preference update..." + kubectl patch virtualmachine {{ $vmName }} -n {{ $namespace }} \ + --type merge \ + -p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}' + {{- end }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $.Release.Name }}-update-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 }}-update-hook + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-5" + helm.sh/hook-delete-policy: before-hook-creation +rules: + - apiGroups: ["kubevirt.io"] + resources: ["virtualmachines"] + verbs: ["patch", "get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ $.Release.Name }}-update-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 }}-update-hook +roleRef: + kind: Role + name: {{ $.Release.Name }}-update-hook + apiGroup: rbac.authorization.k8s.io +{{- end }} diff --git a/packages/apps/vm-instance/templates/vm.yaml b/packages/apps/vm-instance/templates/vm.yaml index 3b0d48f40..eb6ec94b3 100644 --- a/packages/apps/vm-instance/templates/vm.yaml +++ b/packages/apps/vm-instance/templates/vm.yaml @@ -17,15 +17,12 @@ spec: instancetype: kind: VirtualMachineClusterInstancetype name: {{ . }} - revisionName: null - {{- end }} + {{- end }} {{- with .Values.instanceProfile }} preference: kind: VirtualMachineClusterPreference name: {{ . }} - revisionName: null - {{- end }} - + {{- end }} template: metadata: annotations: