@@ -1293,53 +1293,166 @@ var _ = Describe("ChangeProcessor", func() {
1293
1293
})
1294
1294
})
1295
1295
})
1296
- Describe ("namespace changes" , func () {
1297
- When ("namespace is linked via label selectors" , func () {
1298
- It ("triggers an update when labels are removed" , func () {
1299
- ns := & apiv1.Namespace {
1300
- ObjectMeta : metav1.ObjectMeta {
1301
- Name : "ns" ,
1302
- Labels : map [string ]string {
1303
- "app" : "allowed" ,
1304
- },
1296
+ Describe ("namespace changes" , Ordered , func () {
1297
+ var (
1298
+ ns , nsDifferentLabels , nsNoLabels * apiv1.Namespace
1299
+ gw * v1.Gateway
1300
+ )
1301
+
1302
+ BeforeAll (func () {
1303
+ ns = & apiv1.Namespace {
1304
+ ObjectMeta : metav1.ObjectMeta {
1305
+ Name : "ns" ,
1306
+ Labels : map [string ]string {
1307
+ "app" : "allowed" ,
1305
1308
},
1306
- }
1307
- gw := & v1.Gateway {
1308
- ObjectMeta : metav1.ObjectMeta {
1309
- Name : "gw" ,
1309
+ },
1310
+ }
1311
+ nsDifferentLabels = & apiv1.Namespace {
1312
+ ObjectMeta : metav1.ObjectMeta {
1313
+ Name : "ns-different-labels" ,
1314
+ Labels : map [string ]string {
1315
+ "oranges" : "bananas" ,
1310
1316
},
1311
- Spec : v1.GatewaySpec {
1312
- Listeners : []v1.Listener {
1313
- {
1314
- AllowedRoutes : & v1.AllowedRoutes {
1315
- Namespaces : & v1.RouteNamespaces {
1316
- From : helpers .GetPointer (v1 .NamespacesFromSelector ),
1317
- Selector : & metav1.LabelSelector {
1318
- MatchLabels : map [string ]string {
1319
- "app" : "allowed" ,
1320
- },
1317
+ },
1318
+ }
1319
+ nsNoLabels = & apiv1.Namespace {
1320
+ ObjectMeta : metav1.ObjectMeta {
1321
+ Name : "no-labels" ,
1322
+ },
1323
+ }
1324
+ gw = & v1.Gateway {
1325
+ ObjectMeta : metav1.ObjectMeta {
1326
+ Name : "gw" ,
1327
+ },
1328
+ Spec : v1.GatewaySpec {
1329
+ GatewayClassName : gcName ,
1330
+ Listeners : []v1.Listener {
1331
+ {
1332
+ Port : 80 ,
1333
+ Protocol : v1 .HTTPProtocolType ,
1334
+ AllowedRoutes : & v1.AllowedRoutes {
1335
+ Namespaces : & v1.RouteNamespaces {
1336
+ From : helpers .GetPointer (v1 .NamespacesFromSelector ),
1337
+ Selector : & metav1.LabelSelector {
1338
+ MatchLabels : map [string ]string {
1339
+ "app" : "allowed" ,
1321
1340
},
1322
1341
},
1323
1342
},
1324
1343
},
1325
1344
},
1326
1345
},
1327
- }
1346
+ },
1347
+ }
1348
+ processor = state .NewChangeProcessorImpl (state.ChangeProcessorConfig {
1349
+ GatewayCtlrName : controllerName ,
1350
+ GatewayClassName : gcName ,
1351
+ RelationshipCapturer : relationship .NewCapturerImpl (),
1352
+ Logger : zap .New (),
1353
+ Validators : createAlwaysValidValidators (),
1354
+ Scheme : createScheme (),
1355
+ })
1356
+ processor .CaptureUpsertChange (gc )
1357
+ processor .CaptureUpsertChange (gw )
1358
+ processor .Process ()
1359
+ })
1328
1360
1329
- processor .CaptureUpsertChange (gw )
1361
+ When ("a namespace is created that is not linked to a listener" , func () {
1362
+ It ("does not trigger an update" , func () {
1363
+ processor .CaptureUpsertChange (nsNoLabels )
1364
+ changed , _ := processor .Process ()
1365
+ Expect (changed ).To (BeFalse ())
1366
+ })
1367
+ })
1368
+ When ("a namespace is created that is linked to a listener" , func () {
1369
+ It ("triggers an update" , func () {
1330
1370
processor .CaptureUpsertChange (ns )
1371
+ changed , _ := processor .Process ()
1372
+ Expect (changed ).To (BeTrue ())
1373
+ })
1374
+ })
1375
+ When ("a namespace is deleted that is not linked to a listener" , func () {
1376
+ It ("does not trigger an update" , func () {
1377
+ processor .CaptureDeleteChange (nsNoLabels , types.NamespacedName {Name : "no-labels" })
1378
+ changed , _ := processor .Process ()
1379
+ Expect (changed ).To (BeFalse ())
1380
+ })
1381
+ })
1382
+ When ("a namespace is deleted that is linked to a listener" , func () {
1383
+ It ("triggers an update" , func () {
1384
+ processor .CaptureDeleteChange (ns , types.NamespacedName {Name : "ns" })
1385
+ changed , _ := processor .Process ()
1386
+ Expect (changed ).To (BeTrue ())
1387
+ })
1388
+ })
1389
+ When ("a namespace that is not linked to a listener has its labels changed to match a listener" , func () {
1390
+ It ("triggers an update" , func () {
1391
+ processor .CaptureUpsertChange (nsDifferentLabels )
1392
+ changed , _ := processor .Process ()
1393
+ Expect (changed ).To (BeFalse ())
1331
1394
1395
+ nsDifferentLabels .Labels = map [string ]string {
1396
+ "app" : "allowed" ,
1397
+ }
1398
+ processor .CaptureUpsertChange (nsDifferentLabels )
1399
+ changed , _ = processor .Process ()
1400
+ Expect (changed ).To (BeTrue ())
1401
+ })
1402
+ })
1403
+ When ("a namespace that is linked to a listener has its labels changed to no longer match a listener" , func () {
1404
+ It ("triggers an update" , func () {
1405
+ nsDifferentLabels .Labels = map [string ]string {
1406
+ "oranges" : "bananas" ,
1407
+ }
1408
+ processor .CaptureUpsertChange (nsDifferentLabels )
1409
+ changed , _ := processor .Process ()
1410
+ Expect (changed ).To (BeTrue ())
1411
+ })
1412
+ })
1413
+ When ("a gateway changes its listener's labels" , func () {
1414
+ It ("triggers an update when a namespace that matches the new labels is created" , func () {
1415
+ gwChangedLabel := gw .DeepCopy ()
1416
+ gwChangedLabel .Spec .Listeners [0 ].AllowedRoutes .Namespaces .Selector .MatchLabels = map [string ]string {
1417
+ "oranges" : "bananas" ,
1418
+ }
1419
+ gwChangedLabel .Generation ++
1420
+ processor .CaptureUpsertChange (gwChangedLabel )
1332
1421
changed , _ := processor .Process ()
1333
1422
Expect (changed ).To (BeTrue ())
1334
1423
1335
- newNS := ns .DeepCopy ()
1336
- newNS .Labels = nil
1337
- processor .CaptureUpsertChange (newNS )
1424
+ // After changing the gateway's labels and generation, the processor should be marked to update
1425
+ // the nginx configuration and build a new graph. When processor.Process() gets called,
1426
+ // the nginx configuration gets updated and a new graph is built with an updated
1427
+ // referencedNamespaces. Thus, when the namespace "ns" is upserted with labels that no longer match
1428
+ // the new labels on the gateway, it would not trigger a change as the namespace would no longer
1429
+ // be in the updated referencedNamespaces and the labels no longer match the new labels on the
1430
+ // gateway.
1431
+ processor .CaptureUpsertChange (ns )
1432
+ changed , _ = processor .Process ()
1433
+ Expect (changed ).To (BeFalse ())
1338
1434
1435
+ processor .CaptureUpsertChange (nsDifferentLabels )
1339
1436
changed , _ = processor .Process ()
1340
1437
Expect (changed ).To (BeTrue ())
1341
1438
})
1342
1439
})
1440
+ When ("a namespace that is not linked to a listener has its labels removed" , func () {
1441
+ It ("does not trigger an update" , func () {
1442
+ ns .Labels = nil
1443
+ processor .CaptureUpsertChange (ns )
1444
+ changed , _ := processor .Process ()
1445
+ Expect (changed ).To (BeFalse ())
1446
+ })
1447
+ })
1448
+ When ("a namespace that is linked to a listener has its labels removed" , func () {
1449
+ It ("triggers an update when labels are removed" , func () {
1450
+ nsDifferentLabels .Labels = nil
1451
+ processor .CaptureUpsertChange (nsDifferentLabels )
1452
+ changed , _ := processor .Process ()
1453
+ Expect (changed ).To (BeTrue ())
1454
+ })
1455
+ })
1343
1456
})
1344
1457
})
1345
1458
0 commit comments