@@ -9,13 +9,14 @@ import (
9
9
"strconv"
10
10
11
11
"github.com/Azure/azure-container-networking/cni"
12
+ "github.com/Azure/azure-container-networking/cni/log"
12
13
"github.com/Azure/azure-container-networking/common"
13
14
"github.com/Azure/azure-container-networking/ipam"
14
- "github.com/Azure/azure-container-networking/log"
15
15
"github.com/Azure/azure-container-networking/platform"
16
16
cniSkel "github.com/containernetworking/cni/pkg/skel"
17
17
cniTypes "github.com/containernetworking/cni/pkg/types"
18
18
cniTypesCurr "github.com/containernetworking/cni/pkg/types/100"
19
+ "go.uber.org/zap"
19
20
)
20
21
21
22
const ipamV6 = "azure-vnet-ipamv6"
@@ -61,22 +62,29 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error {
61
62
// Initialize base plugin.
62
63
err := plugin .Initialize (config )
63
64
if err != nil {
64
- log .Printf ("[cni-ipam] Failed to initialize base plugin, err:%v." , err )
65
+ log .Logger .Error ("Failed to initialize base plugin." ,
66
+ zap .Error (err ), zap .String ("component" , "cni-ipam" ))
65
67
return err
66
68
}
67
69
68
70
// Log platform information.
69
- log .Printf ("[cni-ipam] Plugin %v version %v." , plugin .Name , plugin .Version )
70
- log .Printf ("[cni-ipam] Running on %v" , platform .GetOSInfo ())
71
+ log .Logger .Info ("Plugin version." , zap .String ("name" , plugin .Name ),
72
+ zap .String ("version" , plugin .Version ),
73
+ zap .String ("component" , "cni-ipam" ))
74
+ log .Logger .Info ("Running on" ,
75
+ zap .String ("platform" , platform .GetOSInfo ()),
76
+ zap .String ("component" , "cni-ipam" ))
71
77
72
78
// Initialize address manager. rehyrdration not required on reboot for cni ipam plugin
73
79
err = plugin .am .Initialize (config , false , plugin .Options )
74
80
if err != nil {
75
- log .Printf ("[cni-ipam] Failed to initialize address manager, err:%v." , err )
81
+ log .Logger .Error ("Failed to initialize address manager" ,
82
+ zap .String ("error" , err .Error ()),
83
+ zap .String ("component" , "cni-ipam" ))
76
84
return err
77
85
}
78
86
79
- log .Printf ( "[cni-ipam] Plugin started." )
87
+ log .Logger . Info ( " Plugin started" , zap . String ( "component" , "cni-ipam" ) )
80
88
81
89
return nil
82
90
}
@@ -85,7 +93,7 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error {
85
93
func (plugin * ipamPlugin ) Stop () {
86
94
plugin .am .Uninitialize ()
87
95
plugin .Uninitialize ()
88
- log .Printf ( "[cni-ipam] Plugin stopped." )
96
+ log .Logger . Info ( " Plugin stopped" , zap . String ( "component" , "cni-ipam" ) )
89
97
}
90
98
91
99
// Configure parses and applies the given network configuration.
@@ -96,7 +104,9 @@ func (plugin *ipamPlugin) Configure(stdinData []byte) (*cni.NetworkConfig, error
96
104
return nil , err
97
105
}
98
106
99
- log .Printf ("[cni-ipam] Read network configuration %+v." , nwCfg )
107
+ log .Logger .Info ("Read network configuration" ,
108
+ zap .Any ("config" , nwCfg ),
109
+ zap .String ("component" , "cni-ipam" ))
100
110
101
111
// Apply IPAM configuration.
102
112
@@ -135,10 +145,21 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
135
145
var result * cniTypesCurr.Result
136
146
var err error
137
147
138
- log .Printf ("[cni-ipam] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}." ,
139
- args .ContainerID , args .Netns , args .IfName , args .Args , args .Path , args .StdinData )
148
+ log .Logger .Info ("Processing ADD command" ,
149
+ zap .String ("ContainerId" , args .ContainerID ),
150
+ zap .String ("Netns" , args .Netns ),
151
+ zap .String ("IfName" , args .IfName ),
152
+ zap .String ("Args" , args .Args ),
153
+ zap .String ("Path" , args .Path ),
154
+ zap .ByteString ("StdinData" , args .StdinData ),
155
+ zap .String ("component" , "cni-ipam" ))
140
156
141
- defer func () { log .Printf ("[cni-ipam] ADD command completed with result:%+v err:%v." , result , err ) }()
157
+ defer func () {
158
+ log .Logger .Info ("ADD command completed" ,
159
+ zap .Any ("result" , result ),
160
+ zap .Any ("error:" , err ),
161
+ zap .String ("component" , "cni-ipam" ))
162
+ }()
142
163
143
164
// Parse network configuration from stdin.
144
165
nwCfg , err := plugin .Configure (args .StdinData )
@@ -174,13 +195,18 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
174
195
// On failure, release the address pool.
175
196
defer func () {
176
197
if err != nil && poolID != "" {
177
- log .Printf ("[cni-ipam] Releasing pool %v." , poolID )
198
+ log .Logger .Info ("Releasing pool" ,
199
+ zap .String ("poolId" , poolID ),
200
+ zap .String ("component" , "cni-ipam" ))
178
201
_ = plugin .am .ReleasePool (nwCfg .IPAM .AddrSpace , poolID )
179
202
}
180
203
}()
181
204
182
205
nwCfg .IPAM .Subnet = subnet
183
- log .Printf ("[cni-ipam] Allocated address poolID %v with subnet %v." , poolID , subnet )
206
+ log .Logger .Info ("Allocated address with subnet" ,
207
+ zap .String ("poolId" , poolID ),
208
+ zap .String ("subnet" , subnet ),
209
+ zap .String ("component" , "cni-ipam" ))
184
210
}
185
211
186
212
// Allocate an address for the endpoint.
@@ -193,12 +219,16 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
193
219
// On failure, release the address.
194
220
defer func () {
195
221
if err != nil && address != "" {
196
- log .Printf ("[cni-ipam] Releasing address %v." , address )
222
+ log .Logger .Info ("Releasing address" ,
223
+ zap .String ("address" , address ),
224
+ zap .String ("component" , "cni-ipam" ))
197
225
_ = plugin .am .ReleaseAddress (nwCfg .IPAM .AddrSpace , nwCfg .IPAM .Subnet , address , options )
198
226
}
199
227
}()
200
228
201
- log .Printf ("[cni-ipam] Allocated address %v." , address )
229
+ log .Logger .Info ("Allocated address" ,
230
+ zap .String ("address" , address ),
231
+ zap .String ("component" , "cni-ipam" ))
202
232
203
233
// Parse IP address.
204
234
ipAddress , err := platform .ConvertStringToIPNet (address )
@@ -263,10 +293,18 @@ func (plugin *ipamPlugin) Get(args *cniSkel.CmdArgs) error {
263
293
func (plugin * ipamPlugin ) Delete (args * cniSkel.CmdArgs ) error {
264
294
var err error
265
295
266
- log .Printf ("[cni-ipam] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}." ,
267
- args .ContainerID , args .Netns , args .IfName , args .Args , args .Path , args .StdinData )
296
+ log .Logger .Info ("[cni-ipam] Processing DEL command" ,
297
+ zap .String ("ContainerId" , args .ContainerID ),
298
+ zap .String ("Netns" , args .Netns ),
299
+ zap .String ("IfName" , args .IfName ),
300
+ zap .String ("Args" , args .Args ),
301
+ zap .String ("Path" , args .Path ),
302
+ zap .ByteString ("StdinData" , args .StdinData ))
268
303
269
- defer func () { log .Printf ("[cni-ipam] DEL command completed with err:%v." , err ) }()
304
+ defer func () {
305
+ log .Logger .Info ("[cni-ipam] DEL command completed" ,
306
+ zap .Error (err ))
307
+ }()
270
308
271
309
// Parse network configuration from stdin.
272
310
nwCfg , err := plugin .Configure (args .StdinData )
0 commit comments