Skip to content

Commit 039f703

Browse files
pbasovdukov
authored andcommitted
Add trunk subports support for OpenStackMachine ports
This adds the ability to specify subports when creating trunk ports. Users can now define VLAN subports that will be attached to the trunk when the port is created. Example usage: ports: - network: filter: name: foo_vlan_300 trunk: true subports: - network: filter: name: bar_vlan_301 segmentationID: 301 segmentationType: "vlan" - Added SubportOpts and ResolvedSubportSpec types to API - Since sub-ports and ports are essentially the same entities CommonPortOpts and CommonResolvedPortSpec types were introduced as a basis for regular ports and trunk subports - Added SubPortStatus to keep track of ports which are associated with trunk - Introduced separate method for adding supports to trunk - Added AddSubports method to NetworkClient interface - Added validation to ensure subports require trunk enabled - Updated port normalization to resolve subports
1 parent 0c82f66 commit 039f703

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6451
-618
lines changed

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/conversion_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ func TestFuzzyConversion(t *testing.T) {
9696
// None of the following identityRef fields have ever been set in v1alpha7
9797
identityRef.Region = ""
9898
},
99+
func(portOpts *infrav1.PortOpts, c fuzz.Continue) {
100+
c.FuzzNoCustom(portOpts)
101+
102+
// None of the following PortOpts fields have ever been set in v1alpha7
103+
portOpts.Subports = nil
104+
},
99105
}
100106

101107
return slices.Concat(v1alpha7FuzzerFuncs, testhelpers.InfraV1FuzzerFuncs())

api/v1alpha7/types_conversion.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package v1alpha7
1818

1919
import (
2020
"errors"
21+
unsafe "unsafe"
2122

2223
apiconversion "k8s.io/apimachinery/pkg/conversion"
2324

2425
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
26+
v1beta1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2527
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversioncommon"
2628
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2729
)
@@ -426,6 +428,35 @@ func Convert_v1alpha7_PortOpts_To_v1beta1_PortOpts(in *PortOpts, out *infrav1.Po
426428
}
427429
}
428430

431+
if in.Network != nil {
432+
in, out := &in.Network, &out.Network
433+
*out = new(v1beta1.NetworkParam)
434+
if err := Convert_v1alpha7_NetworkFilter_To_v1beta1_NetworkParam(*in, *out, s); err != nil {
435+
return err
436+
}
437+
} else {
438+
out.Network = nil
439+
}
440+
if err := optional.Convert_string_To_optional_String(&in.NameSuffix, &out.NameSuffix, s); err != nil {
441+
return err
442+
}
443+
if err := optional.Convert_string_To_optional_String(&in.Description, &out.Description, s); err != nil {
444+
return err
445+
}
446+
447+
if in.FixedIPs != nil {
448+
in, out := &in.FixedIPs, &out.FixedIPs
449+
*out = make([]v1beta1.FixedIP, len(*in))
450+
for i := range *in {
451+
if err := Convert_v1alpha7_FixedIP_To_v1beta1_FixedIP(&(*in)[i], &(*out)[i], s); err != nil {
452+
return err
453+
}
454+
}
455+
} else {
456+
out.FixedIPs = nil
457+
}
458+
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
459+
429460
return nil
430461
}
431462

@@ -482,6 +513,34 @@ func Convert_v1beta1_PortOpts_To_v1alpha7_PortOpts(in *infrav1.PortOpts, out *Po
482513
}
483514
}
484515

516+
if in.Network != nil {
517+
in, out := &in.Network, &out.Network
518+
*out = new(NetworkFilter)
519+
if err := Convert_v1beta1_NetworkParam_To_v1alpha7_NetworkFilter(*in, *out, s); err != nil {
520+
return err
521+
}
522+
} else {
523+
out.Network = nil
524+
}
525+
if err := optional.Convert_optional_String_To_string(&in.Description, &out.Description, s); err != nil {
526+
return err
527+
}
528+
if err := optional.Convert_optional_String_To_string(&in.NameSuffix, &out.NameSuffix, s); err != nil {
529+
return err
530+
}
531+
if in.FixedIPs != nil {
532+
in, out := &in.FixedIPs, &out.FixedIPs
533+
*out = make([]FixedIP, len(*in))
534+
for i := range *in {
535+
if err := Convert_v1beta1_FixedIP_To_v1alpha7_FixedIP(&(*in)[i], &(*out)[i], s); err != nil {
536+
return err
537+
}
538+
}
539+
} else {
540+
out.FixedIPs = nil
541+
}
542+
out.Tags = *(*[]string)(unsafe.Pointer(&in.Tags))
543+
485544
return nil
486545
}
487546

api/v1alpha7/zz_generated.conversion.go

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

api/v1beta1/types.go

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ type AllocationPool struct {
290290
End string `json:"end"`
291291
}
292292

293-
type PortOpts struct {
293+
type CommonPortOpts struct {
294294
// Network is a query for an openstack network that the port will be created or discovered on.
295295
// This will fail if the query returns more than one network.
296296
// +optional
@@ -320,13 +320,41 @@ type PortOpts struct {
320320
// +optional
321321
Tags []string `json:"tags,omitempty"`
322322

323+
ResolvedPortSpecFields `json:",inline"`
324+
}
325+
326+
// PortOpts defines port parameters.
327+
type PortOpts struct {
323328
// Trunk specifies whether trunking is enabled at the port level. If not
324329
// provided the value is inherited from the machine, or false for a
325330
// bastion host.
326331
// +optional
327332
Trunk *bool `json:"trunk,omitempty"`
328333

329-
ResolvedPortSpecFields `json:",inline"`
334+
// Subports is a list of port specifications that will be created as
335+
// subports of the trunk.
336+
// +optional
337+
// +listType=atomic
338+
Subports []SubportOpts `json:"subports,omitempty"`
339+
340+
CommonPortOpts `json:",inline"`
341+
}
342+
343+
// SubportOpts defines a trunk subport.
344+
type SubportOpts struct {
345+
// SegmentationID is the segmentation ID of the subport. E.g. VLAN ID.
346+
// +required
347+
// +kubebuilder:validation:Minimum:=1
348+
// +kubebuilder:validation:Maximum:=4094
349+
SegmentationID int `json:"segmentationID"`
350+
351+
// SegmentationType is the segmentation type of the subport. E.g. "vlan".
352+
// +required
353+
// +kubebuilder:validation:Enum=vlan;flat
354+
SegmentationType string `json:"segmentationType"`
355+
356+
// Port contains parameters of the port associated with this subport
357+
CommonPortOpts `json:",inline"`
330358
}
331359

332360
// ResolvePortSpecFields is a convenience struct containing all fields of a
@@ -393,7 +421,7 @@ type ResolvedPortSpecFields struct {
393421
}
394422

395423
// ResolvedPortSpec is a PortOpts with all contained references fully resolved.
396-
type ResolvedPortSpec struct {
424+
type CommonResolvedPortSpec struct {
397425
// Name is the name of the port.
398426
Name string `json:"name"`
399427

@@ -408,10 +436,6 @@ type ResolvedPortSpec struct {
408436
// +optional
409437
Tags []string `json:"tags,omitempty"`
410438

411-
// Trunk specifies whether trunking is enabled at the port level.
412-
// +optional
413-
Trunk optional.Bool `json:"trunk,omitempty"`
414-
415439
// FixedIPs is a list of pairs of subnet and/or IP address to assign to the port. If specified, these must be subnets of the port's network.
416440
// +optional
417441
// +listType=atomic
@@ -425,10 +449,47 @@ type ResolvedPortSpec struct {
425449
ResolvedPortSpecFields `json:",inline"`
426450
}
427451

452+
type ResolvedPortSpec struct {
453+
// Trunk specifies whether trunking is enabled at the port level.
454+
// +optional
455+
Trunk optional.Bool `json:"trunk,omitempty"`
456+
457+
// Subports is a list of resolved port specifications that will be created as
458+
// subports of the trunk.
459+
// +optional
460+
// +listType=atomic
461+
Subports []ResolvedSubportSpec `json:"subports,omitempty"`
462+
463+
CommonResolvedPortSpec `json:",inline"`
464+
}
465+
466+
// ResolvedSubportSpec is a SubportOpts with all contained references fully resolved.
467+
type ResolvedSubportSpec struct {
468+
// SegmentationID is the segmentation ID of the subport. E.g. VLAN ID.
469+
SegmentationID int `json:"segmentationID"`
470+
471+
// SegmentationType is the segmentation type of the subport. E.g. "vlan".
472+
SegmentationType string `json:"segmentationType"`
473+
474+
// Port is a PortOpts with all contained references fully resolved. This is
475+
// essentially port which is used as subport in trunk
476+
CommonResolvedPortSpec `json:",inline"`
477+
}
478+
428479
type PortStatus struct {
429480
// ID is the unique identifier of the port.
430481
// +required
431482
ID string `json:"id"`
483+
484+
// Subports is the list of port IDs which intended to be trunk sub-ports
485+
// +optional
486+
Subports []SubPortStatus `json:"subports,omitempty"`
487+
}
488+
489+
type SubPortStatus struct {
490+
// ID is the unique identifier of the trunk sub-port.
491+
// +required
492+
ID string `json:"id"`
432493
}
433494

434495
type BindingProfile struct {

0 commit comments

Comments
 (0)