Skip to content

Commit aa163aa

Browse files
perf: [WIN-NPM] apply ipsets in background (#1875)
* wip * fix UT by applying dataplane immediately for RemovePolicy() * configmap options for apply in background * fix deadlocks * better logging * rename config variables, update default config, change shouldApply check * update configmap values * FIXME: remove tmp commit overriding applyDP config (using for pipeline tests) * optimize applying ipsets for add policy * cleanup code and finalize apply ipsets for netpols * flip order of if statement * UTs. address comments. fix netpol behavior by waiting to start pod controller * all UTs except ones related to issue #1729 * remove bootup phase stuff * fix lints and move applyinbackground to toggle * fix lint * don't check isWindows every time * use diff var for applyinbackground * fix lint
1 parent 3f1c159 commit aa163aa

File tree

8 files changed

+230
-51
lines changed

8 files changed

+230
-51
lines changed

npm/azure-npm.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ data:
151151
"ResyncPeriodInMinutes": 15,
152152
"ListeningPort": 10091,
153153
"ListeningAddress": "0.0.0.0",
154+
"ApplyMaxBatches": 100,
155+
"ApplyIntervalInMilliseconds": 500,
154156
"Toggles": {
155157
"EnablePrometheusMetrics": true,
156158
"EnablePprof": true,
157159
"EnableHTTPDebugAPI": true,
158160
"EnableV2NPM": true,
159-
"PlaceAzureChainFirst": true
161+
"PlaceAzureChainFirst": true,
162+
"ApplyIPSetsOnNeed": false,
163+
"ApplyInBackground": true
160164
}
161165
}

npm/cmd/start.go

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ func start(config npmconfig.Config, flags npmconfig.Flags) error {
123123
stopChannel := wait.NeverStop
124124
if config.Toggles.EnableV2NPM {
125125
// update the dataplane config
126+
npmV2DataplaneCfg.ApplyInBackground = config.Toggles.ApplyInBackground
127+
if config.ApplyMaxBatches > 0 {
128+
npmV2DataplaneCfg.ApplyMaxBatches = config.ApplyMaxBatches
129+
} else {
130+
npmV2DataplaneCfg.ApplyMaxBatches = npmconfig.DefaultConfig.ApplyMaxBatches
131+
}
132+
if config.ApplyIntervalInMilliseconds > 0 {
133+
npmV2DataplaneCfg.ApplyInterval = time.Duration(config.ApplyIntervalInMilliseconds * int(time.Millisecond))
134+
} else {
135+
npmV2DataplaneCfg.ApplyInterval = time.Duration(npmconfig.DefaultConfig.ApplyIntervalInMilliseconds * int(time.Millisecond))
136+
}
137+
126138
if config.WindowsNetworkName == "" {
127139
npmV2DataplaneCfg.NetworkName = util.AzureNetworkName
128140
} else {

npm/config/config.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import "github.com/Azure/azure-container-networking/npm/util"
44

55
const (
66
defaultResyncPeriod = 15
7+
defaultApplyMaxBatches = 100
8+
defaultApplyInterval = 500
79
defaultListeningPort = 10091
810
defaultGrpcPort = 10092
911
defaultGrpcServicePort = 9002
@@ -16,7 +18,6 @@ const (
1618

1719
// DefaultConfig is the guaranteed configuration NPM can run in out of the box
1820
var DefaultConfig = Config{
19-
WindowsNetworkName: util.AzureNetworkName,
2021
ResyncPeriodInMinutes: defaultResyncPeriod,
2122

2223
ListeningPort: defaultListeningPort,
@@ -28,13 +29,18 @@ var DefaultConfig = Config{
2829
ServicePort: defaultGrpcServicePort,
2930
},
3031

32+
WindowsNetworkName: util.AzureNetworkName,
33+
ApplyMaxBatches: defaultApplyMaxBatches,
34+
ApplyIntervalInMilliseconds: defaultApplyInterval,
35+
3136
Toggles: Toggles{
3237
EnablePrometheusMetrics: true,
3338
EnablePprof: true,
3439
EnableHTTPDebugAPI: true,
3540
EnableV2NPM: true,
3641
PlaceAzureChainFirst: util.PlaceAzureChainFirst,
3742
ApplyIPSetsOnNeed: false,
43+
ApplyInBackground: true,
3844
},
3945
}
4046

@@ -48,14 +54,17 @@ type GrpcServerConfig struct {
4854
}
4955

5056
type Config struct {
51-
// WindowsNetworkName can be either 'azure' or 'Calico' (case sensitive).
52-
// It can also be the empty string, which results in the default value of 'azure'.
53-
WindowsNetworkName string `json:"WindowsNetworkName,omitempty"`
5457
ResyncPeriodInMinutes int `json:"ResyncPeriodInMinutes,omitempty"`
5558
ListeningPort int `json:"ListeningPort,omitempty"`
5659
ListeningAddress string `json:"ListeningAddress,omitempty"`
5760
Transport GrpcServerConfig `json:"Transport,omitempty"`
58-
Toggles Toggles `json:"Toggles,omitempty"`
61+
// WindowsNetworkName can be either 'azure' or 'Calico' (case sensitive).
62+
// It can also be the empty string, which results in the default value of 'azure'.
63+
WindowsNetworkName string `json:"WindowsNetworkName,omitempty"`
64+
// Apply options for Windows only. Relevant when ApplyInBackground is true.
65+
ApplyMaxBatches int `json:"ApplyDataPlaneMaxBatches,omitempty"`
66+
ApplyIntervalInMilliseconds int `json:"ApplyDataPlaneMaxWaitInMilliseconds,omitempty"`
67+
Toggles Toggles `json:"Toggles,omitempty"`
5968
}
6069

6170
type Toggles struct {
@@ -65,6 +74,8 @@ type Toggles struct {
6574
EnableV2NPM bool
6675
PlaceAzureChainFirst bool
6776
ApplyIPSetsOnNeed bool
77+
// ApplyInBackground applies for Windows only
78+
ApplyInBackground bool
6879
}
6980

7081
type Flags struct {

npm/examples/windows/azure-npm.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,15 @@ data:
143143
"ResyncPeriodInMinutes": 15,
144144
"ListeningPort": 10091,
145145
"ListeningAddress": "0.0.0.0",
146+
"ApplyMaxBatches": 100,
147+
"ApplyIntervalInMilliseconds": 500,
146148
"Toggles": {
147149
"EnablePrometheusMetrics": true,
148150
"EnablePprof": true,
149151
"EnableHTTPDebugAPI": true,
150152
"EnableV2NPM": true,
151153
"PlaceAzureChainFirst": true,
152-
"ApplyIPSetsOnNeed": false
153-
},
154-
"Transport": {
155-
"Address": "azure-npm.kube-system.svc.cluster.local",
156-
"Port": 10092,
157-
"ServicePort": 9001
154+
"ApplyIPSetsOnNeed": false,
155+
"ApplyInBackground": true
158156
}
159157
}

npm/npm.go

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func (npMgr *NetworkPolicyManager) Start(config npmconfig.Config, stopCh <-chan
198198
go npMgr.PodControllerV2.Run(stopCh)
199199
go npMgr.NamespaceControllerV2.Run(stopCh)
200200
go npMgr.NetPolControllerV2.Run(stopCh)
201+
201202
return nil
202203
}
203204

npm/pkg/dataplane/dataplane-test-cases_windows_test.go

+42-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dataplane
22

33
import (
4+
"time"
5+
46
"github.com/Azure/azure-container-networking/network/hnswrapper"
57
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/ipsets"
68
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/policies"
@@ -12,11 +14,12 @@ import (
1214

1315
// tags
1416
const (
15-
podCrudTag Tag = "pod-crud"
16-
nsCrudTag Tag = "namespace-crud"
17-
netpolCrudTag Tag = "netpol-crud"
18-
reconcileTag Tag = "reconcile"
19-
calicoTag Tag = "calico"
17+
podCrudTag Tag = "pod-crud"
18+
nsCrudTag Tag = "namespace-crud"
19+
netpolCrudTag Tag = "netpol-crud"
20+
reconcileTag Tag = "reconcile"
21+
calicoTag Tag = "calico"
22+
applyInBackgroundTag Tag = "apply-in-background"
2023
)
2124

2225
const (
@@ -2255,3 +2258,37 @@ func getAllMultiJobTests() []*MultiJobTestCase {
22552258
},
22562259
}
22572260
}
2261+
2262+
func applyInBackgroundTests() []*SerialTestCase {
2263+
allTests := make([]*SerialTestCase, 0)
2264+
allTests = append(allTests, basicTests()...)
2265+
allTests = append(allTests, capzCalicoTests()...)
2266+
allTests = append(allTests, updatePodTests()...)
2267+
2268+
for _, test := range allTests {
2269+
test.TestCaseMetadata.Tags = append(test.TestCaseMetadata.Tags, applyInBackgroundTag)
2270+
cfg := *test.DpCfg
2271+
cfg.ApplyInBackground = true
2272+
cfg.ApplyMaxBatches = 3
2273+
cfg.ApplyInterval = time.Duration(50 * time.Millisecond)
2274+
test.DpCfg = &cfg
2275+
}
2276+
2277+
return allTests
2278+
}
2279+
2280+
func multiJobApplyInBackgroundTests() []*MultiJobTestCase {
2281+
allTests := make([]*MultiJobTestCase, 0)
2282+
allTests = append(allTests, getAllMultiJobTests()...)
2283+
2284+
for _, test := range allTests {
2285+
test.TestCaseMetadata.Tags = append(test.TestCaseMetadata.Tags, applyInBackgroundTag)
2286+
cfg := *test.DpCfg
2287+
cfg.ApplyInBackground = true
2288+
cfg.ApplyMaxBatches = 3
2289+
cfg.ApplyInterval = time.Duration(50 * time.Millisecond)
2290+
test.DpCfg = &cfg
2291+
}
2292+
2293+
return allTests
2294+
}

0 commit comments

Comments
 (0)