@@ -4,22 +4,21 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
- "github.com/Azure/azure-container-networking/cni/log"
8
- "go.uber.org/zap"
9
7
"net"
10
8
11
9
"github.com/Azure/azure-container-networking/cni"
10
+ "github.com/Azure/azure-container-networking/cni/log"
12
11
"github.com/Azure/azure-container-networking/cni/util"
13
12
"github.com/Azure/azure-container-networking/cns"
14
13
cnscli "github.com/Azure/azure-container-networking/cns/client"
15
14
"github.com/Azure/azure-container-networking/iptables"
16
- "github.com/Azure/azure-container-networking/log"
17
15
"github.com/Azure/azure-container-networking/network"
18
16
"github.com/Azure/azure-container-networking/network/networkutils"
19
17
cniSkel "github.com/containernetworking/cni/pkg/skel"
20
18
cniTypes "github.com/containernetworking/cni/pkg/types"
21
19
cniTypesCurr "github.com/containernetworking/cni/pkg/types/100"
22
20
"github.com/pkg/errors"
21
+ "go.uber.org/zap"
23
22
)
24
23
25
24
var (
@@ -82,11 +81,13 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
82
81
83
82
log .Logger .Info ("Requesting IP for pod using ipconfig" ,
84
83
zap .Any ("pod" , podInfo ),
85
- zap .Any ("ipconfig" , ipconfig ))
84
+ zap .Any ("ipconfig" , ipconfigs ))
85
+ response , err := invoker .cnsClient .RequestIPs (context .TODO (), ipconfigs )
86
86
if err != nil {
87
87
if cnscli .IsUnsupportedAPI (err ) {
88
88
// If RequestIPs is not supported by CNS, use RequestIPAddress API
89
- log .Errorf ("RequestIPs not supported by CNS. Invoking RequestIPAddress API with infracontainerid %s" , ipconfigs .InfraContainerID )
89
+ log .Logger .Error ("RequestIPs not supported by CNS. Invoking RequestIPAddress API" ,
90
+ zap .Any ("infracontainerid" , ipconfigs .InfraContainerID ))
90
91
ipconfig := cns.IPConfigRequest {
91
92
OrchestratorContext : orchestratorContext ,
92
93
PodInterfaceID : GetEndpointID (addConfig .args ),
@@ -96,7 +97,9 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
96
97
res , errRequestIP := invoker .cnsClient .RequestIPAddress (context .TODO (), ipconfig )
97
98
if errRequestIP != nil {
98
99
// if the old API fails as well then we just return the error
99
- log .Errorf ("Failed to request IP address from CNS using RequestIPAddress with infracontainerid %s. error: %v" , ipconfig .InfraContainerID , errRequestIP )
100
+ log .Logger .Error ("Failed to request IP address from CNS using RequestIPAddress" ,
101
+ zap .Any ("infracontainerid" , ipconfig .InfraContainerID ),
102
+ zap .Any ("error" , errRequestIP ))
100
103
return IPAMAddResult {}, errors .Wrap (errRequestIP , "Failed to get IP address from CNS" )
101
104
}
102
105
response = & cns.IPConfigsResponse {
@@ -106,7 +109,9 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
106
109
},
107
110
}
108
111
} else {
109
- log .Printf ("Failed to get IP address from CNS with error %v, response: %v" , err , response )
112
+ log .Logger .Info ("Failed to get IP address from CNS" ,
113
+ zap .Any ("error" , err ),
114
+ zap .Any ("response" , response ))
110
115
return IPAMAddResult {}, errors .Wrap (err , "Failed to get IP address from CNS" )
111
116
}
112
117
}
@@ -299,7 +304,9 @@ func (invoker *CNSIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConf
299
304
if err := invoker .cnsClient .ReleaseIPs (context .TODO (), ipConfigs ); err != nil {
300
305
if cnscli .IsUnsupportedAPI (err ) {
301
306
// If ReleaseIPs is not supported by CNS, use ReleaseIPAddress API
302
- log .Errorf ("ReleaseIPs not supported by CNS. Invoking ReleaseIPAddress API. Request: %v" , ipConfigs )
307
+ log .Logger .Error ("ReleaseIPs not supported by CNS. Invoking ReleaseIPAddress API" ,
308
+ zap .Any ("ipconfigs" , ipConfigs ))
309
+
303
310
ipConfig := cns.IPConfigRequest {
304
311
OrchestratorContext : orchestratorContext ,
305
312
PodInterfaceID : GetEndpointID (args ),
@@ -308,11 +315,15 @@ func (invoker *CNSIPAMInvoker) Delete(address *net.IPNet, nwCfg *cni.NetworkConf
308
315
309
316
if err = invoker .cnsClient .ReleaseIPAddress (context .TODO (), ipConfig ); err != nil {
310
317
// if the old API fails as well then we just return the error
311
- log .Errorf ("Failed to release IP address from CNS using ReleaseIPAddress with infracontainerid %s. error: %v" , ipConfigs .InfraContainerID , err )
318
+ log .Logger .Error ("Failed to release IP address from CNS using ReleaseIPAddress " ,
319
+ zap .Any ("infracontainerid" , ipConfigs .InfraContainerID ),
320
+ zap .Any ("error" , err ))
312
321
return errors .Wrap (err , fmt .Sprintf ("failed to release IP %v using ReleaseIPAddress with err " , ipConfig .DesiredIPAddress )+ "%w" )
313
322
}
314
323
} else {
315
- log .Errorf ("Failed to release IP address with infracontainerid %s from CNS error: %v" , ipConfigs .InfraContainerID , err )
324
+ log .Logger .Error ("Failed to release IP address" ,
325
+ zap .Any ("infracontainerid" , ipConfigs .InfraContainerID ),
326
+ zap .Any ("error" , err ))
316
327
return errors .Wrap (err , fmt .Sprintf ("failed to release IP %v using ReleaseIPs with err " , ipConfigs .DesiredIPAddresses )+ "%w" )
317
328
}
318
329
}
0 commit comments