Skip to content

Commit

Permalink
Merge pull request #451 from venkatesh-eb/fix_log_flush
Browse files Browse the repository at this point in the history
Switch from skel.PluginMain to skel.PluginMainWithError, as the log h…
  • Loading branch information
Claes Mogren authored May 7, 2019
2 parents 957f835 + 6d9ff85 commit 6fe1ecf
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions plugins/routed-eni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"net"
"os"
"runtime"

"golang.org/x/net/context"
Expand Down Expand Up @@ -142,7 +143,7 @@ func add(args *skel.CmdArgs, cniTypes typeswrapper.CNITYPES, grpcClient grpcwrap
K8S_POD_NAME: string(k8sArgs.K8S_POD_NAME),
K8S_POD_NAMESPACE: string(k8sArgs.K8S_POD_NAMESPACE),
K8S_POD_INFRA_CONTAINER_ID: string(k8sArgs.K8S_POD_INFRA_CONTAINER_ID),
IfName: args.IfName})
IfName: args.IfName})

if err != nil {
log.Errorf("Error received from AddNetwork grpc call for pod %s namespace %s container %s: %v",
Expand Down Expand Up @@ -296,10 +297,20 @@ func del(args *skel.CmdArgs, cniTypes typeswrapper.CNITYPES, grpcClient grpcwrap
}

func main() {
defer log.Flush()
logger.SetupLogger(logger.GetLogFileLocation(defaultLogFilePath))

log.Infof("Starting CNI Plugin %s ...", version)

skel.PluginMain(cmdAdd, cmdDel, cniSpecVersion.All)
exitCode := 0

if e := skel.PluginMainWithError(cmdAdd, cmdDel, cniSpecVersion.All); e != nil {
exitCode = 1
log.Error("Failed CNI request: ", e)
if err := e.Print(); err != nil {
log.Error("Error writing error JSON to stdout: ", err)
}
}

log.Flush()
os.Exit(exitCode)
}

0 comments on commit 6fe1ecf

Please sign in to comment.