From bd5535eecaab82f18ea10f9a7b1f82eafcedec4a Mon Sep 17 00:00:00 2001 From: Behzad Mirkhanzadeh Date: Thu, 15 Aug 2024 14:47:19 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20make=20statless=20CNI=20to=20return=20an?= =?UTF-8?q?=20empty=20state=20when=20CNI=20GET=20API=20is=20=E2=80=A6=20(#?= =?UTF-8?q?2921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: make statless CNI to return an empty state when CNI GET API is invoked --- cni/network/stateless/main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cni/network/stateless/main.go b/cni/network/stateless/main.go index afd7ea1433..2b273da7eb 100644 --- a/cni/network/stateless/main.go +++ b/cni/network/stateless/main.go @@ -9,6 +9,7 @@ import ( "time" "github.com/Azure/azure-container-networking/cni" + "github.com/Azure/azure-container-networking/cni/api" zapLog "github.com/Azure/azure-container-networking/cni/log" "github.com/Azure/azure-container-networking/cni/network" "github.com/Azure/azure-container-networking/common" @@ -127,6 +128,19 @@ func rootExecute() error { panic("network plugin start fatal error") } } + // dump an empty state in case the API is called for StateMigration or InitilizeCNS from CNI State + if cniCmd == cni.CmdGetEndpointsState { + logger.Debug("returning an empty state") + simpleState := api.AzureCNIState{ + ContainerInterfaces: make(map[string]api.PodNetworkInterfaceInfo), + } + err = simpleState.PrintResult() + if err != nil { + logger.Error("Failed to print state result to stdout", zap.Error(err)) + } + + return errors.Wrap(err, "Get cni state printresult error") + } if cniCmd == cni.CmdVersion { return errors.Wrap(err, "Execute netplugin failure")