Skip to content

Port can be created with incorrect name #1940

Closed
@mdbooth

Description

@mdbooth

/kind bug

This is from code inspection. In CreatePorts we generate the port's name by index:

portName := GetPortName(instanceName, portOpts, i)
// Events are recorded in CreatePort
port, err := s.CreatePort(eventObject, clusterName, portName, portOpts, instanceSecurityGroups, iTags)

However, this index is not absolute. It is relative to the number of ports which were previously created:

desiredPorts := openStackMachine.Status.ReferencedResources.Ports
portsToCreate := networking.MissingPorts(openStackMachine.Status.DependentResources.Ports, desiredPorts)
// Sanity check that the number of desired ports is equal to the addition of ports to create and ports that already exist.
if len(desiredPorts) != len(portsToCreate)+len(openStackMachine.Status.DependentResources.Ports) {
return fmt.Errorf("length of desired ports (%d) is not equal to the length of ports to create (%d) + the length of ports that already exist (%d)", len(desiredPorts), len(portsToCreate), len(openStackMachine.Status.DependentResources.Ports))
}
if len(portsToCreate) > 0 {
instanceTags := getInstanceTags(openStackMachine, openStackCluster)
managedSecurityGroups := getManagedSecurityGroups(openStackCluster, machine, openStackMachine)
machinePortsStatus, err = networkingService.CreatePorts(openStackMachine, clusterName, portsToCreate, managedSecurityGroups, instanceTags, openStackMachine.Name)

This means that if we declare 2 ports, create 1, fail, then create the other one on the next reconcile, they will both get the index 1.

This is not just untidy, it is also something we rely on in port adoption:

portName := GetPortName(openStackMachine.Name, portOpts, i)
ports, err := s.client.ListPort(ports.ListOpts{
Name: portName,
NetworkID: port.Network.ID,
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions