Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions npm/pkg/controlplane/controllers/v2/namespaceController.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@ func (nsc *NamespaceController) cleanDeletedNamespace(cachedNsKey string) error
return fmt.Errorf("failed to remove from list during clean deleted namespace %w", err)
}

// Delete ipset for the namespace.
nsc.dp.DeleteIPSet(ipsets.NewIPSetMetadata(cachedNsKey, ipsets.Namespace), util.SoftDelete)

delete(nsc.npmNamespaceCache.NsMap, cachedNsKey)

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ func TestDeleteNamespace(t *testing.T) {
for i := 1; i < len(setsToAddNamespaceTo); i++ {
dp.EXPECT().RemoveFromList(setsToAddNamespaceTo[i], setsToAddNamespaceTo[:1]).Return(nil).Times(1)
}
dp.EXPECT().DeleteIPSet(setsToAddNamespaceTo[0], util.SoftDelete).Return().Times(1)

deleteNamespace(t, f, nsObj, DeletedFinalStateknownObject)

Expand Down Expand Up @@ -702,7 +701,6 @@ func TestDeleteNamespaceWithTombstoneAfterAddingNameSpace(t *testing.T) {
for i := 1; i < len(setsToAddNamespaceTo); i++ {
dp.EXPECT().RemoveFromList(setsToAddNamespaceTo[i], setsToAddNamespaceTo[:1]).Return(nil).Times(1)
}
dp.EXPECT().DeleteIPSet(setsToAddNamespaceTo[0], util.SoftDelete).Return().Times(1)

deleteNamespace(t, f, nsObj, DeletedFinalStateUnknownObject)
testCases := []expectedNsValues{
Expand Down
29 changes: 25 additions & 4 deletions npm/pkg/dataplane/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dataplane

import (
"fmt"
"time"

"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/npm/metrics"
Expand All @@ -15,6 +16,8 @@ import (
const (
// AzureNetworkName is default network Azure CNI creates
AzureNetworkName = "azure"

reconcileTimeInMinutes = 5
)

type PolicyMode string
Expand Down Expand Up @@ -78,7 +81,27 @@ func (dp *DataPlane) BootupDataplane() error {

// RunPeriodicTasks runs periodic tasks. Should only be called once.
func (dp *DataPlane) RunPeriodicTasks() {
dp.policyMgr.Reconcile(dp.stopChannel)
go func() {
ticker := time.NewTicker(time.Minute * time.Duration(reconcileTimeInMinutes))
defer ticker.Stop()

for {
select {
case <-dp.stopChannel:
return
case <-ticker.C:
// send the heartbeat log in another go routine in case it takes a while
go metrics.SendHeartbeatLog()

// locks ipset manager
dp.ipsetMgr.Reconcile()

// in Windows, does nothing
// in Linux, locks policy manager but can be interrupted
dp.policyMgr.Reconcile()
}
}
}()
}

func (dp *DataPlane) GetIPSet(setName string) *ipsets.IPSet {
Expand Down Expand Up @@ -292,7 +315,7 @@ func (dp *DataPlane) createIPSetsAndReferences(sets []*ipsets.TranslatedIPSet, n
}
for _, set := range sets {
dp.ipsetMgr.CreateIPSets([]*ipsets.IPSetMetadata{set.Metadata})
err := dp.ipsetMgr.AddReference(set.Metadata.GetPrefixName(), netpolName, referenceType)
err := dp.ipsetMgr.AddReference(set.Metadata, netpolName, referenceType)
if err != nil {
return npmerrors.Errorf(npmErrorString, false, fmt.Sprintf("[DataPlane] failed to add reference with err: %s", err.Error()))
}
Expand Down Expand Up @@ -337,7 +360,6 @@ func (dp *DataPlane) deleteIPSetsAndReferences(sets []*ipsets.TranslatedIPSet, n
}
for _, set := range sets {
// TODO ignore set does not exist error
// TODO add delete ipset after removing members
err := dp.ipsetMgr.DeleteReference(set.Metadata.GetPrefixName(), netpolName, referenceType)
if err != nil {
return npmerrors.Errorf(npmErrorString, false, fmt.Sprintf("[DataPlane] failed to deleteIPSetReferences with err: %s", err.Error()))
Expand Down Expand Up @@ -371,7 +393,6 @@ func (dp *DataPlane) deleteIPSetsAndReferences(sets []*ipsets.TranslatedIPSet, n
if err != nil {
return npmerrors.Errorf(npmErrorString, false, fmt.Sprintf("[DataPlane] failed to RemoveFromList in deleteIPSetReferences with err: %s", err.Error()))
}

}

// Try to delete these IPSets
Expand Down
Loading