-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcore.go
58 lines (47 loc) · 1.31 KB
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright Microsoft Corp.
// All rights reserved.
package core
import (
"fmt"
"os"
"github.com/Microsoft/go-winio/pkg/etwlogrus"
"github.com/Microsoft/windows-container-networking/cni"
"github.com/Microsoft/windows-container-networking/common"
"github.com/sirupsen/logrus"
)
// Version is populated by make during build.
var version string
// The entry point for CNI network plugin.
func Core() {
var config common.PluginConfig
config.Version = version
// Provider ID: {c822b598-f4cc-5a72-7933-ce2a816d033f}
if hook, err := etwlogrus.NewHook("wincni"); err == nil {
logrus.AddHook(hook)
}
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetLevel(logrus.DebugLevel)
file, err := os.OpenFile("wincni.log", os.O_CREATE|os.O_WRONLY, os.FileMode(0777))
if err != nil {
fmt.Println("OpenFile wincni.log error")
os.Exit(1)
}
logrus.SetOutput(file)
defer file.Close()
netPlugin, err := NewPlugin(&config)
if err != nil {
logrus.Errorf("Failed to create network plugin, err:%v", err)
os.Exit(1)
}
err = netPlugin.Start(&config)
if err != nil {
logrus.Errorf("Failed to start network plugin, err:%v.\n", err)
os.Exit(1)
}
err = netPlugin.Execute(cni.PluginApi(netPlugin))
netPlugin.Stop()
if err != nil {
logrus.Errorf("Failed to Execute network plugin, err:%v.\n", err)
os.Exit(1)
}
}