Skip to content

Commit cb484c3

Browse files
authored
fix: fixing CNS IP releae for azure CNI in case of managed endpoint s… (#2588)
* fix: fixing CNS IP releae for azure CNI in case of managed endpoint state. * fix: changing PodInfo Key to InfraContainerID when Mange Endpoint State is enabled.
1 parent 1a48e2f commit cb484c3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Diff for: cns/NetworkContainerContract.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ type podInfoScheme int
180180
const (
181181
KubernetesPodInfoScheme podInfoScheme = iota
182182
InterfaceIDPodInfoScheme
183+
InfraIDPodInfoScheme
183184
)
184185

185186
// PodInfo represents the object that we are providing network for.
@@ -249,11 +250,18 @@ func (p *podInfo) InterfaceID() string {
249250
// orchestrator pod name and namespace. if the Version is interfaceID, key is
250251
// composed of the CNI interfaceID, which is generated from the CRI infra
251252
// container ID and the pod net ns primary interface name.
253+
// If the version in InfraContainerID then the key is containerID.
252254
func (p *podInfo) Key() string {
253-
if p.Version == InterfaceIDPodInfoScheme {
255+
switch p.Version {
256+
case InfraIDPodInfoScheme:
257+
return p.PodInfraContainerID
258+
case InterfaceIDPodInfoScheme:
254259
return p.PodInterfaceID
260+
case KubernetesPodInfoScheme:
261+
return p.PodName + ":" + p.PodNamespace
262+
default:
263+
return p.PodName + ":" + p.PodNamespace
255264
}
256-
return p.PodName + ":" + p.PodNamespace
257265
}
258266

259267
func (p *podInfo) Name() string {

Diff for: cns/restserver/ipam.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func (service *HTTPRestService) releaseIPConfigs(podInfo cns.PodInfo) error {
713713
service.Lock()
714714
defer service.Unlock()
715715
ipsToBeReleased := make([]cns.IPConfigurationStatus, 0)
716-
716+
logger.Printf("[releaseIPConfigs] Releasing pod with key %s", podInfo.Key())
717717
for i, ipID := range service.PodIPIDByPodInterfaceKey[podInfo.Key()] {
718718
if ipID != "" {
719719
if ipconfig, isExist := service.PodIPConfigState[ipID]; isExist {

Diff for: cns/service/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ func main() {
843843
// in this case, cns maintains state with containerid as key and so in-memory cache can lookup
844844
// and update based on container id.
845845
if cnsconfig.ManageEndpointState {
846-
cns.GlobalPodInfoScheme = cns.InterfaceIDPodInfoScheme
846+
cns.GlobalPodInfoScheme = cns.InfraIDPodInfoScheme
847847
}
848848

849849
logger.Printf("Set GlobalPodInfoScheme %v (InitializeFromCNI=%t)", cns.GlobalPodInfoScheme, cnsconfig.InitializeFromCNI)
@@ -1244,6 +1244,10 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
12441244
if err = PopulateCNSEndpointState(httpRestServiceImplementation.EndpointStateStore); err != nil {
12451245
return errors.Wrap(err, "failed to create CNS EndpointState From CNI")
12461246
}
1247+
// endpoint state needs tobe loaded in memory so the subsequent Delete calls remove the state and release the IPs.
1248+
if err = httpRestServiceImplementation.EndpointStateStore.Read(restserver.EndpointStoreKey, &httpRestServiceImplementation.EndpointState); err != nil {
1249+
return errors.Wrap(err, "failed to restore endpoint state")
1250+
}
12471251
}
12481252

12491253
var podInfoByIPProvider cns.PodInfoByIPProvider

0 commit comments

Comments
 (0)