Skip to content

Commit

Permalink
fix: fixing CNS IP releae for azure CNI in case of managed endpoint s… (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
behzad-mir authored Feb 16, 2024
1 parent 1a48e2f commit cb484c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type podInfoScheme int
const (
KubernetesPodInfoScheme podInfoScheme = iota
InterfaceIDPodInfoScheme
InfraIDPodInfoScheme
)

// PodInfo represents the object that we are providing network for.
Expand Down Expand Up @@ -249,11 +250,18 @@ func (p *podInfo) InterfaceID() string {
// orchestrator pod name and namespace. if the Version is interfaceID, key is
// composed of the CNI interfaceID, which is generated from the CRI infra
// container ID and the pod net ns primary interface name.
// If the version in InfraContainerID then the key is containerID.
func (p *podInfo) Key() string {
if p.Version == InterfaceIDPodInfoScheme {
switch p.Version {
case InfraIDPodInfoScheme:
return p.PodInfraContainerID
case InterfaceIDPodInfoScheme:
return p.PodInterfaceID
case KubernetesPodInfoScheme:
return p.PodName + ":" + p.PodNamespace
default:
return p.PodName + ":" + p.PodNamespace
}
return p.PodName + ":" + p.PodNamespace
}

func (p *podInfo) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func (service *HTTPRestService) releaseIPConfigs(podInfo cns.PodInfo) error {
service.Lock()
defer service.Unlock()
ipsToBeReleased := make([]cns.IPConfigurationStatus, 0)

logger.Printf("[releaseIPConfigs] Releasing pod with key %s", podInfo.Key())
for i, ipID := range service.PodIPIDByPodInterfaceKey[podInfo.Key()] {
if ipID != "" {
if ipconfig, isExist := service.PodIPConfigState[ipID]; isExist {
Expand Down
6 changes: 5 additions & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func main() {
// in this case, cns maintains state with containerid as key and so in-memory cache can lookup
// and update based on container id.
if cnsconfig.ManageEndpointState {
cns.GlobalPodInfoScheme = cns.InterfaceIDPodInfoScheme
cns.GlobalPodInfoScheme = cns.InfraIDPodInfoScheme
}

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

var podInfoByIPProvider cns.PodInfoByIPProvider
Expand Down

0 comments on commit cb484c3

Please sign in to comment.