Skip to content

Commit bd5535e

Browse files
authored
fix: make statless CNI to return an empty state when CNI GET API is … (#2921)
feat: make statless CNI to return an empty state when CNI GET API is invoked
1 parent 9ff0bac commit bd5535e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cni/network/stateless/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/Azure/azure-container-networking/cni"
12+
"github.com/Azure/azure-container-networking/cni/api"
1213
zapLog "github.com/Azure/azure-container-networking/cni/log"
1314
"github.com/Azure/azure-container-networking/cni/network"
1415
"github.com/Azure/azure-container-networking/common"
@@ -127,6 +128,19 @@ func rootExecute() error {
127128
panic("network plugin start fatal error")
128129
}
129130
}
131+
// dump an empty state in case the API is called for StateMigration or InitilizeCNS from CNI State
132+
if cniCmd == cni.CmdGetEndpointsState {
133+
logger.Debug("returning an empty state")
134+
simpleState := api.AzureCNIState{
135+
ContainerInterfaces: make(map[string]api.PodNetworkInterfaceInfo),
136+
}
137+
err = simpleState.PrintResult()
138+
if err != nil {
139+
logger.Error("Failed to print state result to stdout", zap.Error(err))
140+
}
141+
142+
return errors.Wrap(err, "Get cni state printresult error")
143+
}
130144

131145
if cniCmd == cni.CmdVersion {
132146
return errors.Wrap(err, "Execute netplugin failure")

0 commit comments

Comments
 (0)