Skip to content

Commit

Permalink
GetPorts: fix referencing of ports
Browse files Browse the repository at this point in the history
This commit fixes the collection of ports by storing the actual item
instead of the address of the loop variable in the list. An example,
because I find pointers confusing:

Let's say our actual ports are [1, 2, 3]. Previously, GetPorts returned
[3, 3, 3], and now we receive (as expected) [1, 2, 3].

I stumbled over this problem while applying force to lbaas by having a
script create and delete services at random intervals as well as
manually deleting the lbaas and the workload pod. This should resolve
the resource leaks observed in cloudandheat#28. If we're lucky this might also help
with lbaas eating FIPs.
  • Loading branch information
Yannic Ahrens committed Jun 8, 2022
1 parent 8179501 commit 158c8cd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/openstack/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UncachedClient struct {
}

type PortClient interface {
GetPorts() ([]*portsv2.Port, error)
GetPorts() ([]portsv2.Port, error)
GetPortByID(ID string) (*portsv2.Port, *floatingipsv2.FloatingIP, error)
}

Expand All @@ -47,7 +47,7 @@ func NewPortClient(networkingclient *gophercloud.ServiceClient, tag string, useF
}
}

func (pc *UncachedClient) GetPorts() (ports []*portsv2.Port, err error) {
func (pc *UncachedClient) GetPorts() (ports []portsv2.Port, err error) {
err = portsv2.List(
pc.client,
portsv2.ListOpts{Tags: pc.tag},
Expand All @@ -57,7 +57,7 @@ func (pc *UncachedClient) GetPorts() (ports []*portsv2.Port, err error) {
return false, err
}
for _, found_port := range fetched_ports {
ports = append(ports, &found_port)
ports = append(ports, found_port)
}
return true, nil
})
Expand Down

0 comments on commit 158c8cd

Please sign in to comment.