Skip to content

Commit b6635a0

Browse files
authored
Add API spec for machine ip pool ref (#429)
* WIP: Add API spec for machine ip pool ref * Adjusting code to comply with the new API * Implement the logic for the IP Pool Ref for proxmoxmachines * Make Default network required when setting network and add tests
1 parent 5a50fbd commit b6635a0

15 files changed

+604
-129
lines changed

api/v1alpha1/proxmoxmachine_types.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ type NetworkSpec struct {
271271
VirtualNetworkDevices `json:",inline"`
272272
}
273273

274-
// InterfaceConfig contains all configurables a network interface can have.
275-
type InterfaceConfig struct {
274+
// IPPoolConfig defines the IPAM pool ref.
275+
type IPPoolConfig struct {
276276
// IPv4PoolRef is a reference to an IPAM Pool resource, which exposes IPv4 addresses.
277277
// The network device will use an available IP address from the referenced pool.
278278
// This can be combined with `IPv6PoolRef` in order to enable dual stack.
@@ -288,13 +288,10 @@ type InterfaceConfig struct {
288288
// +kubebuilder:validation:XValidation:rule="self.apiGroup == 'ipam.cluster.x-k8s.io'",message="ipv6PoolRef allows only IPAM apiGroup ipam.cluster.x-k8s.io"
289289
// +kubebuilder:validation:XValidation:rule="self.kind == 'InClusterIPPool' || self.kind == 'GlobalInClusterIPPool'",message="ipv6PoolRef allows either InClusterIPPool or GlobalInClusterIPPool"
290290
IPv6PoolRef *corev1.TypedLocalObjectReference `json:"ipv6PoolRef,omitempty"`
291+
}
291292

292-
// DNSServers contains information about nameservers to be used for this interface.
293-
// If this field is not set, it will use the default dns servers from the ProxmoxCluster.
294-
// +optional
295-
// +kubebuilder:validation:MinItems=1
296-
DNSServers []string `json:"dnsServers,omitempty"`
297-
293+
// InterfaceConfig contains all configurables a network interface can have.
294+
type InterfaceConfig struct {
298295
// Routing is the common spec of routes and routing policies to all interfaces and VRFs.
299296
Routing `json:",inline"`
300297

@@ -404,6 +401,19 @@ type NetworkDevice struct {
404401
// +kubebuilder:validation:Minimum=1
405402
// +kubebuilder:validation:Maximum=4094
406403
VLAN *uint16 `json:"vlan,omitempty"`
404+
405+
// DNSServers contains information about nameservers to be used for this interface.
406+
// If this field is not set, it will use the default dns servers from the ProxmoxCluster.
407+
// +optional
408+
// +kubebuilder:validation:MinItems=1
409+
DNSServers []string `json:"dnsServers,omitempty"`
410+
411+
// IPPoolConfig defines config for IP Pool ref.
412+
// For default device 'net0' the IP pool is optional,
413+
// If not set, the default IPAM pool will be used.
414+
// For additional devices, the IP pool is required (IPV4/IPV6).
415+
// +optional
416+
IPPoolConfig `json:",inline"`
407417
}
408418

409419
// MTU is the network device Maximum Transmission Unit. MTUs below 1280 break IPv6.

api/v1alpha1/proxmoxmachine_types_test.go

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ var _ = Describe("ProxmoxMachine Test", func() {
179179
},
180180
AdditionalDevices: []AdditionalNetworkDevice{
181181
{
182-
NetworkDevice: NetworkDevice{},
183-
Name: "net0",
184-
InterfaceConfig: InterfaceConfig{
185-
IPv4PoolRef: &corev1.TypedLocalObjectReference{
186-
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
187-
Kind: "InClusterIPPool",
188-
Name: "some-pool",
182+
NetworkDevice: NetworkDevice{
183+
IPPoolConfig: IPPoolConfig{
184+
IPv4PoolRef: &corev1.TypedLocalObjectReference{
185+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
186+
Kind: "InClusterIPPool",
187+
Name: "some-pool",
188+
},
189189
},
190190
},
191+
Name: "net0",
192+
InterfaceConfig: InterfaceConfig{},
191193
},
192194
},
193195
}
@@ -200,14 +202,15 @@ var _ = Describe("ProxmoxMachine Test", func() {
200202
dm.Spec.Network = &NetworkSpec{
201203
AdditionalDevices: []AdditionalNetworkDevice{
202204
{
203-
NetworkDevice: NetworkDevice{},
204-
Name: "net1",
205-
InterfaceConfig: InterfaceConfig{
206-
IPv4PoolRef: &corev1.TypedLocalObjectReference{
207-
APIGroup: ptr.To("apps"),
208-
Name: "some-app",
205+
NetworkDevice: NetworkDevice{
206+
IPPoolConfig: IPPoolConfig{
207+
IPv4PoolRef: &corev1.TypedLocalObjectReference{
208+
APIGroup: ptr.To("apps"),
209+
Name: "some-app",
210+
},
209211
},
210212
},
213+
Name: "net1",
211214
},
212215
},
213216
}
@@ -219,13 +222,17 @@ var _ = Describe("ProxmoxMachine Test", func() {
219222
dm.Spec.Network = &NetworkSpec{
220223
AdditionalDevices: []AdditionalNetworkDevice{
221224
{
222-
NetworkDevice: NetworkDevice{},
223-
Name: "net1",
224-
InterfaceConfig: InterfaceConfig{IPv4PoolRef: &corev1.TypedLocalObjectReference{
225-
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
226-
Kind: "ConfigMap",
227-
Name: "some-app",
228-
}},
225+
NetworkDevice: NetworkDevice{
226+
IPPoolConfig: IPPoolConfig{
227+
IPv4PoolRef: &corev1.TypedLocalObjectReference{
228+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
229+
Kind: "ConfigMap",
230+
Name: "some-app",
231+
},
232+
},
233+
},
234+
Name: "net1",
235+
InterfaceConfig: InterfaceConfig{},
229236
},
230237
},
231238
}
@@ -237,14 +244,16 @@ var _ = Describe("ProxmoxMachine Test", func() {
237244
dm.Spec.Network = &NetworkSpec{
238245
AdditionalDevices: []AdditionalNetworkDevice{
239246
{
240-
NetworkDevice: NetworkDevice{},
241-
Name: "net1",
242-
InterfaceConfig: InterfaceConfig{
243-
IPv6PoolRef: &corev1.TypedLocalObjectReference{
244-
APIGroup: ptr.To("apps"),
245-
Name: "some-app",
247+
NetworkDevice: NetworkDevice{
248+
IPPoolConfig: IPPoolConfig{
249+
IPv6PoolRef: &corev1.TypedLocalObjectReference{
250+
APIGroup: ptr.To("apps"),
251+
Name: "some-app",
252+
},
246253
},
247254
},
255+
Name: "net1",
256+
InterfaceConfig: InterfaceConfig{},
248257
},
249258
},
250259
}
@@ -256,15 +265,17 @@ var _ = Describe("ProxmoxMachine Test", func() {
256265
dm.Spec.Network = &NetworkSpec{
257266
AdditionalDevices: []AdditionalNetworkDevice{
258267
{
259-
NetworkDevice: NetworkDevice{},
260-
Name: "net1",
261-
InterfaceConfig: InterfaceConfig{
262-
IPv6PoolRef: &corev1.TypedLocalObjectReference{
263-
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
264-
Kind: "ConfigMap",
265-
Name: "some-app",
268+
NetworkDevice: NetworkDevice{
269+
IPPoolConfig: IPPoolConfig{
270+
IPv6PoolRef: &corev1.TypedLocalObjectReference{
271+
APIGroup: ptr.To("ipam.cluster.x-k8s.io"),
272+
Kind: "ConfigMap",
273+
Name: "some-app",
274+
},
266275
},
267276
},
277+
Name: "net1",
278+
InterfaceConfig: InterfaceConfig{},
268279
},
269280
},
270281
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 21 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclusters.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,80 @@ spec:
388388
to the machine.
389389
minLength: 1
390390
type: string
391+
dnsServers:
392+
description: |-
393+
DNSServers contains information about nameservers to be used for this interface.
394+
If this field is not set, it will use the default dns servers from the ProxmoxCluster.
395+
items:
396+
type: string
397+
minItems: 1
398+
type: array
399+
ipv4PoolRef:
400+
description: |-
401+
IPv4PoolRef is a reference to an IPAM Pool resource, which exposes IPv4 addresses.
402+
The network device will use an available IP address from the referenced pool.
403+
This can be combined with `IPv6PoolRef` in order to enable dual stack.
404+
properties:
405+
apiGroup:
406+
description: |-
407+
APIGroup is the group for the resource being referenced.
408+
If APIGroup is not specified, the specified Kind must be in the core API group.
409+
For any other third-party types, APIGroup is required.
410+
type: string
411+
kind:
412+
description: Kind is the type of resource being
413+
referenced
414+
type: string
415+
name:
416+
description: Name is the name of resource being
417+
referenced
418+
type: string
419+
required:
420+
- kind
421+
- name
422+
type: object
423+
x-kubernetes-map-type: atomic
424+
x-kubernetes-validations:
425+
- message: ipv4PoolRef allows only IPAM apiGroup
426+
ipam.cluster.x-k8s.io
427+
rule: self.apiGroup == 'ipam.cluster.x-k8s.io'
428+
- message: ipv4PoolRef allows either InClusterIPPool
429+
or GlobalInClusterIPPool
430+
rule: self.kind == 'InClusterIPPool' || self.kind
431+
== 'GlobalInClusterIPPool'
432+
ipv6PoolRef:
433+
description: |-
434+
IPv6PoolRef is a reference to an IPAM pool resource, which exposes IPv6 addresses.
435+
The network device will use an available IP address from the referenced pool.
436+
this can be combined with `IPv4PoolRef` in order to enable dual stack.
437+
properties:
438+
apiGroup:
439+
description: |-
440+
APIGroup is the group for the resource being referenced.
441+
If APIGroup is not specified, the specified Kind must be in the core API group.
442+
For any other third-party types, APIGroup is required.
443+
type: string
444+
kind:
445+
description: Kind is the type of resource being
446+
referenced
447+
type: string
448+
name:
449+
description: Name is the name of resource being
450+
referenced
451+
type: string
452+
required:
453+
- kind
454+
- name
455+
type: object
456+
x-kubernetes-map-type: atomic
457+
x-kubernetes-validations:
458+
- message: ipv6PoolRef allows only IPAM apiGroup
459+
ipam.cluster.x-k8s.io
460+
rule: self.apiGroup == 'ipam.cluster.x-k8s.io'
461+
- message: ipv6PoolRef allows either InClusterIPPool
462+
or GlobalInClusterIPPool
463+
rule: self.kind == 'InClusterIPPool' || self.kind
464+
== 'GlobalInClusterIPPool'
391465
model:
392466
default: virtio
393467
description: Model is the network device model.

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxclustertemplates.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,80 @@ spec:
418418
to attach to the machine.
419419
minLength: 1
420420
type: string
421+
dnsServers:
422+
description: |-
423+
DNSServers contains information about nameservers to be used for this interface.
424+
If this field is not set, it will use the default dns servers from the ProxmoxCluster.
425+
items:
426+
type: string
427+
minItems: 1
428+
type: array
429+
ipv4PoolRef:
430+
description: |-
431+
IPv4PoolRef is a reference to an IPAM Pool resource, which exposes IPv4 addresses.
432+
The network device will use an available IP address from the referenced pool.
433+
This can be combined with `IPv6PoolRef` in order to enable dual stack.
434+
properties:
435+
apiGroup:
436+
description: |-
437+
APIGroup is the group for the resource being referenced.
438+
If APIGroup is not specified, the specified Kind must be in the core API group.
439+
For any other third-party types, APIGroup is required.
440+
type: string
441+
kind:
442+
description: Kind is the type of resource
443+
being referenced
444+
type: string
445+
name:
446+
description: Name is the name of resource
447+
being referenced
448+
type: string
449+
required:
450+
- kind
451+
- name
452+
type: object
453+
x-kubernetes-map-type: atomic
454+
x-kubernetes-validations:
455+
- message: ipv4PoolRef allows only IPAM
456+
apiGroup ipam.cluster.x-k8s.io
457+
rule: self.apiGroup == 'ipam.cluster.x-k8s.io'
458+
- message: ipv4PoolRef allows either InClusterIPPool
459+
or GlobalInClusterIPPool
460+
rule: self.kind == 'InClusterIPPool' ||
461+
self.kind == 'GlobalInClusterIPPool'
462+
ipv6PoolRef:
463+
description: |-
464+
IPv6PoolRef is a reference to an IPAM pool resource, which exposes IPv6 addresses.
465+
The network device will use an available IP address from the referenced pool.
466+
this can be combined with `IPv4PoolRef` in order to enable dual stack.
467+
properties:
468+
apiGroup:
469+
description: |-
470+
APIGroup is the group for the resource being referenced.
471+
If APIGroup is not specified, the specified Kind must be in the core API group.
472+
For any other third-party types, APIGroup is required.
473+
type: string
474+
kind:
475+
description: Kind is the type of resource
476+
being referenced
477+
type: string
478+
name:
479+
description: Name is the name of resource
480+
being referenced
481+
type: string
482+
required:
483+
- kind
484+
- name
485+
type: object
486+
x-kubernetes-map-type: atomic
487+
x-kubernetes-validations:
488+
- message: ipv6PoolRef allows only IPAM
489+
apiGroup ipam.cluster.x-k8s.io
490+
rule: self.apiGroup == 'ipam.cluster.x-k8s.io'
491+
- message: ipv6PoolRef allows either InClusterIPPool
492+
or GlobalInClusterIPPool
493+
rule: self.kind == 'InClusterIPPool' ||
494+
self.kind == 'GlobalInClusterIPPool'
421495
model:
422496
default: virtio
423497
description: Model is the network device

0 commit comments

Comments
 (0)