-
Notifications
You must be signed in to change notification settings - Fork 386
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
Fix rollback invocation after CmdAdd failure in CNI server #5548
Merged
antoninbas
merged 2 commits into
antrea-io:main
from
antoninbas:fix-rollback-after-cni-add-failure
Oct 9, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I agree that it is an improvement to directly use the existing "cniConfig" in cmdDel to avoid unnecessary call on
loadNetworkConfig
.However, I didn't understand why the original code can append a duplicate PodCIDR range in the IPAM configuration. When we call function
loadNetworkConfig
in CmdDel/CmdAdd/CmdCheck, it has generated a newCNIConfig
object, and thecniConfig.NetworkConfig
is unmarshaled from the json stringrequest.CniArgs.NetworkConfiguration
. So even if we call CmdDel in CmdAdd rollback, the cniConfig passed to IPAM plugin from a new call withloadNetworkConfig
is supposed to equal to the values existing in CmdAdd.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 original code was calling
validateRequest
for the rollback (becauseCmdDel
callsvalidateRequest
), using the samerequest
object.validateRequest
actually mutates therequest
but it is not obvious when looking at the code:loadNetworkConfig
has the following assignment:antrea/pkg/agent/cniserver/server.go
Line 198 in bbec9d0
cniConfig.CniCmdArgs
(a pointer to a protobuf struct) will mutate the request.updateLocalIPAMSubnet
has the following assignment:antrea/pkg/agent/cniserver/server.go
Line 275 in bbec9d0
cniConfig.NetworkConfiguration
is actually the same ascniConfig.CniCmdArgs.NetworkConfiguration
(it is a byte slice). So at this point we have mutated the request. The next time we callvalidateRequestMessage
(which we no longer do with my patch), the network configuration of the request already includes the Node subnets in the IPAM section.I confirmed all of this with my unit test.
Note that I don't know why we are mutating the request in the first place; I don't know if it's intentional, but I think we have been doing it for 4 years. Since using the existing
cniConfig
seemed like the right thing to do, that's what I did in this patch. We could consider a follow-up patch to clean up existing logic, but I didn't want to risk introducing a new bug.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.
To clarify the statement above:
This is because
CniCmdArgs
is an embedded field:antrea/pkg/agent/cniserver/server.go
Lines 127 to 136 in bbec9d0
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.
Got it, thanks for the clarification.