Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions pkg/cloud/openstack/clients/machineservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const (
TimeoutPortDelete = 3 * time.Minute
RetryIntervalPortDelete = 5 * time.Second

// Maximum port name length supported by Neutron
PortNameMaxSize = 255

// MachineRegionLabelName as annotation name for a machine region
MachineRegionLabelName = "machine.openshift.io/region"

Expand Down Expand Up @@ -326,15 +329,25 @@ func getSubnetsByFilter(is *InstanceService, opts *subnets.ListOpts) ([]subnets.
}

func getOrCreatePort(is *InstanceService, name string, portOpts openstackconfigv1.PortOpts) (*ports.Port, error) {
var portName string
if portOpts.NameSuffix != "" {
portName = name + "-" + portOpts.NameSuffix
} else {
portName = name
}
if len(portName) > PortNameMaxSize {
portName = portName[len(portName)-PortNameMaxSize:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for shortening the the port name in case it's too long takes the last 255 chars, I would have personally kept the first chars since the name is supposed to be for humans. Not that it matters, I expect we never end up in a situation where the port name is that long anyway...

}
existingPorts, err := listPorts(is, ports.ListOpts{
Name: name,
Name: portName,
NetworkID: portOpts.NetworkID,
})
if err != nil {
return nil, err
}
if len(existingPorts) == 0 {
createOpts := ports.CreateOpts{
Name: name,
Name: portName,
NetworkID: portOpts.NetworkID,
Description: portOpts.Description,
AdminStateUp: portOpts.AdminStateUp,
Expand Down Expand Up @@ -390,7 +403,7 @@ func getOrCreatePort(is *InstanceService, name string, portOpts openstackconfigv
return &existingPorts[0], nil
}

return nil, fmt.Errorf("multiple ports found with name \"%s\"", name)
return nil, fmt.Errorf("multiple ports found with name \"%s\"", portName)
}

func listPorts(is *InstanceService, opts ports.ListOpts) ([]ports.Port, error) {
Expand Down Expand Up @@ -498,6 +511,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
if net.Subnets == nil {
nets = append(nets, openstackconfigv1.PortOpts{
NetworkID: netID,
NameSuffix: net.UUID,
Tags: net.PortTags,
VNICType: net.VNICType,
PortSecurity: net.PortSecurity,
Expand All @@ -522,6 +536,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
for _, snet := range snetResults {
nets = append(nets, openstackconfigv1.PortOpts{
NetworkID: snet.NetworkID,
NameSuffix: snet.ID,
FixedIPs: []openstackconfigv1.FixedIPs{{SubnetID: snet.ID}},
Tags: append(net.PortTags, snetParam.PortTags...),
VNICType: net.VNICType,
Expand Down Expand Up @@ -616,7 +631,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
}

for _, portCreateOpts := range config.Ports {
port, err := getOrCreatePort(is, name+"-"+portCreateOpts.NameSuffix, portCreateOpts)
port, err := getOrCreatePort(is, name, portCreateOpts)
if err != nil {
return nil, err
}
Expand Down