-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathmain.go
91 lines (73 loc) · 2.15 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2017 Microsoft. All rights reserved.
// MIT License
package main
import (
"context"
"fmt"
"os"
"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cni/ipam"
zaplog "github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
"go.uber.org/zap/zapcore"
)
const (
name = "azure-vnet-ipamv6"
maxLogFileSizeInMb = 5
maxLogFileCount = 8
component = "cni"
)
// Version is populated by make during build.
var version string
// Main is the entry point for CNI IPAM plugin.
func main() {
ctx, cancel := context.WithCancel(context.Background())
var config common.PluginConfig
config.Version = version
logDirectory := "" // Sets the current location as log directory
log.SetName(name)
log.SetLevel(log.LevelInfo)
if err := log.SetTargetLogDirectory(log.TargetLogfile, logDirectory); err != nil {
fmt.Printf("Failed to setup cni logging: %v\n", err)
return
}
defer log.Close()
loggerCfg := &zaplog.Config{
Level: zapcore.DebugLevel,
LogPath: zaplog.LogPath + "azure-ipam.log",
MaxSizeInMB: maxLogFileSizeInMb,
MaxBackups: maxLogFileCount,
Name: name,
Component: component,
}
zaplog.Initialize(ctx, loggerCfg)
ipamPlugin, err := ipam.NewPlugin(name, &config)
if err != nil {
fmt.Printf("Failed to create IPAM plugin, err:%v.\n", err)
os.Exit(1)
}
if err := ipamPlugin.Plugin.InitializeKeyValueStore(&config); err != nil {
fmt.Printf("Failed to initialize key-value store of ipam plugin, err:%v.\n", err)
os.Exit(1)
}
defer func() {
if errUninit := ipamPlugin.Plugin.UninitializeKeyValueStore(); errUninit != nil {
fmt.Printf("Failed to uninitialize key-value store of ipam plugin, err:%v.\n", errUninit)
}
if recover() != nil {
os.Exit(1)
}
}()
err = ipamPlugin.Start(&config)
if err != nil {
fmt.Printf("Failed to start IPAM plugin, err:%v.\n", err)
panic("ipam plugin fatal error")
}
err = ipamPlugin.Execute(cni.PluginApi(ipamPlugin))
ipamPlugin.Stop()
cancel()
if err != nil {
panic("ipam plugin fatal error")
}
}