Skip to content

Commit 08697eb

Browse files
committed
test remove dataplane changes to see if race condition fixes
1 parent cf04343 commit 08697eb

File tree

5 files changed

+83
-127
lines changed

5 files changed

+83
-127
lines changed

Diff for: npm/pkg/dataplane/dataplane.go

+28-55
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ type DataPlane struct {
8181
func NewDataPlane(nodeName string, ioShim *common.IOShim, cfg *Config, stopChannel <-chan struct{}) (*DataPlane, error) {
8282
metrics.InitializeAll()
8383
if util.IsWindowsDP() {
84-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
85-
// klog.Infof("[DataPlane] enabling AddEmptySetToLists for Windows")
84+
klog.Infof("[DataPlane] enabling AddEmptySetToLists for Windows")
8685
cfg.IPSetManagerCfg.AddEmptySetToLists = true
8786
}
8887

@@ -113,8 +112,7 @@ func NewDataPlane(nodeName string, ioShim *common.IOShim, cfg *Config, stopChann
113112
return nil, ErrInvalidApplyConfig
114113
}
115114
} else {
116-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
117-
// klog.Info("[DataPlane] dataplane configured to NOT apply in background")
115+
klog.Info("[DataPlane] dataplane configured to NOT apply in background")
118116
dp.updatePodCache = newUpdatePodCache(1)
119117
}
120118

@@ -152,8 +150,7 @@ func (dp *DataPlane) FinishBootupPhase() {
152150
dp.applyInfo.Lock()
153151
defer dp.applyInfo.Unlock()
154152

155-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
156-
// klog.Infof("[DataPlane] finished bootup phase")
153+
klog.Infof("[DataPlane] finished bootup phase")
157154
dp.applyInfo.inBootupPhase = false
158155
}
159156

@@ -260,8 +257,7 @@ func (dp *DataPlane) AddToSets(setNames []*ipsets.IPSetMetadata, podMetadata *Po
260257
}
261258

262259
if dp.shouldUpdatePod() && podMetadata.NodeName == dp.nodeName {
263-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
264-
// klog.Infof("[DataPlane] Updating Sets to Add for pod key %s", podMetadata.PodKey)
260+
klog.Infof("[DataPlane] Updating Sets to Add for pod key %s", podMetadata.PodKey)
265261

266262
// lock updatePodCache while reading/modifying or setting the updatePod in the cache
267263
dp.updatePodCache.Lock()
@@ -283,8 +279,7 @@ func (dp *DataPlane) RemoveFromSets(setNames []*ipsets.IPSetMetadata, podMetadat
283279
}
284280

285281
if dp.shouldUpdatePod() && podMetadata.NodeName == dp.nodeName {
286-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
287-
// klog.Infof("[DataPlane] Updating Sets to Remove for pod key %s", podMetadata.PodKey)
282+
klog.Infof("[DataPlane] Updating Sets to Remove for pod key %s", podMetadata.PodKey)
288283

289284
// lock updatePodCache while reading/modifying or setting the updatePod in the cache
290285
dp.updatePodCache.Lock()
@@ -333,27 +328,23 @@ func (dp *DataPlane) ApplyDataPlane() error {
333328
newCount := dp.applyInfo.numBatches
334329
dp.applyInfo.Unlock()
335330

336-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
337-
// klog.Infof("[DataPlane] [%s] new batch count: %d", contextApplyDP, newCount)
331+
klog.Infof("[DataPlane] [%s] new batch count: %d", contextApplyDP, newCount)
338332

339333
if newCount >= dp.ApplyMaxBatches {
340-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
341-
// klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextApplyDP, newCount)
334+
klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextApplyDP, newCount)
342335
return dp.applyDataPlaneNow(contextApplyDP)
343336
}
344337

345338
return nil
346339
}
347340

348341
func (dp *DataPlane) applyDataPlaneNow(context string) error {
349-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
350-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] starting to apply ipsets", context)
342+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] starting to apply ipsets", context)
351343
err := dp.ipsetMgr.ApplyIPSets()
352344
if err != nil {
353345
return fmt.Errorf("[DataPlane] [%s] error while applying IPSets: %w", context, err)
354346
}
355-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
356-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] finished applying ipsets", context)
347+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] finished applying ipsets", context)
357348

358349
// see comment in RemovePolicy() for why this is here
359350
dp.setRemovePolicyFailure(false)
@@ -374,8 +365,7 @@ func (dp *DataPlane) applyDataPlaneNow(context string) error {
374365
}
375366
dp.updatePodCache.Unlock()
376367

377-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
378-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] refreshing endpoints before updating pods", context)
368+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] refreshing endpoints before updating pods", context)
379369

380370
err := dp.refreshPodEndpoints()
381371
if err != nil {
@@ -384,16 +374,14 @@ func (dp *DataPlane) applyDataPlaneNow(context string) error {
384374
return nil
385375
}
386376

387-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
388-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] refreshed endpoints", context)
377+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] refreshed endpoints", context)
389378

390379
// lock updatePodCache while driving goal state to kernel
391380
// prevents another ApplyDataplane call from updating the same pods
392381
dp.updatePodCache.Lock()
393382
defer dp.updatePodCache.Unlock()
394383

395-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
396-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] starting to update pods", context)
384+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] starting to update pods", context)
397385
for !dp.updatePodCache.isEmpty() {
398386
pod := dp.updatePodCache.dequeue()
399387
if pod == nil {
@@ -411,16 +399,14 @@ func (dp *DataPlane) applyDataPlaneNow(context string) error {
411399
}
412400
}
413401

414-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
415-
// klog.Infof("[DataPlane] [ApplyDataPlane] [%s] finished updating pods", context)
402+
klog.Infof("[DataPlane] [ApplyDataPlane] [%s] finished updating pods", context)
416403
}
417404
return nil
418405
}
419406

420407
// AddPolicy takes in a translated NPMNetworkPolicy object and applies on dataplane
421408
func (dp *DataPlane) AddPolicy(policy *policies.NPMNetworkPolicy) error {
422-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
423-
// klog.Infof("[DataPlane] Add Policy called for %s", policy.PolicyKey)
409+
klog.Infof("[DataPlane] Add Policy called for %s", policy.PolicyKey)
424410

425411
if !dp.netPolInBackground {
426412
return dp.addPolicies([]*policies.NPMNetworkPolicy{policy})
@@ -434,12 +420,10 @@ func (dp *DataPlane) AddPolicy(policy *policies.NPMNetworkPolicy) error {
434420
dp.netPolQueue.enqueue(policy)
435421
newCount := dp.netPolQueue.len()
436422

437-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
438-
// klog.Infof("[DataPlane] [%s] new pending netpol count: %d", contextAddNetPol, newCount)
423+
klog.Infof("[DataPlane] [%s] new pending netpol count: %d", contextAddNetPol, newCount)
439424

440425
if newCount >= dp.MaxPendingNetPols {
441-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
442-
// klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextAddNetPol, newCount)
426+
klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextAddNetPol, newCount)
443427
dp.addPoliciesWithRetry(contextAddNetPol)
444428
}
445429
return nil
@@ -449,14 +433,12 @@ func (dp *DataPlane) AddPolicy(policy *policies.NPMNetworkPolicy) error {
449433
// The caller must lock netPolQueue.
450434
func (dp *DataPlane) addPoliciesWithRetry(context string) {
451435
netPols := dp.netPolQueue.dump()
452-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
453-
// klog.Infof("[DataPlane] adding policies %+v", netPols)
436+
klog.Infof("[DataPlane] adding policies %+v", netPols)
454437

455438
err := dp.addPolicies(netPols)
456439
if err == nil {
457440
// clear queue and return on success
458-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
459-
// klog.Infof("[DataPlane] [%s] added policies successfully", context)
441+
klog.Infof("[DataPlane] [%s] added policies successfully", context)
460442
dp.netPolQueue.clear()
461443
return
462444
}
@@ -469,8 +451,7 @@ func (dp *DataPlane) addPoliciesWithRetry(context string) {
469451
err = dp.addPolicies([]*policies.NPMNetworkPolicy{netPol})
470452
if err == nil {
471453
// remove from queue on success
472-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
473-
// klog.Infof("[DataPlane] [%s] added policy successfully one at a time. policyKey: %s", context, netPol.PolicyKey)
454+
klog.Infof("[DataPlane] [%s] added policy successfully one at a time. policyKey: %s", context, netPol.PolicyKey)
474455
dp.netPolQueue.delete(netPol.PolicyKey)
475456
} else {
476457
// keep in queue on failure
@@ -488,8 +469,7 @@ func (dp *DataPlane) addPolicies(netPols []*policies.NPMNetworkPolicy) error {
488469
}
489470

490471
if len(netPols) == 0 {
491-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
492-
// klog.Infof("[DataPlane] expected to have at least one NetPol in dp.addPolicies()")
472+
klog.Infof("[DataPlane] expected to have at least one NetPol in dp.addPolicies()")
493473
return nil
494474
}
495475

@@ -533,8 +513,7 @@ func (dp *DataPlane) addPolicies(netPols []*policies.NPMNetworkPolicy) error {
533513
// Create and add references for Rule IPSets
534514
err = dp.createIPSetsAndReferences(netPol.RuleIPSets, netPol.PolicyKey, ipsets.NetPolType)
535515
if err != nil {
536-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
537-
// klog.Infof("[DataPlane] error while adding Rule IPSet references: %s", err.Error())
516+
klog.Infof("[DataPlane] error while adding Rule IPSet references: %s", err.Error())
538517
return fmt.Errorf("[DataPlane] error while adding Rule IPSet references: %w", err)
539518
}
540519

@@ -547,18 +526,15 @@ func (dp *DataPlane) addPolicies(netPols []*policies.NPMNetworkPolicy) error {
547526
// increment batch and apply IPSets if needed
548527
dp.applyInfo.numBatches++
549528
newCount := dp.applyInfo.numBatches
550-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
551-
// klog.Infof("[DataPlane] [%s] new batch count: %d", contextAddNetPolBootup, newCount)
529+
klog.Infof("[DataPlane] [%s] new batch count: %d", contextAddNetPolBootup, newCount)
552530
if newCount >= dp.ApplyMaxBatches {
553-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
554-
// klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextAddNetPolBootup, newCount)
555-
// klog.Infof("[DataPlane] [%s] starting to apply ipsets", contextAddNetPolBootup)
531+
klog.Infof("[DataPlane] [%s] applying now since reached maximum batch count: %d", contextAddNetPolBootup, newCount)
532+
klog.Infof("[DataPlane] [%s] starting to apply ipsets", contextAddNetPolBootup)
556533
err = dp.ipsetMgr.ApplyIPSets()
557534
if err != nil {
558535
return fmt.Errorf("[DataPlane] [%s] error while applying IPSets: %w", contextAddNetPolBootup, err)
559536
}
560-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
561-
// klog.Infof("[DataPlane] [%s] finished applying ipsets", contextAddNetPolBootup)
537+
klog.Infof("[DataPlane] [%s] finished applying ipsets", contextAddNetPolBootup)
562538

563539
// see comment in RemovePolicy() for why this is here
564540
dp.setRemovePolicyFailure(false)
@@ -598,8 +574,7 @@ func (dp *DataPlane) addPolicies(netPols []*policies.NPMNetworkPolicy) error {
598574

599575
// RemovePolicy takes in network policyKey (namespace/name of network policy) and removes it from dataplane and cache
600576
func (dp *DataPlane) RemovePolicy(policyKey string) error {
601-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
602-
// klog.Infof("[DataPlane] Remove Policy called for %s", policyKey)
577+
klog.Infof("[DataPlane] Remove Policy called for %s", policyKey)
603578

604579
if dp.netPolInBackground {
605580
// make sure to not add this NetPol if we're deleting it
@@ -675,12 +650,10 @@ func (dp *DataPlane) RemovePolicy(policyKey string) error {
675650
// UpdatePolicy takes in updated policy object, calculates the delta and applies changes
676651
// onto dataplane accordingly
677652
func (dp *DataPlane) UpdatePolicy(policy *policies.NPMNetworkPolicy) error {
678-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
679-
// klog.Infof("[DataPlane] Update Policy called for %s", policy.PolicyKey)
653+
klog.Infof("[DataPlane] Update Policy called for %s", policy.PolicyKey)
680654
ok := dp.policyMgr.PolicyExists(policy.PolicyKey)
681655
if !ok {
682-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
683-
// klog.Infof("[DataPlane] Policy %s is not found.", policy.PolicyKey)
656+
klog.Infof("[DataPlane] Policy %s is not found.", policy.PolicyKey)
684657
return dp.AddPolicy(policy)
685658
}
686659

Diff for: npm/pkg/dataplane/dataplane_linux_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ func TestNetPolInBackgroundUpdatePolicy(t *testing.T) {
9494
}
9595

9696
func TestNetPolInBackgroundSkipAddAfterRemove(t *testing.T) {
97-
// Sleep for a bit to let IncNumACLRulesBy be resolved to avoid race condition
98-
time.Sleep(100 * time.Millisecond)
9997
metrics.ReinitializeAll()
10098

10199
calls := getBootupTestCalls()

Diff for: npm/pkg/dataplane/ipsets/ipsetmanager.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (iMgr *IPSetManager) Reconcile() {
9393
}
9494
numRemovedSets := originalNumSets - len(iMgr.setMap)
9595
if numRemovedSets > 0 {
96-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
97-
// klog.Infof("[IPSetManager] removed %d empty/unreferenced ipsets, updating toDeleteCache to: %+v", numRemovedSets, iMgr.dirtyCache.printDeleteCache())
96+
klog.Infof("[IPSetManager] removed %d empty/unreferenced ipsets, updating toDeleteCache to: %+v", numRemovedSets, iMgr.dirtyCache.printDeleteCache())
9897
}
9998
}
10099

@@ -309,11 +308,10 @@ func (iMgr *IPSetManager) RemoveFromSets(removeFromSets []*IPSetMetadata, ip, po
309308
}
310309
// in case the IP belongs to a new Pod, then ignore this Delete call as this might be stale
311310
if cachedPodKey != podKey {
312-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
313-
// klog.Infof(
314-
// "[IPSetManager] DeleteFromSet: PodOwner has changed for Ip: %s, setName:%s, Old podKey: %s, new podKey: %s. Ignore the delete as this is stale update",
315-
// ip, prefixedName, cachedPodKey, podKey,
316-
// )
311+
klog.Infof(
312+
"[IPSetManager] DeleteFromSet: PodOwner has changed for Ip: %s, setName:%s, Old podKey: %s, new podKey: %s. Ignore the delete as this is stale update",
313+
ip, prefixedName, cachedPodKey, podKey,
314+
)
317315
continue
318316
}
319317

@@ -455,16 +453,14 @@ func (iMgr *IPSetManager) ApplyIPSets() error {
455453
defer iMgr.Unlock()
456454

457455
if iMgr.dirtyCache.numSetsToAddOrUpdate() == 0 && iMgr.dirtyCache.numSetsToDelete() == 0 {
458-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
459-
// klog.Info("[IPSetManager] No IPSets to apply")
456+
klog.Info("[IPSetManager] No IPSets to apply")
460457
return nil
461458
}
462459

463-
// TODO: Refactor non-error/warning klogs with Zap and set the following logs to "debug" level
464-
// klog.Infof(
465-
// "[IPSetManager] dirty caches. toAddUpdateCache: %s, toDeleteCache: %s",
466-
// iMgr.dirtyCache.printAddOrUpdateCache(), iMgr.dirtyCache.printDeleteCache(),
467-
// )
460+
klog.Infof(
461+
"[IPSetManager] dirty caches. toAddUpdateCache: %s, toDeleteCache: %s",
462+
iMgr.dirtyCache.printAddOrUpdateCache(), iMgr.dirtyCache.printDeleteCache(),
463+
)
468464
iMgr.sanitizeDirtyCache()
469465

470466
// Call the appropriate apply ipsets

0 commit comments

Comments
 (0)