kubernetes-sigs / cluster-api-provider-openstack

Cluster API implementation for OpenStack
https://cluster-api-openstack.sigs.k8s.io/
Apache License 2.0
279 stars 252 forks source link

Port can be created with incorrect name #1940

Closed mdbooth closed 4 months ago

mdbooth commented 4 months ago

/kind bug

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

https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/654d714fd0b0fbdaec2a16489a0d4eb4a5d4f06f/pkg/cloud/services/networking/port.go#L335-L337

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

https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/654d714fd0b0fbdaec2a16489a0d4eb4a5d4f06f/controllers/openstackmachine_controller.go#L501-L512

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:

https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/654d714fd0b0fbdaec2a16489a0d4eb4a5d4f06f/pkg/cloud/services/networking/port.go#L553-L557