Skip to content

Commit 11ad9a1

Browse files
committed
aws/eni: Fix max results cutoff in GetDetachedNetworkInterfaces
`GetDetachedNetworkInterfaces` has a `maxResults` parameter which is set from [`GarbageCollectionParams.MaxPerInterval`](https://github.com/cilium/cilium/blob/6d1aa98670fe046fe3ac5a2b4167cfece416603e/pkg/aws/eni/eni_gc.go#L29-L31). Which in turn is set from the [`ENIGarbageCollectionMaxPerInterval`](https://github.com/cilium/cilium/blob/6d1aa98670fe046fe3ac5a2b4167cfece416603e/pkg/defaults/defaults.go#L391-L393) const to 25. The goal of this parameter is to cap the length of the returned `result`. But with the way it is currently used, `GetDetachedNetworkInterfaces` can actually return a `result` of length up to 49. This is because for each page, we append all ENIs from `output.NetworkInterfaces` to `result` and only after that check for the length of `result`. so if at the beginning of a page iteration `result` is a slice of length 24 and the new page has 25 ENIs, then they will all be appended to `result` before the length check will `break` out of the paginator loop as `result` will be of length 24+25=49. Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
1 parent c1bceb7 commit 11ad9a1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

pkg/aws/ec2/ec2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ func (c *Client) GetDetachedNetworkInterfaces(ctx context.Context, tags ipamType
230230
return nil, err
231231
}
232232
for _, eni := range output.NetworkInterfaces {
233+
if len(result) >= int(maxResults) {
234+
return result, nil
235+
}
233236
result = append(result, aws.ToString(eni.NetworkInterfaceId))
234237
}
235-
if len(result) >= int(maxResults) {
236-
break
237-
}
238238
}
239239
return result, nil
240240
}

0 commit comments

Comments
 (0)