Skip to content

Commit d4df708

Browse files
[Fix][CNS] InterfaceID should be set to containerID instead of interfaceName if CNS managing state (Azure#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
1 parent 51152f3 commit d4df708

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

cns/cnireconciler/podinfoprovider.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ func cniStateToPodInfoByIP(state *api.AzureCNIState) (map[string]cns.PodInfo, er
7171
func endpointStateToPodInfoByIP(state map[string]*restserver.EndpointInfo) (map[string]cns.PodInfo, error) {
7272
podInfoByIP := map[string]cns.PodInfo{}
7373
for containerID, endpointInfo := range state { // for each endpoint
74-
for ifname, ipinfo := range endpointInfo.IfnameToIPMap { // for each IP info object of the endpoint's interfaces
74+
for _, ipinfo := range endpointInfo.IfnameToIPMap { // for each IP info object of the endpoint's interfaces
7575
for _, ipv4conf := range ipinfo.IPv4 { // for each IPv4 config of the endpoint's interfaces
7676
if _, ok := podInfoByIP[ipv4conf.IP.String()]; ok {
7777
return nil, errors.Wrap(cns.ErrDuplicateIP, ipv4conf.IP.String())
7878
}
7979
podInfoByIP[ipv4conf.IP.String()] = cns.NewPodInfo(
8080
containerID,
81-
ifname,
81+
containerID,
8282
endpointInfo.PodName,
8383
endpointInfo.PodNamespace,
8484
)
@@ -89,7 +89,7 @@ func endpointStateToPodInfoByIP(state map[string]*restserver.EndpointInfo) (map[
8989
}
9090
podInfoByIP[ipv6conf.IP.String()] = cns.NewPodInfo(
9191
containerID,
92-
ifname,
92+
containerID,
9393
endpointInfo.PodName,
9494
endpointInfo.PodNamespace,
9595
)

cns/cnireconciler/podinfoprovider_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ func TestNewCNSPodInfoProvider(t *testing.T) {
8181
wantErr bool
8282
}{
8383
{
84-
name: "good",
85-
store: goodStore,
86-
want: map[string]cns.PodInfo{"10.241.0.65": cns.NewPodInfo("0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea", "eth0", "goldpinger-deploy-bbbf9fd7c-z8v4l", "default")},
84+
name: "good",
85+
store: goodStore,
86+
want: map[string]cns.PodInfo{"10.241.0.65": cns.NewPodInfo("0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea",
87+
"0a4917617e15d24dc495e407d8eb5c88e4406e58fa209e4eb75a2c2fb7045eea", "goldpinger-deploy-bbbf9fd7c-z8v4l", "default")},
8788
wantErr: false,
8889
},
8990
{

cns/restserver/ipam.go

+1
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ func (service *HTTPRestService) GetExistingIPConfig(podInfo cns.PodInfo) ([]cns.
655655
}
656656
}
657657

658+
logger.Printf("[GetExistingIPConfig] IPConfigExists [%t] for pod [%+v]", ipConfigExists, podInfo.Key())
658659
return podIPInfo, ipConfigExists, nil
659660
}
660661

0 commit comments

Comments
 (0)