Skip to content

Commit c63fb20

Browse files
committed
[apps] virtual-machine: add vpc support
Signed-off-by: nbykov0 <[email protected]>
1 parent dfaf51d commit c63fb20

6 files changed

Lines changed: 93 additions & 8 deletions

File tree

‎packages/apps/virtual-machine/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ virtctl ssh <user>@<vm>
4848
| `systemDisk.image` | The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine`, `fedora` and `talos` | `string` | `ubuntu` |
4949
| `systemDisk.storage` | The size of the disk allocated for the virtual machine | `string` | `5Gi` |
5050
| `systemDisk.storageClass` | StorageClass used to store the data | `*string` | `replicated` |
51+
| `subnets` | Additional subnets (management subnet will be attached by default) | `[]object` | `[]` |
52+
| `subnets[i].name` | Additional subnet to attach | `string` | `""` |
5153
| `gpus` | List of GPUs to attach | `[]object` | `[]` |
5254
| `gpus[i].name` | The name of the GPU to attach. This should match the GPU resource name in the cluster. | `string` | `""` |
5355
| `resources` | Resources | `*object` | `null` |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# if subnets are specified and image is either ubunu or alpine
2+
{{- if and .Values.subnets (or (eq .Values.systemDisk.image "ubuntu") (eq .Values.systemDisk.image "alpine")) }}
3+
---
4+
apiVersion: v1
5+
kind: Secret
6+
metadata:
7+
name: {{ include "virtual-machine.fullname" $ }}-network-config
8+
stringData:
9+
networkData: |
10+
network:
11+
version: 1
12+
config:
13+
{{- if eq .Values.systemDisk.image "ubuntu" }}
14+
# main iface
15+
- type: physical
16+
name: enp1s0
17+
subnets:
18+
- type: dhcp
19+
# additional ifaces attached to subnets
20+
{{- range $i, $subnet := .Values.subnets }}
21+
- type: physical
22+
name: enp{{ add 2 $i }}s0
23+
subnets:
24+
- type: dhcp
25+
{{- end }}
26+
{{- else if eq .Values.systemDisk.image "alpine" }}
27+
#main iface
28+
- type: physical
29+
name: eth0
30+
subnets:
31+
- type: dhcp
32+
# additional ifaces attached to subnets
33+
{{- range $i, $subnet := .Values.subnets }}
34+
- type: physical
35+
name: eth{{ add1 $i }}
36+
subnets:
37+
- type: dhcp
38+
{{- end }}
39+
{{- end }}
40+
{{- end }}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ spec:
5151
{{- else if eq .Values.systemDisk.image "ubuntu" }}
5252
url: https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
5353
{{- else if eq .Values.systemDisk.image "fedora" }}
54-
url: https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
54+
url: https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2
5555
{{- else if eq .Values.systemDisk.image "alpine" }}
56-
url: https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/cloud/nocloud_alpine-3.20.2-x86_64-bios-tiny-r0.qcow2
56+
url: https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/cloud/nocloud_alpine-3.20.8-x86_64-bios-cloudinit-r0.qcow2
5757
{{- else if eq .Values.systemDisk.image "talos" }}
5858
url: https://github.com/siderolabs/talos/releases/download/v1.7.6/nocloud-amd64.raw.xz
5959
{{- end }}
@@ -93,7 +93,7 @@ spec:
9393
- disk:
9494
bus: scsi
9595
name: systemdisk
96-
{{- if or .Values.cloudInit .Values.sshKeys }}
96+
{{- if or .Values.cloudInit .Values.sshKeys (and .Values.subnets (or (eq .Values.systemDisk.image "ubuntu") (eq .Values.systemDisk.image "alpine"))) }}
9797
- disk:
9898
bus: virtio
9999
name: cloudinitdisk
@@ -102,6 +102,12 @@ spec:
102102
interfaces:
103103
- name: default
104104
bridge: {}
105+
{{- if .Values.subnets }}
106+
{{- range $i, $subnet := .Values.subnets }}
107+
- name: {{ $subnet.name }}
108+
bridge: {}
109+
{{- end }}
110+
{{- end }}
105111

106112
machine:
107113
type: ""
@@ -123,13 +129,26 @@ spec:
123129
- name: systemdisk
124130
dataVolume:
125131
name: {{ include "virtual-machine.fullname" . }}
126-
{{- if or .Values.cloudInit .Values.sshKeys }}
132+
{{- if or .Values.cloudInit .Values.sshKeys (and .Values.subnets (or (eq .Values.systemDisk.image "ubuntu") (eq .Values.systemDisk.image "alpine"))) }}
127133
- name: cloudinitdisk
128134
cloudInitNoCloud:
135+
{{- if or .Values.cloudInit .Values.sshKeys }}
129136
secretRef:
130137
name: {{ include "virtual-machine.fullname" . }}-cloud-init
138+
{{- end }}
139+
{{- if and .Values.subnets (or (eq .Values.systemDisk.image "ubuntu") (eq .Values.systemDisk.image "alpine")) }}
140+
networkDataSecretRef:
141+
name: {{ include "virtual-machine.fullname" . }}-network-config
142+
{{- end }}
131143
{{- end }}
132144

133145
networks:
134146
- name: default
135147
pod: {}
148+
{{- if .Values.subnets }}
149+
{{- range $i, $subnet := .Values.subnets }}
150+
- name: {{ $subnet.name }}
151+
multus:
152+
networkName: {{ $.Release.Namespace }}/{{ $subnet.name }}
153+
{{- end }}
154+
{{- end }}

‎packages/apps/virtual-machine/values.schema.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@
165165
"type": "string"
166166
}
167167
},
168+
"subnets": {
169+
"description": "Additional subnets (management subnet will be attached by default)",
170+
"type": "array",
171+
"default": [],
172+
"items": {
173+
"type": "object",
174+
"required": [
175+
"name"
176+
],
177+
"properties": {
178+
"name": {
179+
"description": "Additional subnet to attach",
180+
"type": "string"
181+
}
182+
}
183+
}
184+
},
168185
"systemDisk": {
169186
"description": "System disk configuration",
170187
"type": "object",

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## @section Common parameters
32
##
43
## @param external {bool} Enable external access from outside the cluster
@@ -28,14 +27,22 @@ systemDisk:
2827
storage: 5Gi
2928
storageClass: replicated
3029

30+
## @param subnets {[]subnet} Additional subnets (management subnet will be attached by default)
31+
## @field subnet.name {string} Additional subnet to attach
32+
## Example:
33+
## subnets:
34+
## - name: subnet-84dbec17
35+
## - name: subnet-aa8896b5
36+
## - name: subnet-e9b97196
37+
subnets: []
38+
3139
## @param gpus {[]gpu} List of GPUs to attach
3240
## @field gpu.name {string} The name of the GPU to attach. This should match the GPU resource name in the cluster.
3341
## Example:
3442
## gpus:
3543
## - name: nvidia.com/GA102GL_A10
3644
gpus: []
3745

38-
3946
## @param resources {*resources} Resources
4047
## @field resources.cpu {*quantity} The number of CPU cores allocated to the virtual machine
4148
## @field resources.sockets {*quantity} The number of CPU sockets allocated to the virtual machine (used to define vCPU topology)

0 commit comments

Comments
 (0)