-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Use ListAll() to reduce nft subprocesses during resync #12471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||
| // Copyright (c) 2016-2024 Tigera, Inc. All rights reserved. | ||||||||||||||||||||||||||||
| // Copyright (c) 2016-2026 Tigera, Inc. All rights reserved. | ||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||
|
|
@@ -646,8 +646,25 @@ func (t *NftablesTable) decrefChain(chainName string) { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func (t *NftablesTable) loadDataplaneState() { | ||||||||||||||||||||||||||||
| // Sync maps. | ||||||||||||||||||||||||||||
| if err := t.LoadDataplaneState(); err != nil { | ||||||||||||||||||||||||||||
| // Fetch all object names from the dataplane in a single nft invocation. | ||||||||||||||||||||||||||||
| // This replaces separate List("map") and List("chain") calls, halving | ||||||||||||||||||||||||||||
| // the number of nft subprocesses during resync. | ||||||||||||||||||||||||||||
| ctx, cancel := context.WithTimeout(context.Background(), t.contextTimeout) | ||||||||||||||||||||||||||||
| defer cancel() | ||||||||||||||||||||||||||||
| allObjects, err := t.nft.ListAll(ctx) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| if knftables.IsNotFound(err) { | ||||||||||||||||||||||||||||
| t.logCxt.Debug("Table not found in dataplane, nothing to load.") | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| t.logCxt.WithError(err).Warn("Failed to list all nftables objects") | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // Fall through — maps and chains will get empty slices, which is | ||||||||||||||||||||||||||||
| // correct when the table doesn't exist yet. | ||||||||||||||||||||||||||||
| allObjects = map[string][]string{} | ||||||||||||||||||||||||||||
|
Comment on lines
+658
to
+663
|
||||||||||||||||||||||||||||
| } else { | |
| t.logCxt.WithError(err).Warn("Failed to list all nftables objects") | |
| } | |
| // Fall through — maps and chains will get empty slices, which is | |
| // correct when the table doesn't exist yet. | |
| allObjects = map[string][]string{} | |
| // Fall through — maps and chains will get empty slices, which is | |
| // correct when the table doesn't exist yet. | |
| allObjects = map[string][]string{} | |
| } else { | |
| t.logCxt.WithError(err).Warn("Failed to list all nftables objects") | |
| return | |
| } |
Copilot
AI
Apr 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nft list table is being invoked with only the table name. Since Felix creates both IPv4 and IPv6 tables with the same name (e.g. "calico"), this may dump the wrong table or fail depending on nft's argument parsing. Consider including the nftables family (ip/ip6/arp) in the command invocation (store the family on NftablesTable so it can be used here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same timeout-scoped ctx is used for both ListAll() and the subsequent map resync (which may issue many ListElements calls). This couples their time budgets and can cause premature context deadline exceeded during large resyncs. Consider using separate contexts/timeouts per operation (or let Maps.LoadDataplaneState derive its own per-call timeouts).