-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle async delete in stateless cni (#2967)
* feat: adding stateless CNI pipeline test * feat: making change for stateless CNI pipeline * feat: addressing the comments * fix: fixing stateles cni yaml * fix: stateless CNI delete fix * fix: addressing the comments * fix: addressing the comments and fix linter issues * Update cns/fsnotify/fsnotify.go Co-authored-by: tamilmani1989 <tamanoha@microsoft.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * Update cni/network/network.go Co-authored-by: tamilmani1989 <tamanoha@microsoft.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * Update cni/network/network.go Co-authored-by: tamilmani1989 <tamanoha@microsoft.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * fix: addressing the comments * fix: fix the error code. * Fix: decoupling hnsclient form CNS watcher * fix: adding endpointmanager package to resolve platfrom specific call to HNS * Update cns/endpointmanager/endpointmanager_linux.go Co-authored-by: Evan Baker <rbtr@users.noreply.github.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * Update cns/service/main.go Co-authored-by: Evan Baker <rbtr@users.noreply.github.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * Fix: addressing the comments * fix: removing stateless CNI pipline changes form the PR * Update cns/configuration/configuration.go Co-authored-by: Evan Baker <rbtr@users.noreply.github.com> Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> * addressing the comment --------- Signed-off-by: Behzad Mirkhanzadeh <b.mirkhanzadeh@gmail.com> Co-authored-by: tamilmani1989 <tamanoha@microsoft.com> Co-authored-by: Evan Baker <rbtr@users.noreply.github.com>
- Loading branch information
1 parent
4c0eb94
commit a9fccfa
Showing
13 changed files
with
213 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package endpointmanager | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
"github.com/Azure/azure-container-networking/cns/restserver" | ||
) | ||
|
||
type EndpointManager struct { | ||
cli releaseIPsClient // nolint | ||
} | ||
|
||
type releaseIPsClient interface { | ||
ReleaseIPs(ctx context.Context, ipconfig cns.IPConfigsRequest) error | ||
GetEndpoint(ctx context.Context, endpointID string) (*restserver.GetEndpointResponse, error) | ||
} | ||
|
||
func WithPlatformReleaseIPsManager(cli releaseIPsClient) *EndpointManager { | ||
return &EndpointManager{cli: cli} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package endpointmanager | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ReleaseIPs implements an Interface in fsnotify for async delete of the HNS endpoint and IP addresses | ||
func (em *EndpointManager) ReleaseIPs(ctx context.Context, ipconfigreq cns.IPConfigsRequest) error { | ||
return errors.Wrap(em.cli.ReleaseIPs(ctx, ipconfigreq), "failed to release IP from CNS") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package endpointmanager | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
"github.com/Azure/azure-container-networking/cns/hnsclient" | ||
"github.com/Azure/azure-container-networking/cns/logger" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ReleaseIPs implements an Interface in fsnotify for async delete of the HNS endpoint and IP addresses | ||
func (em *EndpointManager) ReleaseIPs(ctx context.Context, ipconfigreq cns.IPConfigsRequest) error { | ||
logger.Printf("deleting HNS Endpoint asynchronously") | ||
// remove HNS endpoint | ||
if err := em.deleteEndpoint(ctx, ipconfigreq.InfraContainerID); err != nil { | ||
logger.Errorf("failed to remove HNS endpoint %s", err.Error()) | ||
} | ||
return errors.Wrap(em.cli.ReleaseIPs(ctx, ipconfigreq), "failed to release IP from CNS") | ||
} | ||
|
||
// deleteEndpoint API to get the state and then remove assiciated HNS | ||
func (em *EndpointManager) deleteEndpoint(ctx context.Context, containerid string) error { | ||
endpointResponse, err := em.cli.GetEndpoint(ctx, containerid) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to read the endpoint from CNS state") | ||
} | ||
for _, ipInfo := range endpointResponse.EndpointInfo.IfnameToIPMap { | ||
hnsEndpointID := ipInfo.HnsEndpointID | ||
// we need to get the HNSENdpoint via the IP address if the HNSEndpointID is not present in the statefile | ||
if ipInfo.HnsEndpointID == "" { | ||
if hnsEndpointID, err = hnsclient.GetHNSEndpointbyIP(ipInfo.IPv4, ipInfo.IPv6); err != nil { | ||
return errors.Wrap(err, "failed to find HNS endpoint with id") | ||
} | ||
} | ||
logger.Printf("deleting HNS Endpoint with id %v", hnsEndpointID) | ||
if err := hnsclient.DeleteHNSEndpointbyID(hnsEndpointID); err != nil { | ||
return errors.Wrap(err, "failed to delete HNS endpoint with id "+ipInfo.HnsEndpointID) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters