Skip to content

Commit 8f5adcc

Browse files
authored
[system] Add VPC (#1543)
<!-- 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 Add VPC support ### 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 Added VPC support ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** - Added Virtual Private Cloud (VPC) support with configurable subnets, per-subnet network attachments, and generated subnet resources. - Enabled subnet support for Virtual Machine and VM Instance: additional interfaces, Multus networks, and conditional cloud-init/network secret wiring for supported images. * **Documentation** - Added/updated docs and examples for VPC, Virtual Machine, and VM Instance showing subnet parameters. * **Chores** - Expanded admin role permissions to manage Virtual Private Cloud resources. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 08bd918 + 023276e commit 8f5adcc

20 files changed

Lines changed: 348 additions & 8 deletions

File tree

‎packages/apps/tenant/templates/tenant.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ rules:
270270
- vmdisks
271271
- vminstances
272272
- infos
273+
- virtualprivateclouds
273274
verbs:
274275
- get
275276
- list

‎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. | `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 | `[]object` | `[]` |
52+
| `subnets[i].name` | Subnet name | `string` | `""` |
5153
| `gpus` | List of GPUs to attach. | `[]object` | `[]` |
5254
| `gpus[i].name` | The name of the GPU resource to attach. | `string` | `""` |
5355
| `resources` | Resource configuration for the virtual machine. | `object` | `{}` |
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@
167167
"type": "string"
168168
}
169169
},
170+
"subnets": {
171+
"description": "Additional subnets",
172+
"type": "array",
173+
"default": [],
174+
"items": {
175+
"type": "object",
176+
"properties": {
177+
"name": {
178+
"description": "Subnet name",
179+
"type": "string"
180+
}
181+
}
182+
}
183+
},
170184
"systemDisk": {
171185
"description": "System disk configuration.",
172186
"type": "object",

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
## @field {string} storage - The size of the disk allocated for the virtual machine.
1919
## @field {string} [storageClass] - StorageClass used to store the data.
2020

21+
## @typedef {struct} Subnet - Additional subnets
22+
## @field {string} [name] - Subnet name
23+
2124
## @typedef {struct} GPU - GPU device configuration.
2225
## @field {string} name - The name of the GPU resource to attach.
2326

@@ -50,6 +53,14 @@ systemDisk:
5053
storage: 5Gi
5154
storageClass: replicated
5255

56+
## @param {[]Subnet} subnets - Additional subnets
57+
subnets: []
58+
## Example:
59+
## subnets:
60+
## - name: subnet-84dbec17
61+
## - name: subnet-aa8896b5
62+
## - name: subnet-e9b97196
63+
5364
## @param {[]GPU} gpus - List of GPUs to attach.
5465
gpus: []
5566
## Example:

‎packages/apps/vm-instance/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ virtctl ssh <user>@<vm>
4747
| `disks` | List of disks to attach. | `[]object` | `[]` |
4848
| `disks[i].name` | Disk name. | `string` | `""` |
4949
| `disks[i].bus` | Disk bus type (e.g. "sata"). | `string` | `""` |
50+
| `subnets` | Additional subnets | `[]object` | `[]` |
51+
| `subnets[i].name` | Subnet name | `string` | `""` |
5052
| `gpus` | List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM). | `[]object` | `[]` |
5153
| `gpus[i].name` | The name of the GPU resource to attach. | `string` | `""` |
5254
| `resources` | Resource configuration for the virtual machine. | `object` | `{}` |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ spec:
7777
interfaces:
7878
- name: default
7979
bridge: {}
80+
{{- if .Values.subnets }}
81+
{{- range $i, $subnet := .Values.subnets }}
82+
- name: {{ $subnet.name }}
83+
bridge: {}
84+
{{- end }}
85+
{{- end }}
8086
machine:
8187
type: ""
8288
{{- with .Values.sshKeys }}
@@ -105,3 +111,10 @@ spec:
105111
networks:
106112
- name: default
107113
pod: {}
114+
{{- if .Values.subnets }}
115+
{{- range $i, $subnet := .Values.subnets }}
116+
- name: {{ $subnet.name }}
117+
multus:
118+
networkName: {{ $.Release.Namespace }}/{{ $subnet.name }}
119+
{{- end }}
120+
{{- end }}

‎packages/apps/vm-instance/values.schema.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@
187187
"items": {
188188
"type": "string"
189189
}
190+
},
191+
"subnets": {
192+
"description": "Additional subnets",
193+
"type": "array",
194+
"default": [],
195+
"items": {
196+
"type": "object",
197+
"properties": {
198+
"name": {
199+
"description": "Subnet name",
200+
"type": "string"
201+
}
202+
}
203+
}
190204
}
191205
}
192206
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
## @field {string} name - Disk name.
1111
## @field {string} [bus] - Disk bus type (e.g. "sata").
1212

13+
## @typedef {struct} Subnet - Additional subnets
14+
## @field {string} [name] - Subnet name
15+
1316
## @typedef {struct} GPU - GPU device configuration.
1417
## @field {string} name - The name of the GPU resource to attach.
1518

@@ -45,6 +48,14 @@ disks: []
4548
## - name: example-data
4649
## bus: sata
4750

51+
## @param {[]Subnet} subnets - Additional subnets
52+
subnets: []
53+
## Example:
54+
## subnets:
55+
## - name: subnet-84dbec17
56+
## - name: subnet-aa8896b5
57+
## - name: subnet-e9b97196
58+
4859
## @param {[]GPU} gpus - List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM).
4960
gpus: []
5061
## Example:

0 commit comments

Comments
 (0)