Skip to content

Commit

Permalink
ipcache/md: Add queue to handle identity updates
Browse files Browse the repository at this point in the history
Add a queue into the metadata structure for handling the set of prefixes
which need to be processed as part of the next label injection trigger.

Signed-off-by: Joe Stringer <joe@cilium.io>
  • Loading branch information
joestringer committed Sep 1, 2022
1 parent e39244c commit cd9783e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pkg/ipcache/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,41 @@ type metadata struct {
// applyChangesMU protects InjectLabels and RemoveLabelsExcluded from being
// run in parallel
applyChangesMU lock.Mutex

// queued* handle updates into the IPCache. Whenever a label is added
// or removed from a specific IP prefix, that prefix is added into
// 'queuedPrefixes'. Each time label injection is triggered, it will
// process the metadata changes for these prefixes and potentially
// generate updates into the ipcache, policy engine and datapath.
queuedChangesMU lock.Mutex
queuedPrefixes map[string]struct{}
}

func newMetadata() *metadata {
return &metadata{
m: make(map[string]prefixInfo),
m: make(map[string]prefixInfo),
queuedPrefixes: make(map[string]struct{}),
}
}

func (m *metadata) dequeuePrefixUpdates() (modifiedPrefixes []string) {
m.queuedChangesMU.Lock()
modifiedPrefixes = make([]string, 0, len(m.queuedPrefixes))
for p := range m.queuedPrefixes {
modifiedPrefixes = append(modifiedPrefixes, p)
}
m.queuedPrefixes = make(map[string]struct{})
m.queuedChangesMU.Unlock()

return
}

func (m *metadata) enqueuePrefixUpdates(prefixes ...string) {
m.queuedChangesMU.Lock()
defer m.queuedChangesMU.Unlock()

for _, prefix := range prefixes {
m.queuedPrefixes[prefix] = struct{}{}
}
}

Expand Down

0 comments on commit cd9783e

Please sign in to comment.