Skip to content

Commit 86d4300

Browse files
committed
getOrCreatePort: add support to configure port Profile
Configuring port profiles can be useful to enable an application running on the specified host to pass and receive VIF port-specific information to the plugin. One of the use-cases here is when configuring ports in OVS Hardware offload, where we need to use the profile: {"capabilities": ["switchdev"]} Thanks to this patch, we'll now able to do it when creating the machines and their ports. thinx cluster-api-provider- OSASINFRA-2434
1 parent 065b0b4 commit 86d4300

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/apis/openstackproviderconfig/v1alpha1/types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ type NetworkParam struct {
135135
// NoAllowedAddressPairs disables creation of allowed address pairs for the network ports
136136
NoAllowedAddressPairs bool `json:"noAllowedAddressPairs,omitempty"`
137137
// PortTags allows users to specify a list of tags to add to ports created in a given network
138-
PortTags []string `json:"portTags,omitempty"`
139-
VNICType string `json:"vnicType,omitempty"`
138+
PortTags []string `json:"portTags,omitempty"`
139+
VNICType string `json:"vnicType,omitempty"`
140+
Profile map[string]string `json:"profile,omitempty"`
140141
// PortSecurity optionally enables or disables security on ports managed by OpenStack
141142
PortSecurity *bool `json:"portSecurity,omitempty"`
142143
}
@@ -218,6 +219,11 @@ type PortOpts struct {
218219
// neutron port.
219220
VNICType string `json:"vnicType,omitempty"`
220221

222+
// A dictionary that enables the application running on the specified
223+
// host to pass and receive virtual network interface (VIF) port-specific
224+
// information to the plug-in.
225+
Profile map[string]string `json:"profile,omitempty"`
226+
221227
// enable or disable security on a given port
222228
// incompatible with securityGroups and allowedAddressPairs
223229
PortSecurity *bool `json:"portSecurity,omitempty"`

pkg/cloud/openstack/clients/machineservice.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func getOrCreatePort(is *InstanceService, name string, portOpts openstackconfigv
375375
CreateOptsBuilder: createOpts,
376376
HostID: portOpts.HostID,
377377
VNICType: portOpts.VNICType,
378-
Profile: nil,
378+
Profile: getPortProfile(portOpts.Profile),
379379
}).Extract()
380380
if err != nil {
381381
return nil, err
@@ -405,6 +405,21 @@ func getOrCreatePort(is *InstanceService, name string, portOpts openstackconfigv
405405
return nil, fmt.Errorf("multiple ports found with name \"%s\"", portName)
406406
}
407407

408+
func getPortProfile(p map[string]string) map[string]interface{} {
409+
portProfile := make(map[string]interface{})
410+
for k, v := range p {
411+
portProfile[k] = v
412+
}
413+
// We need return nil if there is no profiles
414+
// to have backward compatible defaults.
415+
// To set profiles, your tenant needs this permission:
416+
// rule:create_port and rule:create_port:binding:profile
417+
if len(portProfile) == 0 {
418+
return nil
419+
}
420+
return portProfile
421+
}
422+
408423
func listPorts(is *InstanceService, opts ports.ListOpts) ([]ports.Port, error) {
409424
allPages, err := ports.List(is.networkClient, opts).AllPages()
410425
if err != nil {
@@ -572,6 +587,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
572587
NameSuffix: net.UUID,
573588
Tags: net.PortTags,
574589
VNICType: net.VNICType,
590+
Profile: net.Profile,
575591
PortSecurity: net.PortSecurity,
576592
})
577593
}
@@ -598,6 +614,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
598614
FixedIPs: []openstackconfigv1.FixedIPs{{SubnetID: snet.ID}},
599615
Tags: append(net.PortTags, snetParam.PortTags...),
600616
VNICType: net.VNICType,
617+
Profile: net.Profile,
601618
PortSecurity: portSecurity,
602619
})
603620
}

0 commit comments

Comments
 (0)