Skip to content

Commit 16415b4

Browse files
authored
Merge pull request #1518 from shiftstack/networks
⚠️ Remove Networks
2 parents 7f2aa81 + 8b2ca6b commit 16415b4

17 files changed

+408
-852
lines changed

api/v1alpha5/zz_generated.conversion.go

Lines changed: 1 addition & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion.go

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ func restorev1alpha6MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMa
8686
// Subnet is removed from v1alpha7 with no replacement, so can't be
8787
// losslessly converted. Restore the previously stored value on down-conversion.
8888
dst.Subnet = previous.Subnet
89+
90+
// Strictly speaking this is lossy because we lose changes in
91+
// down-conversion which were made to the up-converted object. However
92+
// it isn't worth implementing this as the fields are immutable.
93+
dst.Networks = previous.Networks
94+
dst.Ports = previous.Ports
8995
}
9096

9197
func restorev1alpha7MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
@@ -288,7 +294,80 @@ func (r *OpenStackMachineTemplateList) ConvertFrom(srcRaw ctrlconversion.Hub) er
288294
}
289295

290296
func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s conversion.Scope) error {
291-
return autoConvert_v1alpha6_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s)
297+
err := autoConvert_v1alpha6_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s)
298+
if err != nil {
299+
return err
300+
}
301+
302+
if len(in.Networks) > 0 {
303+
ports := convertNetworksToPorts(in.Networks)
304+
// Networks were previously created first, so need to come before ports
305+
out.Ports = append(ports, out.Ports...)
306+
}
307+
return nil
308+
}
309+
310+
func convertNetworksToPorts(networks []NetworkParam) []infrav1.PortOpts {
311+
var ports []infrav1.PortOpts
312+
313+
for _, network := range networks {
314+
// This will remain null if the network is not specified in NetworkParam
315+
var networkFilter *infrav1.NetworkFilter
316+
317+
// In v1alpha6, if network.Filter resolved to multiple networks
318+
// then we would add multiple ports. It is not possible to
319+
// support this behaviour during k8s API conversion as it
320+
// requires an OpenStack API call. A network filter returning
321+
// multiple networks now becomes an error when we attempt to
322+
// create the port.
323+
switch {
324+
case network.UUID != "":
325+
networkFilter = &infrav1.NetworkFilter{
326+
ID: network.UUID,
327+
}
328+
case network.Filter != (NetworkFilter{}):
329+
networkFilter = (*infrav1.NetworkFilter)(&network.Filter)
330+
}
331+
332+
// Note that network.FixedIP was unused in v1alpha6 so we also ignore it here.
333+
334+
// In v1alpha6, specifying multiple subnets created multiple
335+
// ports. We maintain this behaviour in conversion by adding
336+
// multiple portOpts in this case.
337+
//
338+
// Also, similar to network.Filter above, if a subnet filter
339+
// resolved to multiple subnets then we would add a port for
340+
// each subnet. Again, it is not possible to support this
341+
// behaviour during k8s API conversion as it requires an
342+
// OpenStack API call. A subnet filter returning multiple
343+
// subnets now becomes an error when we attempt to create the
344+
// port.
345+
if len(network.Subnets) == 0 {
346+
// If the network has no explicit subnets then we create a single port with no subnets.
347+
ports = append(ports, infrav1.PortOpts{Network: networkFilter})
348+
} else {
349+
// If the network has explicit subnets then we create a separate port for each subnet.
350+
for _, subnet := range network.Subnets {
351+
if subnet.UUID != "" {
352+
ports = append(ports, infrav1.PortOpts{
353+
Network: networkFilter,
354+
FixedIPs: []infrav1.FixedIP{
355+
{Subnet: &infrav1.SubnetFilter{ID: subnet.UUID}},
356+
},
357+
})
358+
} else {
359+
ports = append(ports, infrav1.PortOpts{
360+
Network: networkFilter,
361+
FixedIPs: []infrav1.FixedIP{
362+
{Subnet: (*infrav1.SubnetFilter)(&subnet.Filter)},
363+
},
364+
})
365+
}
366+
}
367+
}
368+
}
369+
370+
return ports
292371
}
293372

294373
func Convert_v1alpha7_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *infrav1.OpenStackClusterSpec, out *OpenStackClusterSpec, s conversion.Scope) error {

0 commit comments

Comments
 (0)