Skip to content

Commit 031f9c2

Browse files
committed
Store []ResolvedPortSpec in ReferencedMachineResources
The purpose of this change is fix an issue where we are storing unresolved references in ReferencedMachineResources. Specifically we are storing a PortOpts, which is a user-intent struct. PortOpts can contain unresolved references to both subnets and security groups, as well fields requiring additional processing which reference external objects: the port name, description, and tags. We create a new type, ResolvedPortSpec, which can contain only fully resolved data. This can be seen in the new signature of CreatePorts(), which no longer requires any source of data other than the []ResolvedPortSpec from ReferencedMachineResources, and is now greatly simplified. Fully resolving the port name also allows a simplification in port adoption. All of the complexity now moves to ConstructPorts(), which is updated to return []ResolvedPortSpec instead of []PortOpts. ConstructPorts() is updated to resolve security groups, port name, description, and all subnets referenced in FixedIPs.
1 parent 1b07f9f commit 031f9c2

28 files changed

+1844
-2172
lines changed

api/v1alpha5/zz_generated.conversion.go

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

api/v1alpha6/conversion_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ func TestPortOptsConvertTo(t *testing.T) {
570570
SecurityGroups: uuids,
571571
}},
572572
hubPortOpts: []infrav1.PortOpts{{
573-
Profile: &convertedPortProfile,
573+
ResolvedPortSpecFields: infrav1.ResolvedPortSpecFields{
574+
Profile: &convertedPortProfile,
575+
},
574576
SecurityGroups: securityGroupsUuids,
575577
}},
576578
},
@@ -582,7 +584,9 @@ func TestPortOptsConvertTo(t *testing.T) {
582584
SecurityGroupFilters: securityGroupFilter,
583585
}},
584586
hubPortOpts: []infrav1.PortOpts{{
585-
Profile: &convertedPortProfile,
587+
ResolvedPortSpecFields: infrav1.ResolvedPortSpecFields{
588+
Profile: &convertedPortProfile,
589+
},
586590
SecurityGroups: securityGroupFilterMerged,
587591
}},
588592
},

api/v1alpha6/zz_generated.conversion.go

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

api/v1alpha7/types_conversion.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1alpha7
1818

1919
import (
20+
"errors"
21+
2022
apiconversion "k8s.io/apimachinery/pkg/conversion"
2123
"k8s.io/utils/pointer"
2224

@@ -253,6 +255,38 @@ func Convert_v1alpha7_PortOpts_To_v1beta1_PortOpts(in *PortOpts, out *infrav1.Po
253255
return err
254256
}
255257

258+
// Copy members of ResolvedPortSpecFields
259+
var allowedAddressPairs []infrav1.AddressPair
260+
if len(in.AllowedAddressPairs) > 0 {
261+
allowedAddressPairs = make([]infrav1.AddressPair, len(in.AllowedAddressPairs))
262+
for i := range in.AllowedAddressPairs {
263+
aap := &in.AllowedAddressPairs[i]
264+
allowedAddressPairs[i] = infrav1.AddressPair{
265+
MACAddress: &aap.MACAddress,
266+
IPAddress: aap.IPAddress,
267+
}
268+
}
269+
}
270+
var valueSpecs []infrav1.ValueSpec
271+
if len(in.ValueSpecs) > 0 {
272+
valueSpecs = make([]infrav1.ValueSpec, len(in.ValueSpecs))
273+
for i, vs := range in.ValueSpecs {
274+
valueSpecs[i] = infrav1.ValueSpec(vs)
275+
}
276+
}
277+
out.AdminStateUp = in.AdminStateUp
278+
out.AllowedAddressPairs = allowedAddressPairs
279+
out.DisablePortSecurity = in.DisablePortSecurity
280+
out.PropagateUplinkStatus = in.PropagateUplinkStatus
281+
out.ValueSpecs = valueSpecs
282+
if err := errors.Join(
283+
optional.Convert_string_To_optional_String(&in.MACAddress, &out.MACAddress, s),
284+
optional.Convert_string_To_optional_String(&in.HostID, &out.HostID, s),
285+
optional.Convert_string_To_optional_String(&in.VNICType, &out.VNICType, s),
286+
); err != nil {
287+
return err
288+
}
289+
256290
if len(in.SecurityGroupFilters) > 0 {
257291
out.SecurityGroups = make([]infrav1.SecurityGroupFilter, len(in.SecurityGroupFilters))
258292
for i := range in.SecurityGroupFilters {
@@ -277,6 +311,39 @@ func Convert_v1beta1_PortOpts_To_v1alpha7_PortOpts(in *infrav1.PortOpts, out *Po
277311
return err
278312
}
279313

314+
// Copy members of ResolvedPortSpecFields
315+
var allowedAddressPairs []AddressPair
316+
if len(in.AllowedAddressPairs) > 0 {
317+
allowedAddressPairs = make([]AddressPair, len(in.AllowedAddressPairs))
318+
for i := range in.AllowedAddressPairs {
319+
inAAP := &in.AllowedAddressPairs[i]
320+
outAAP := &allowedAddressPairs[i]
321+
if err := optional.Convert_optional_String_To_string(&inAAP.MACAddress, &outAAP.MACAddress, s); err != nil {
322+
return err
323+
}
324+
outAAP.IPAddress = inAAP.IPAddress
325+
}
326+
}
327+
var valueSpecs []ValueSpec
328+
if len(in.ValueSpecs) > 0 {
329+
valueSpecs = make([]ValueSpec, len(in.ValueSpecs))
330+
for i, vs := range in.ValueSpecs {
331+
valueSpecs[i] = ValueSpec(vs)
332+
}
333+
}
334+
out.AdminStateUp = in.AdminStateUp
335+
out.AllowedAddressPairs = allowedAddressPairs
336+
out.DisablePortSecurity = in.DisablePortSecurity
337+
out.PropagateUplinkStatus = in.PropagateUplinkStatus
338+
out.ValueSpecs = valueSpecs
339+
if err := errors.Join(
340+
optional.Convert_optional_String_To_string(&in.MACAddress, &out.MACAddress, s),
341+
optional.Convert_optional_String_To_string(&in.HostID, &out.HostID, s),
342+
optional.Convert_optional_String_To_string(&in.VNICType, &out.VNICType, s),
343+
); err != nil {
344+
return err
345+
}
346+
280347
if len(in.SecurityGroups) > 0 {
281348
out.SecurityGroupFilters = make([]SecurityGroupFilter, len(in.SecurityGroups))
282349
for i := range in.SecurityGroups {

api/v1alpha7/zz_generated.conversion.go

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

0 commit comments

Comments
 (0)