Skip to content

Commit

Permalink
pkg/endpoint: returned NamedPorts model consistently
Browse files Browse the repository at this point in the history
We need to return the NamedPorts consistently across calls of
getNamedPortsModel function. This avoids unnecessary CEP updates to
kube-apiserver.

Fixes: 3a72ffc ("api: Add named ports")
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed May 12, 2020
1 parent d613dea commit 74cc967
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/endpoint/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,17 @@ func (e *Endpoint) GetHealthModel() *models.EndpointHealth {
// Must be called with e.Mutex locked.
func (e *Endpoint) getNamedPortsModel() (np models.NamedPorts) {
k8sPorts := e.k8sPorts
// keep named ports ordered to avoid the unnecessary updates to
// kube-apiserver
names := make([]string, 0, len(k8sPorts))
for name := range k8sPorts {
names = append(names, name)
}
sort.Strings(names)

np = make(models.NamedPorts, 0, len(k8sPorts))
for name, value := range k8sPorts {
for _, name := range names {
value := k8sPorts[name]
np = append(np, &models.Port{
Name: name,
Port: value.Port,
Expand Down

0 comments on commit 74cc967

Please sign in to comment.