@@ -4089,6 +4089,12 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4089
4089
add rule ip kube-proxy endpoint-2OCDJSZQ-ns3/svc3/tcp/p80__10.0.3.1/80 meta l4proto tcp dnat to 10.0.3.1:80
4090
4090
` )
4091
4091
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4092
+ // add 1 element to cluster-ips and service-ips = 2 operations
4093
+ // add+flush 2 chains for service and endpoint, add 2 rules in each = 8 operations
4094
+ // 10 operations total.
4095
+ if nft .LastTransaction .NumOperations () != 10 {
4096
+ t .Errorf ("Expected 10 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4097
+ }
4092
4098
4093
4099
// Delete a service; its chains will be flushed, but not immediately deleted.
4094
4100
fp .OnServiceDelete (svc2 )
@@ -4117,6 +4123,12 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4117
4123
add rule ip kube-proxy endpoint-2OCDJSZQ-ns3/svc3/tcp/p80__10.0.3.1/80 meta l4proto tcp dnat to 10.0.3.1:80
4118
4124
` )
4119
4125
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4126
+ // delete 1 element from cluster-ips and service-ips = 2 operations
4127
+ // flush 2 chains for service and endpoint = 2 operations
4128
+ // 4 operations total.
4129
+ if nft .LastTransaction .NumOperations () != 4 {
4130
+ t .Errorf ("Expected 4 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4131
+ }
4120
4132
4121
4133
// Fake the passage of time and confirm that the stale chains get deleted.
4122
4134
ageStaleChains ()
@@ -4142,6 +4154,10 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4142
4154
add rule ip kube-proxy endpoint-2OCDJSZQ-ns3/svc3/tcp/p80__10.0.3.1/80 meta l4proto tcp dnat to 10.0.3.1:80
4143
4155
` )
4144
4156
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4157
+ // delete stale chains happens in a separate transaction, nothing else changed => last transaction will have 0 operations.
4158
+ if nft .LastTransaction .NumOperations () != 0 {
4159
+ t .Errorf ("Expected 0 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4160
+ }
4145
4161
4146
4162
// Add a service, sync, then add its endpoints.
4147
4163
makeServiceMap (fp ,
@@ -4180,6 +4196,10 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4180
4196
add element ip kube-proxy no-endpoint-services { 172.30.0.44 . tcp . 80 comment "ns4/svc4:p80" : goto reject-chain }
4181
4197
` )
4182
4198
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4199
+ // add 1 element to cluster-ips and no-endpoint-services = 2 operations
4200
+ if nft .LastTransaction .NumOperations () != 2 {
4201
+ t .Errorf ("Expected 2 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4202
+ }
4183
4203
4184
4204
populateEndpointSlices (fp ,
4185
4205
makeTestEndpointSlice ("ns4" , "svc4" , 1 , func (eps * discovery.EndpointSlice ) {
@@ -4225,6 +4245,11 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4225
4245
add rule ip kube-proxy endpoint-WAHRBT2B-ns4/svc4/tcp/p80__10.0.4.1/80 meta l4proto tcp dnat to 10.0.4.1:80
4226
4246
` )
4227
4247
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4248
+ // add 1 element to service-ips, remove 1 element from no-endpoint-services = 2 operations
4249
+ // add+flush 2 chains for service and endpoint, add 2 rules in each = 8 operations
4250
+ if nft .LastTransaction .NumOperations () != 10 {
4251
+ t .Errorf ("Expected 10 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4252
+ }
4228
4253
4229
4254
// Change an endpoint of an existing service.
4230
4255
eps3update := eps3 .DeepCopy ()
@@ -4264,6 +4289,11 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4264
4289
add rule ip kube-proxy endpoint-WAHRBT2B-ns4/svc4/tcp/p80__10.0.4.1/80 meta l4proto tcp dnat to 10.0.4.1:80
4265
4290
` )
4266
4291
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4292
+ // add+flush 2 chains for service and endpoint, add 2 rules in each = 8 operations
4293
+ // flush old endpoint chain = 1 operation
4294
+ if nft .LastTransaction .NumOperations () != 9 {
4295
+ t .Errorf ("Expected 9 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4296
+ }
4267
4297
4268
4298
// (Ensure the old svc3 chain gets deleted in the next sync.)
4269
4299
ageStaleChains ()
@@ -4307,6 +4337,10 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4307
4337
add rule ip kube-proxy endpoint-WAHRBT2B-ns4/svc4/tcp/p80__10.0.4.1/80 meta l4proto tcp dnat to 10.0.4.1:80
4308
4338
` )
4309
4339
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4340
+ // add+flush 3 chains for 1 service and 2 endpoints, add 2 rules in each = 12 operations
4341
+ if nft .LastTransaction .NumOperations () != 12 {
4342
+ t .Errorf ("Expected 12 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4343
+ }
4310
4344
4311
4345
// Empty a service's endpoints; its chains will be flushed, but not immediately deleted.
4312
4346
eps3update3 := eps3update2 .DeepCopy ()
@@ -4340,6 +4374,12 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4340
4374
add rule ip kube-proxy endpoint-WAHRBT2B-ns4/svc4/tcp/p80__10.0.4.1/80 meta l4proto tcp dnat to 10.0.4.1:80
4341
4375
` )
4342
4376
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4377
+ // remove 1 element from service-ips, add 1 element to no-endpoint-services = 2 operations
4378
+ // flush 3 chains = 3 operations
4379
+ if nft .LastTransaction .NumOperations () != 5 {
4380
+ t .Errorf ("Expected 5 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4381
+ }
4382
+
4343
4383
expectedStaleChains := sets .NewString ("service-4AT6LBPK-ns3/svc3/tcp/p80" , "endpoint-SWWHDC7X-ns3/svc3/tcp/p80__10.0.3.2/80" , "endpoint-TQ2QKHCZ-ns3/svc3/tcp/p80__10.0.3.3/80" )
4344
4384
gotStaleChains := sets .StringKeySet (fp .staleChains )
4345
4385
if ! expectedStaleChains .Equal (gotStaleChains ) {
@@ -4381,6 +4421,12 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4381
4421
add rule ip kube-proxy endpoint-WAHRBT2B-ns4/svc4/tcp/p80__10.0.4.1/80 meta l4proto tcp dnat to 10.0.4.1:80
4382
4422
` )
4383
4423
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4424
+ // remove 1 element from no-endpoint-services, add 1 element to service-ips = 2 operations
4425
+ // add+flush 3 chains for 1 service and 2 endpoints, add 2 rules in each = 12 operations
4426
+ if nft .LastTransaction .NumOperations () != 14 {
4427
+ t .Errorf ("Expected 14 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4428
+ }
4429
+
4384
4430
if len (fp .staleChains ) != 0 {
4385
4431
t .Errorf ("unexpected stale chains: %v" , fp .staleChains )
4386
4432
}
@@ -4399,6 +4445,9 @@ func TestSyncProxyRulesRepeated(t *testing.T) {
4399
4445
// Sync with no new changes, so same expected rules as last time
4400
4446
fp .syncProxyRules ()
4401
4447
assertNFTablesTransactionEqual (t , getLine (), expected , nft .Dump ())
4448
+ if nft .LastTransaction .NumOperations () != 0 {
4449
+ t .Errorf ("Expected 0 trasaction operations, got %d" , nft .LastTransaction .NumOperations ())
4450
+ }
4402
4451
}
4403
4452
4404
4453
func TestNoEndpointsMetric (t * testing.T ) {
0 commit comments