@@ -186,6 +186,8 @@ TODO: could use one grep call instead of separate calls for getting jump line nu
186
186
- would use a grep pattern like so: <line num...AZURE-NPM>|<Chain AZURE-NPM>
187
187
*/
188
188
func (pMgr * PolicyManager ) bootup (_ []string ) error {
189
+ klog .Infof ("booting up iptables Azure chains" )
190
+
189
191
// 0.1. Detect iptables version
190
192
if err := pMgr .detectIptablesVersion (); err != nil {
191
193
return npmerrors .SimpleErrorWrapper ("failed to detect iptables version" , err )
@@ -212,6 +214,7 @@ func (pMgr *PolicyManager) bootupAfterDetectAndCleanup() error {
212
214
// 1. delete the deprecated jump to AZURE-NPM
213
215
deprecatedErrCode , deprecatedErr := pMgr .ignoreErrorsAndRunIPTablesCommand (removeDeprecatedJumpIgnoredErrors , util .IptablesDeletionFlag , deprecatedJumpFromForwardToAzureChainArgs ... )
214
216
if deprecatedErrCode == 0 {
217
+ klog .Infof ("deleted deprecated jump rule from FORWARD chain to AZURE-NPM chain" )
215
218
} else if deprecatedErr != nil {
216
219
metrics .SendErrorLogAndMetric (util .IptmID ,
217
220
"failed to delete deprecated jump rule from FORWARD chain to AZURE-NPM chain for unexpected reason with exit code %d and error: %s" ,
@@ -223,6 +226,8 @@ func (pMgr *PolicyManager) bootupAfterDetectAndCleanup() error {
223
226
return npmerrors .SimpleErrorWrapper ("failed to get current chains for bootup" , err )
224
227
}
225
228
229
+ klog .Infof ("found %d current chains in the default iptables" , len (currentChains ))
230
+
226
231
// 2. cleanup old NPM chains, and configure base chains and their rules.
227
232
creator := pMgr .creatorForBootup (currentChains )
228
233
if err := restore (creator ); err != nil {
@@ -245,11 +250,13 @@ func (pMgr *PolicyManager) bootupAfterDetectAndCleanup() error {
245
250
// kube-proxy creates an iptables chain as a hint for which version it uses.
246
251
// For more details, see: https://kubernetes.io/blog/2022/09/07/iptables-chains-not-api/#use-case-iptables-mode
247
252
func (pMgr * PolicyManager ) detectIptablesVersion () error {
253
+ klog .Info ("first attempt detecting iptables version. looking for hint/canary chain in iptables-nft" )
248
254
if pMgr .hintOrCanaryChainExist (util .IptablesNft ) {
249
255
util .SetIptablesToNft ()
250
256
return nil
251
257
}
252
258
259
+ klog .Info ("second attempt detecting iptables version. looking for hint/canary chain in iptables-legacy" )
253
260
if pMgr .hintOrCanaryChainExist (util .IptablesLegacy ) {
254
261
util .SetIptablesToLegacy ()
255
262
return nil
@@ -291,15 +298,19 @@ func (pMgr *PolicyManager) hintOrCanaryChainExist(iptablesCmd string) bool {
291
298
func (pMgr * PolicyManager ) cleanupOtherIptables () error {
292
299
hadNFT := util .Iptables == util .IptablesNft
293
300
if hadNFT {
301
+ klog .Info ("detected nft iptables. cleaning up legacy iptables" )
294
302
util .SetIptablesToLegacy ()
295
303
} else {
304
+ klog .Info ("detected legacy iptables. cleaning up nft iptables" )
296
305
util .SetIptablesToNft ()
297
306
}
298
307
299
308
defer func () {
300
309
if hadNFT {
310
+ klog .Info ("cleaned up legacy iptables" )
301
311
util .SetIptablesToNft ()
302
312
} else {
313
+ klog .Info ("cleaned up nft tables" )
303
314
util .SetIptablesToLegacy ()
304
315
}
305
316
}()
@@ -309,6 +320,7 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
309
320
// 1.1. delete the deprecated jump to AZURE-NPM
310
321
errCode , err := pMgr .ignoreErrorsAndRunIPTablesCommand (removeDeprecatedJumpIgnoredErrors , util .IptablesDeletionFlag , deprecatedJumpFromForwardToAzureChainArgs ... )
311
322
if errCode == 0 {
323
+ klog .Infof ("[cleanup] deleted deprecated jump rule from FORWARD chain to AZURE-NPM chain" )
312
324
deletedJumpRule = true
313
325
} else if err != nil {
314
326
metrics .SendErrorLogAndMetric (util .IptmID ,
@@ -320,6 +332,7 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
320
332
errCode , err = pMgr .ignoreErrorsAndRunIPTablesCommand (removeDeprecatedJumpIgnoredErrors , util .IptablesDeletionFlag , jumpFromForwardToAzureChainArgs ... )
321
333
if errCode == 0 {
322
334
deletedJumpRule = true
335
+ klog .Infof ("[cleanup] deleted jump rule from FORWARD chain to AZURE-NPM chain" )
323
336
} else if err != nil {
324
337
metrics .SendErrorLogAndMetric (util .IptmID ,
325
338
"[cleanup] failed to delete jump rule from FORWARD chain to AZURE-NPM chain for unexpected reason with exit code %d and error: %s" ,
@@ -333,9 +346,12 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
333
346
}
334
347
335
348
if len (currentChains ) == 0 {
349
+ klog .Info ("no chains to cleanup" )
336
350
return nil
337
351
}
338
352
353
+ klog .Infof ("[cleanup] %d chains to clean up" , len (currentChains ))
354
+
339
355
// 3.1. try to flush all chains at once
340
356
chains := make ([]string , 0 , len (currentChains ))
341
357
_ , hasAzureChain := currentChains [util .IptablesAzureChain ]
@@ -453,6 +469,7 @@ func (pMgr *PolicyManager) reconcile() {
453
469
return
454
470
}
455
471
472
+ klog .Infof ("cleaning up these stale chains: %+v" , staleChains )
456
473
if err := pMgr .cleanupChains (staleChains ); err != nil {
457
474
msg := fmt .Sprintf ("failed to clean up old policy chains with the following error: %s" , err .Error ())
458
475
metrics .SendErrorLogAndMetric (util .IptmID , "error: %s" , msg )
@@ -503,6 +520,8 @@ func (pMgr *PolicyManager) ignoreErrorsAndRunIPTablesCommand(ignored []*exitErro
503
520
allArgs := []string {util .IptablesWaitFlag , util .IptablesDefaultWaitTime , operationFlag }
504
521
allArgs = append (allArgs , args ... )
505
522
523
+ klog .Infof ("executing iptables command [%s] with args %v" , util .Iptables , allArgs )
524
+
506
525
command := pMgr .ioShim .Exec .Command (util .Iptables , allArgs ... )
507
526
output , err := command .CombinedOutput ()
508
527
0 commit comments