Skip to content

Commit

Permalink
[Fix][CNS] InterfaceID should be set to containerID instead of interf…
Browse files Browse the repository at this point in the history
…aceName if CNS managing state (#2023)

* InterfaceID should be set to containerID instead of interfaceName if CNS manage endpoint state is enabled

* add log in GetExistingIPConfig function to debug

* Fix UT (set containerid as pod interface id)
lint fix
  • Loading branch information
tamilmani1989 authored Jun 22, 2023
1 parent 67ec347 commit 9a410fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cns/cnireconciler/podinfoprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func cniStateToPodInfoByIP(state *api.AzureCNIState) (map[string]cns.PodInfo, er
func endpointStateToPodInfoByIP(state map[string]*restserver.EndpointInfo) (map[string]cns.PodInfo, error) {
podInfoByIP := map[string]cns.PodInfo{}
for containerID, endpointInfo := range state { // for each endpoint
for ifname, ipinfo := range endpointInfo.IfnameToIPMap { // for each IP info object of the endpoint's interfaces
for _, ipinfo := range endpointInfo.IfnameToIPMap { // for each IP info object of the endpoint's interfaces
for _, ipv4conf := range ipinfo.IPv4 { // for each IPv4 config of the endpoint's interfaces
if _, ok := podInfoByIP[ipv4conf.IP.String()]; ok {
return nil, errors.Wrap(cns.ErrDuplicateIP, ipv4conf.IP.String())
}
podInfoByIP[ipv4conf.IP.String()] = cns.NewPodInfo(
containerID,
ifname,
containerID,
endpointInfo.PodName,
endpointInfo.PodNamespace,
)
Expand All @@ -89,7 +89,7 @@ func endpointStateToPodInfoByIP(state map[string]*restserver.EndpointInfo) (map[
}
podInfoByIP[ipv6conf.IP.String()] = cns.NewPodInfo(
containerID,
ifname,
containerID,
endpointInfo.PodName,
endpointInfo.PodNamespace,
)
Expand Down
7 changes: 4 additions & 3 deletions cns/cnireconciler/podinfoprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ func TestNewCNSPodInfoProvider(t *testing.T) {
wantErr bool
}{
{
name: "good",
store: goodStore,
want: map[string]cns.PodInfo{"10.241.0.65": cns.NewPodInfo("0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea", "eth0", "goldpinger-deploy-bbbf9fd7c-z8v4l", "default")},
name: "good",
store: goodStore,
want: map[string]cns.PodInfo{"10.241.0.65": cns.NewPodInfo("0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea",
"0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea", "goldpinger-deploy-bbbf9fd7c-z8v4l", "default")},
wantErr: false,
},
{
Expand Down
1 change: 1 addition & 0 deletions cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ func (service *HTTPRestService) GetExistingIPConfig(podInfo cns.PodInfo) (cns.Po
return podIpInfo, isExist, fmt.Errorf("Failed to get existing ipconfig. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")
}

logger.Printf("[GetExistingIPConfig] IPConfigExists [%t] for pod [%s]", isExist, podInfo)
return podIpInfo, isExist, nil
}

Expand Down

0 comments on commit 9a410fc

Please sign in to comment.