-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 -->
- Loading branch information
Showing
6 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/apps/virtual-machine/templates/vm-update-hook.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters