Skip to content

Commit d532986

Browse files
Fix wrong pointer in range loop (kubernetes#1198) (kubernetes#1209)
range copies the value as a local variable in the loop. Getting the pointer from it makes all the elements in the map point to the last value that the range variable copied. Change to get value with index from array directly. Co-authored-by: Phillip <[email protected]>
1 parent cbee1e1 commit d532986

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,9 @@ func (lbaas *LbaasV2) ensureOctaviaPool(lbID string, listener *listeners.Listene
11001100
func (lbaas *LbaasV2) ensureOctaviaListener(lbID string, oldListeners []listeners.Listener, service *corev1.Service, port corev1.ServicePort, svcConf *serviceConfig) (*listeners.Listener, error) {
11011101
// Get all listeners by "port&protocol".
11021102
lbListeners := make(map[listenerKey]*listeners.Listener)
1103-
for _, l := range oldListeners {
1103+
for i, l := range oldListeners {
11041104
key := listenerKey{Protocol: listeners.Protocol(l.Protocol), Port: l.ProtocolPort}
1105-
lbListeners[key] = &l
1105+
lbListeners[key] = &oldListeners[i]
11061106
}
11071107

11081108
proto := toListenersProtocol(port.Protocol)

0 commit comments

Comments
 (0)