Skip to content
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: dualnic options to avoid overwritting vlanMaps #2928

Merged
merged 14 commits into from
Aug 22, 2024
Merged

Conversation

paulyufan2
Copy link
Contributor

@paulyufan2 paulyufan2 commented Aug 16, 2024

Reason for Change:

This PR is to fix dualnic options to avoid overwritting vlanMaps
In the windows dualnic multitenancy case, we receive two interface infos from cns and should create two corresponding networks and endpoints. The first and second endpoints created by hns should have vlan id 1 and vlan id 2, respectively. It is CNI's job to parse the cns input and send a request to hns to create the endpoints.

However, during testing both endpoints have vlan id 2. This is because the ipamAddConfig's options field is unintentionally shared between each EndpointInfo struct. Modifying the vlan id of one options field in an endpoint info struct inadvertently modifies every other endpoint info struct's options. So, the vlan id reflected during endpoint creation is of the last endpoint info's vlan id only, as all endpoint info option fields point to the same underlying object in memory.

The proposed solution is to, for each endpoint info we create, we shallow copy the ipamAddConfig's options field. So, every endpoint info gets its own copy of the options field which it can modify and store without modifying the other endpoint infos.

If the options field of type map[string]interface{} ever holds anything other than primitives before we perform the shallow copy (ex: if we store pointers to another object as a value in the map) the copied pointer will still be pointing to the same object and we will have the same issue, but as of now we have only identified a single instance where we write to the options field in invoker_cns.go (ncPrimaryIP) where the value is of type string, which is immutable.

Issue Fixed:

Requirements:

Notes:
To be tested by partner team(s) before being merged.

@paulyufan2 paulyufan2 added cni Related to CNI. fix Fixes something. labels Aug 16, 2024
@paulyufan2 paulyufan2 requested a review from a team as a code owner August 16, 2024 20:18
cni/network/invoker.go Outdated Show resolved Hide resolved
cni/network/network.go Outdated Show resolved Hide resolved
@paulyufan2
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulyufan2 paulyufan2 force-pushed the dualnicvlanfix branch 3 times, most recently from b63c064 to 38c0b33 Compare August 20, 2024 17:56
@paulyufan2
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add the vlan id to ep info pretty print (endpoint.go) or similar pretty string (should not panic/err if no vlan id is present/map is nil)?

cni/network/invoker_cns_test.go Show resolved Hide resolved
cni/network/network.go Outdated Show resolved Hide resolved
cni/network/network_linux.go Outdated Show resolved Hide resolved
cni/network/network_windows.go Outdated Show resolved Hide resolved
@paulyufan2
Copy link
Contributor Author

Is it possible to add the vlan id to ep info pretty print (endpoint.go) or similar pretty string (should not panic/err if no vlan id is present/map is nil)?

we have already printed vlanID when setting options (key and value)

@QxBytes
Copy link
Contributor

QxBytes commented Aug 21, 2024

Is it possible to add the vlan id to ep info pretty print (endpoint.go) or similar pretty string (should not panic/err if no vlan id is present/map is nil)?

we have already printed vlanID when setting options (key and value)

At EndpointCreate, after we generate all epInfos, we print each endpointInfo. If the pretty string function printed the options map (similar to how we print the data map) this would catch the vlan id issue. The log statement in the setting options function would not catch this because it only prints the value for the current iteration and does not print out the previous values of epInfo vlan id to confirm that it has not been improperly modified.

@paulyufan2 paulyufan2 requested a review from a team as a code owner August 21, 2024 18:40
cni/network/invoker_cns_test.go Outdated Show resolved Hide resolved
cni/network/invoker_cns_test.go Outdated Show resolved Hide resolved
cni/network/network.go Outdated Show resolved Hide resolved
QxBytes
QxBytes previously approved these changes Aug 21, 2024
Copy link
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure tested with partner teams if you haven't done so already

@QxBytes
Copy link
Contributor

QxBytes commented Aug 21, 2024

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulyufan2
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

QxBytes
QxBytes previously approved these changes Aug 21, 2024
@paulyufan2 paulyufan2 enabled auto-merge August 21, 2024 21:32
cni/network/network_linux.go Outdated Show resolved Hide resolved
@paulyufan2
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulyufan2
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulyufan2 paulyufan2 added this pull request to the merge queue Aug 22, 2024
Merged via the queue into master with commit ec1a1ee Aug 22, 2024
11 checks passed
@paulyufan2 paulyufan2 deleted the dualnicvlanfix branch August 22, 2024 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cni Related to CNI. fix Fixes something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants