Skip to content

Commit 23c9a80

Browse files
committed
Add managedNetworks on OpenStackCluster
Add managedNetworks on OpenStackCluster to group network related fields for when CAPO creates the cluster network.
1 parent 0f0b378 commit 23c9a80

File tree

16 files changed

+517
-276
lines changed

16 files changed

+517
-276
lines changed

api/v1beta1/conversion.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,42 @@ func Convert_v1beta2_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(
364364
return nil
365365
}
366366

367+
func Convert_v1beta1_OpenStackClusterSpec_To_v1beta2_OpenStackClusterSpec(
368+
in *OpenStackClusterSpec,
369+
out *infrav1.OpenStackClusterSpec,
370+
s apiconversion.Scope,
371+
) error {
372+
if err := autoConvert_v1beta1_OpenStackClusterSpec_To_v1beta2_OpenStackClusterSpec(in, out, s); err != nil {
373+
return err
374+
}
375+
376+
if in.NetworkMTU != nil || in.DisablePortSecurity != nil {
377+
out.ManagedNetwork = &infrav1.ManagedNetwork{
378+
MTU: in.NetworkMTU,
379+
DisablePortSecurity: in.DisablePortSecurity,
380+
}
381+
}
382+
383+
return nil
384+
}
385+
386+
func Convert_v1beta2_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(
387+
in *infrav1.OpenStackClusterSpec,
388+
out *OpenStackClusterSpec,
389+
s apiconversion.Scope,
390+
) error {
391+
if err := autoConvert_v1beta2_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s); err != nil {
392+
return err
393+
}
394+
395+
if in.ManagedNetwork != nil {
396+
out.NetworkMTU = in.ManagedNetwork.MTU
397+
out.DisablePortSecurity = in.ManagedNetwork.DisablePortSecurity
398+
}
399+
400+
return nil
401+
}
402+
367403
// LegacyCalicoSecurityGroupRules returns a list of security group rules for calico
368404
// that need to be applied to the control plane and worker security groups when
369405
// managed security groups are enabled and upgrading to v1beta1.

api/v1beta1/conversion_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func TestOpenStackClusterConversion(t *testing.T) {
9898
g.Expect(dst.Namespace).To(Equal("default"))
9999
g.Expect(dst.Spec.IdentityRef.Name).To(Equal("cloud-config"))
100100
g.Expect(dst.Spec.ManagedSubnets).To(HaveLen(1))
101+
g.Expect(dst.Spec.ManagedNetwork).To(BeNil())
101102

102103
// Verify flavor mapping (name -> FlavorParam.Filter.Name)
103104
g.Expect(dst.Spec.Bastion.Spec.Flavor.ID).To(BeNil())
@@ -136,6 +137,8 @@ func TestOpenStackClusterConversion(t *testing.T) {
136137
g.Expect(restored.Spec.IdentityRef).To(Equal(src.Spec.IdentityRef))
137138
g.Expect(restored.Status.Ready).To(BeTrue())
138139
g.Expect(restored.Status.Conditions).To(HaveLen(2))
140+
g.Expect(restored.Spec.NetworkMTU).To(BeNil())
141+
g.Expect(restored.Spec.DisablePortSecurity).To(BeNil())
139142

140143
// Severity is lost during conversion, so it won't match exactly
141144
g.Expect(restored.Status.Conditions[0].Type).To(Equal(src.Status.Conditions[0].Type))
@@ -967,3 +970,64 @@ func TestIsReadyHelper(t *testing.T) {
967970
g.Expect(infrav1.IsReady(nil)).To(BeFalse())
968971
g.Expect(infrav1.IsReady([]metav1.Condition{})).To(BeFalse())
969972
}
973+
974+
func TestOpenStackCluster_RoundTrip_ManagedNetwork(t *testing.T) {
975+
mtu := optional.Int(ptr.To(1500))
976+
disablePS := optional.Bool(ptr.To(true))
977+
978+
tests := []struct {
979+
name string
980+
in OpenStackCluster
981+
}{
982+
{
983+
name: "both fields set",
984+
in: OpenStackCluster{
985+
Spec: OpenStackClusterSpec{
986+
NetworkMTU: mtu,
987+
DisablePortSecurity: disablePS,
988+
},
989+
},
990+
},
991+
{
992+
name: "only MTU set",
993+
in: OpenStackCluster{
994+
Spec: OpenStackClusterSpec{NetworkMTU: mtu},
995+
},
996+
},
997+
{
998+
name: "only DisablePortSecurity set",
999+
in: OpenStackCluster{
1000+
Spec: OpenStackClusterSpec{DisablePortSecurity: disablePS},
1001+
},
1002+
},
1003+
{
1004+
name: "neither set — ManagedNetwork stays nil",
1005+
in: OpenStackCluster{},
1006+
},
1007+
}
1008+
1009+
for _, tt := range tests {
1010+
t.Run(tt.name, func(t *testing.T) {
1011+
g := NewWithT(t)
1012+
1013+
hub := &infrav1.OpenStackCluster{}
1014+
g.Expect(tt.in.ConvertTo(hub)).To(Succeed())
1015+
1016+
// Verify intermediate v1beta2 state
1017+
if tt.in.Spec.NetworkMTU == nil && tt.in.Spec.DisablePortSecurity == nil {
1018+
g.Expect(hub.Spec.ManagedNetwork).To(BeNil())
1019+
} else {
1020+
g.Expect(hub.Spec.ManagedNetwork).NotTo(BeNil())
1021+
g.Expect(hub.Spec.ManagedNetwork.MTU).To(Equal(tt.in.Spec.NetworkMTU))
1022+
g.Expect(hub.Spec.ManagedNetwork.DisablePortSecurity).To(Equal(tt.in.Spec.DisablePortSecurity))
1023+
}
1024+
1025+
restored := &OpenStackCluster{}
1026+
g.Expect(restored.ConvertFrom(hub)).To(Succeed())
1027+
1028+
// Verify final v1beta1 state
1029+
g.Expect(restored.Spec.NetworkMTU).To(Equal(tt.in.Spec.NetworkMTU))
1030+
g.Expect(restored.Spec.DisablePortSecurity).To(Equal(tt.in.Spec.DisablePortSecurity))
1031+
})
1032+
}
1033+
}

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/openstackcluster_types.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ type OpenStackClusterSpec struct {
4141
// +optional
4242
ManagedSubnets []SubnetSpec `json:"managedSubnets,omitempty"`
4343

44-
// Router specifies an existing router to be used if ManagedSubnets are
45-
// specified. If specified, no new router will be created.
46-
// +optional
47-
Router *RouterParam `json:"router,omitempty"`
48-
49-
// Network specifies an existing network to use if no ManagedSubnets
50-
// are specified.
51-
// +optional
52-
Network *NetworkParam `json:"network,omitempty"`
53-
5444
// Subnets specifies existing subnets to use if not ManagedSubnets are
5545
// specified. All subnets must be in the network specified by Network.
5646
// There can be zero, one, or two subnets. If no subnets are specified,
@@ -61,12 +51,21 @@ type OpenStackClusterSpec struct {
6151
// +optional
6252
Subnets []SubnetParam `json:"subnets,omitempty"`
6353

64-
// NetworkMTU sets the maximum transmission unit (MTU) value to address fragmentation for the private network ID.
65-
// This value will be used only if the Cluster actuator creates the network.
66-
// If left empty, the network will have the default MTU defined in Openstack network service.
67-
// To use this field, the Openstack installation requires the net-mtu neutron API extension.
54+
// Router specifies an existing router to be used if ManagedSubnets are
55+
// specified. If specified, no new router will be created.
6856
// +optional
69-
NetworkMTU optional.Int `json:"networkMTU,omitempty"`
57+
Router *RouterParam `json:"router,omitempty"`
58+
59+
// ManagedNetwork specifies attributes of the network. The values are used only
60+
// if the Cluster actuator creates the network.
61+
// +kubebuilder:validation:XValidation:rule="self == null || self.mtu != null || self.disablePortSecurity != null",message="managedNetwork must not be empty if set"
62+
// +optional
63+
ManagedNetwork *ManagedNetwork `json:"managedNetwork,omitempty"`
64+
65+
// Network specifies an existing network to use if no ManagedSubnets
66+
// are specified.
67+
// +optional
68+
Network *NetworkParam `json:"network,omitempty"`
7069

7170
// ExternalRouterIPs is an array of externalIPs on the respective subnets.
7271
// This is necessary if the router needs a fixed ip in a specific subnet.
@@ -148,11 +147,6 @@ type OpenStackClusterSpec struct {
148147
// +optional
149148
ManagedSecurityGroups *ManagedSecurityGroups `json:"managedSecurityGroups,omitempty"`
150149

151-
// DisablePortSecurity disables the port security of the network created for the
152-
// Kubernetes cluster, which also disables SecurityGroups
153-
// +optional
154-
DisablePortSecurity optional.Bool `json:"disablePortSecurity,omitempty"`
155-
156150
// Tags to set on all resources in cluster which support tags
157151
// +listType=set
158152
// +optional
@@ -285,6 +279,21 @@ type OpenStackClusterList struct {
285279
Items []OpenStackCluster `json:"items"`
286280
}
287281

282+
// ManagedNetwork specifies attributes of the network.
283+
type ManagedNetwork struct {
284+
// MTU sets the maximum transmission unit (MTU) value to address fragmentation for the private network ID.
285+
// This value will be used only if the Cluster actuator creates the network.
286+
// If left empty, the network will have the default MTU defined in Openstack network service.
287+
// To use this field, the Openstack installation requires the net-mtu neutron API extension.
288+
// +optional
289+
MTU optional.Int `json:"mtu,omitempty"`
290+
291+
// DisablePortSecurity disables the port security of the network created for the
292+
// Kubernetes cluster, which also disables SecurityGroups
293+
// +optional
294+
DisablePortSecurity optional.Bool `json:"disablePortSecurity,omitempty"`
295+
}
296+
288297
// ManagedSecurityGroups defines the desired state of security groups and rules for the cluster.
289298
type ManagedSecurityGroups struct {
290299
// allNodesSecurityGroupRules defines the rules that should be applied to all nodes.

api/v1beta2/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)