Skip to content

fix: endpointID for Stateless CNI should add ifName if the NiCType is… #3770

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,11 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
if opt.ifInfo.NICType == cns.InfraNIC && !*opt.infraSeen {
// so we do not break existing scenarios, only the first infra gets the original endpoint id generation
ifName = opt.args.IfName
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName)
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName, opt.ifInfo.NICType)
*opt.infraSeen = true
} else {
ifName = "eth" + strconv.Itoa(opt.endpointIndex)
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName)
endpointID = plugin.nm.GetEndpointID(opt.args.ContainerID, ifName, opt.ifInfo.NICType)
}

endpointInfo := network.EndpointInfo{
Expand Down Expand Up @@ -1096,7 +1096,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
// for when the endpoint is not created, but the ips are already allocated (only works if single network, single infra)
// this block is not applied to stateless CNI
if len(epInfos) == 0 {
endpointID := plugin.nm.GetEndpointID(args.ContainerID, args.IfName)
endpointID := plugin.nm.GetEndpointID(args.ContainerID, args.IfName, cns.InfraNIC)
if !nwCfg.MultiTenancy {
logger.Warn("Could not query endpoint",
zap.String("endpoint", endpointID),
Expand Down
7 changes: 5 additions & 2 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type NetworkManager interface {
DetachEndpoint(networkID string, endpointID string) error
UpdateEndpoint(networkID string, existingEpInfo *EndpointInfo, targetEpInfo *EndpointInfo) error
GetNumberOfEndpoints(ifName string, networkID string) int
GetEndpointID(containerID, ifName string) string
GetEndpointID(containerID, ifName string, nicType cns.NICType) string
IsStatelessCNIMode() bool
SaveState(eps []*endpoint) error
DeleteState(epInfos []*EndpointInfo) error
Expand Down Expand Up @@ -732,8 +732,11 @@ func (nm *networkManager) GetNumberOfEndpoints(ifName string, networkId string)
}

// GetEndpointID returns a unique endpoint ID based on the CNI mode.
func (nm *networkManager) GetEndpointID(containerID, ifName string) string {
func (nm *networkManager) GetEndpointID(containerID, ifName string, nicType cns.NICType) string {
if nm.IsStatelessCNIMode() {
if nicType == cns.DelegatedVMNIC {
return containerID + "-" + ifName
Copy link
Preview

Copilot AI Jul 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using fmt.Sprintf("%s-%s", containerID, ifName) or defining a constant delimiter to improve readability and consistency.

Copilot uses AI. Check for mistakes.

}
return containerID
}
if len(containerID) > ContainerIDLength {
Expand Down
3 changes: 2 additions & 1 deletion network/manager_mock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/common"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (nm *MockNetworkManager) IsStatelessCNIMode() bool {
}

// GetEndpointID returns the ContainerID value
func (nm *MockNetworkManager) GetEndpointID(containerID, ifName string) string {
func (nm *MockNetworkManager) GetEndpointID(containerID, ifName string, _ cns.NICType) string {
if nm.IsStatelessCNIMode() {
return containerID
}
Expand Down
Loading