Skip to content

Commit b349c0c

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 c6efdea commit b349c0c

29 files changed

+1839
-2174
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

2224
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
@@ -217,6 +219,38 @@ func Convert_v1alpha7_PortOpts_To_v1beta1_PortOpts(in *PortOpts, out *infrav1.Po
217219
return err
218220
}
219221

222+
// Copy members of ResolvedPortSpecFields
223+
var allowedAddressPairs []infrav1.AddressPair
224+
if len(in.AllowedAddressPairs) > 0 {
225+
allowedAddressPairs = make([]infrav1.AddressPair, len(in.AllowedAddressPairs))
226+
for i := range in.AllowedAddressPairs {
227+
aap := &in.AllowedAddressPairs[i]
228+
allowedAddressPairs[i] = infrav1.AddressPair{
229+
MACAddress: &aap.MACAddress,
230+
IPAddress: aap.IPAddress,
231+
}
232+
}
233+
}
234+
var valueSpecs []infrav1.ValueSpec
235+
if len(in.ValueSpecs) > 0 {
236+
valueSpecs = make([]infrav1.ValueSpec, len(in.ValueSpecs))
237+
for i, vs := range in.ValueSpecs {
238+
valueSpecs[i] = infrav1.ValueSpec(vs)
239+
}
240+
}
241+
out.AdminStateUp = in.AdminStateUp
242+
out.AllowedAddressPairs = allowedAddressPairs
243+
out.DisablePortSecurity = in.DisablePortSecurity
244+
out.PropagateUplinkStatus = in.PropagateUplinkStatus
245+
out.ValueSpecs = valueSpecs
246+
if err := errors.Join(
247+
optional.Convert_string_To_optional_String(&in.MACAddress, &out.MACAddress, s),
248+
optional.Convert_string_To_optional_String(&in.HostID, &out.HostID, s),
249+
optional.Convert_string_To_optional_String(&in.VNICType, &out.VNICType, s),
250+
); err != nil {
251+
return err
252+
}
253+
220254
if len(in.SecurityGroupFilters) > 0 {
221255
out.SecurityGroups = make([]infrav1.SecurityGroupFilter, len(in.SecurityGroupFilters))
222256
for i := range in.SecurityGroupFilters {
@@ -241,6 +275,39 @@ func Convert_v1beta1_PortOpts_To_v1alpha7_PortOpts(in *infrav1.PortOpts, out *Po
241275
return err
242276
}
243277

278+
// Copy members of ResolvedPortSpecFields
279+
var allowedAddressPairs []AddressPair
280+
if len(in.AllowedAddressPairs) > 0 {
281+
allowedAddressPairs = make([]AddressPair, len(in.AllowedAddressPairs))
282+
for i := range in.AllowedAddressPairs {
283+
inAAP := &in.AllowedAddressPairs[i]
284+
outAAP := &allowedAddressPairs[i]
285+
if err := optional.Convert_optional_String_To_string(&inAAP.MACAddress, &outAAP.MACAddress, s); err != nil {
286+
return err
287+
}
288+
outAAP.IPAddress = inAAP.IPAddress
289+
}
290+
}
291+
var valueSpecs []ValueSpec
292+
if len(in.ValueSpecs) > 0 {
293+
valueSpecs = make([]ValueSpec, len(in.ValueSpecs))
294+
for i, vs := range in.ValueSpecs {
295+
valueSpecs[i] = ValueSpec(vs)
296+
}
297+
}
298+
out.AdminStateUp = in.AdminStateUp
299+
out.AllowedAddressPairs = allowedAddressPairs
300+
out.DisablePortSecurity = in.DisablePortSecurity
301+
out.PropagateUplinkStatus = in.PropagateUplinkStatus
302+
out.ValueSpecs = valueSpecs
303+
if err := errors.Join(
304+
optional.Convert_optional_String_To_string(&in.MACAddress, &out.MACAddress, s),
305+
optional.Convert_optional_String_To_string(&in.HostID, &out.HostID, s),
306+
optional.Convert_optional_String_To_string(&in.VNICType, &out.VNICType, s),
307+
); err != nil {
308+
return err
309+
}
310+
244311
if len(in.SecurityGroups) > 0 {
245312
out.SecurityGroupFilters = make([]SecurityGroupFilter, len(in.SecurityGroups))
246313
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)