Skip to content

Commit

Permalink
client, identity: remove unnecessary guards around delete()
Browse files Browse the repository at this point in the history
From https://golang.org/pkg/builtin/#delete

> If the map is nil or there is no such element, delete is a no-op.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Feb 11, 2020
1 parent c58d749 commit 838e3b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions pkg/client/endpoint.go
Expand Up @@ -143,9 +143,7 @@ func (c *Client) EndpointLabelsPatch(id string, toAdd, toDelete models.Labels) e
}
for _, lbl := range toDelete {
lblParsed := labels.ParseLabel(lbl)
if _, found := userLbl[lblParsed.Key]; found {
delete(userLbl, lblParsed.Key)
}
delete(userLbl, lblParsed.Key)
}
currentCfg.Spec.User = userLbl.GetModel()

Expand Down
8 changes: 2 additions & 6 deletions pkg/identity/cache/cache.go
Expand Up @@ -116,9 +116,7 @@ func collectEvent(event allocator.AllocatorEvent, added, deleted IdentityCache)
// Un-delete the added ID if previously
// 'deleted' so that collected events can be
// processed in any order.
if _, exists := deleted[id]; exists {
delete(deleted, id)
}
delete(deleted, id)
added[id] = gi.LabelArray
return true
}
Expand All @@ -127,9 +125,7 @@ func collectEvent(event allocator.AllocatorEvent, added, deleted IdentityCache)
return false
}
// Reverse an add when subsequently deleted
if _, exists := added[id]; exists {
delete(added, id)
}
delete(added, id)
// record the id deleted even if an add was reversed, as the
// id may also have previously existed, in which case the
// result is not no-op!
Expand Down

0 comments on commit 838e3b8

Please sign in to comment.