Skip to content

Commit 3146c18

Browse files
committed
Add namespace resources to multi k8s api resource change tests
1 parent b8d9a89 commit 3146c18

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

internal/mode/static/state/change_processor_test.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ var _ = Describe("ChangeProcessor", func() {
14731473
rg1, rg1Updated, rg2 *v1beta1.ReferenceGrant
14741474
svc, barSvc, unrelatedSvc *apiv1.Service
14751475
slice, barSlice, unrelatedSlice *discoveryV1.EndpointSlice
1476+
ns, unrelatedNS, testNs, barNs *apiv1.Namespace
14761477
)
14771478

14781479
BeforeEach(OncePerOrdered, func() {
@@ -1499,7 +1500,34 @@ var _ = Describe("ChangeProcessor", func() {
14991500

15001501
gwNsName = types.NamespacedName{Namespace: "test", Name: "gw-1"}
15011502

1502-
gw1 = createGateway("gw-1")
1503+
gw1 = &v1.Gateway{
1504+
ObjectMeta: metav1.ObjectMeta{
1505+
Name: "gw-1",
1506+
Namespace: "test",
1507+
Generation: 1,
1508+
},
1509+
Spec: v1.GatewaySpec{
1510+
GatewayClassName: gcName,
1511+
Listeners: []v1.Listener{
1512+
{
1513+
Name: "listener-80-1",
1514+
Hostname: nil,
1515+
Port: 80,
1516+
Protocol: v1.HTTPProtocolType,
1517+
AllowedRoutes: &v1.AllowedRoutes{
1518+
Namespaces: &v1.RouteNamespaces{
1519+
From: helpers.GetPointer(v1.NamespacesFromSelector),
1520+
Selector: &metav1.LabelSelector{
1521+
MatchLabels: map[string]string{
1522+
"test": "namespace",
1523+
},
1524+
},
1525+
},
1526+
},
1527+
},
1528+
},
1529+
},
1530+
}
15031531

15041532
gw1Updated = gw1.DeepCopy()
15051533
gw1Updated.Generation++
@@ -1567,6 +1595,39 @@ var _ = Describe("ChangeProcessor", func() {
15671595
},
15681596
}
15691597

1598+
testNs = &apiv1.Namespace{
1599+
ObjectMeta: metav1.ObjectMeta{
1600+
Name: "test",
1601+
Labels: map[string]string{
1602+
"test": "namespace",
1603+
},
1604+
},
1605+
}
1606+
ns = &apiv1.Namespace{
1607+
ObjectMeta: metav1.ObjectMeta{
1608+
Name: "ns",
1609+
Labels: map[string]string{
1610+
"test": "namespace",
1611+
},
1612+
},
1613+
}
1614+
barNs = &apiv1.Namespace{
1615+
ObjectMeta: metav1.ObjectMeta{
1616+
Name: "bar-ns",
1617+
Labels: map[string]string{
1618+
"test": "namespace",
1619+
},
1620+
},
1621+
}
1622+
unrelatedNS = &apiv1.Namespace{
1623+
ObjectMeta: metav1.ObjectMeta{
1624+
Name: "unrelated-ns",
1625+
Labels: map[string]string{
1626+
"oranges": "bananas",
1627+
},
1628+
},
1629+
}
1630+
15701631
rgNsName = types.NamespacedName{Namespace: "test", Name: "rg-1"}
15711632

15721633
rg1 = &v1beta1.ReferenceGrant{
@@ -1593,6 +1654,7 @@ var _ = Describe("ChangeProcessor", func() {
15931654
It("should report changed after multiple Upserts", func() {
15941655
processor.CaptureUpsertChange(gc)
15951656
processor.CaptureUpsertChange(gw1)
1657+
processor.CaptureUpsertChange(testNs)
15961658
processor.CaptureUpsertChange(hr1)
15971659
processor.CaptureUpsertChange(rg1)
15981660

@@ -1667,6 +1729,7 @@ var _ = Describe("ChangeProcessor", func() {
16671729
// Set up graph
16681730
processor.CaptureUpsertChange(gc)
16691731
processor.CaptureUpsertChange(gw1)
1732+
processor.CaptureUpsertChange(testNs)
16701733
processor.CaptureUpsertChange(hr1)
16711734
changed, _ := processor.Process()
16721735
Expect(changed).To(BeTrue())
@@ -1675,12 +1738,14 @@ var _ = Describe("ChangeProcessor", func() {
16751738
It("should report changed after multiple Upserts of related resources", func() {
16761739
processor.CaptureUpsertChange(svc)
16771740
processor.CaptureUpsertChange(slice)
1741+
processor.CaptureUpsertChange(ns)
16781742
changed, _ := processor.Process()
16791743
Expect(changed).To(BeTrue())
16801744
})
16811745
It("should report not changed after multiple Upserts of unrelated resources", func() {
16821746
processor.CaptureUpsertChange(unrelatedSvc)
16831747
processor.CaptureUpsertChange(unrelatedSlice)
1748+
processor.CaptureUpsertChange(unrelatedNS)
16841749

16851750
changed, _ := processor.Process()
16861751
Expect(changed).To(BeFalse())
@@ -1690,10 +1755,12 @@ var _ = Describe("ChangeProcessor", func() {
16901755
// these are changing changes
16911756
processor.CaptureUpsertChange(barSvc)
16921757
processor.CaptureUpsertChange(barSlice)
1758+
processor.CaptureUpsertChange(barNs)
16931759

16941760
// there are non-changing changes
16951761
processor.CaptureUpsertChange(unrelatedSvc)
16961762
processor.CaptureUpsertChange(unrelatedSlice)
1763+
processor.CaptureUpsertChange(unrelatedNS)
16971764

16981765
changed, _ := processor.Process()
16991766
Expect(changed).To(BeTrue())
@@ -1704,10 +1771,12 @@ var _ = Describe("ChangeProcessor", func() {
17041771
// these are changing changes
17051772
processor.CaptureDeleteChange(&apiv1.Service{}, svcNsName)
17061773
processor.CaptureDeleteChange(&discoveryV1.EndpointSlice{}, sliceNsName)
1774+
processor.CaptureDeleteChange(&apiv1.Namespace{}, types.NamespacedName{Name: "ns"})
17071775

17081776
// these are non-changing changes
17091777
processor.CaptureUpsertChange(unrelatedSvc)
17101778
processor.CaptureUpsertChange(unrelatedSlice)
1779+
processor.CaptureUpsertChange(unrelatedNS)
17111780

17121781
changed, _ := processor.Process()
17131782
Expect(changed).To(BeTrue())
@@ -1719,12 +1788,14 @@ var _ = Describe("ChangeProcessor", func() {
17191788
// new Gateway API resources
17201789
processor.CaptureUpsertChange(gc)
17211790
processor.CaptureUpsertChange(gw1)
1791+
processor.CaptureUpsertChange(testNs)
17221792
processor.CaptureUpsertChange(hr1)
17231793
processor.CaptureUpsertChange(rg1)
17241794

17251795
// related Kubernetes API resources
17261796
processor.CaptureUpsertChange(svc)
17271797
processor.CaptureUpsertChange(slice)
1798+
processor.CaptureUpsertChange(ns)
17281799

17291800
changed, _ := processor.Process()
17301801
Expect(changed).To(BeTrue())
@@ -1733,6 +1804,7 @@ var _ = Describe("ChangeProcessor", func() {
17331804
// unrelated Kubernetes API resources
17341805
processor.CaptureUpsertChange(unrelatedSvc)
17351806
processor.CaptureUpsertChange(unrelatedSlice)
1807+
processor.CaptureUpsertChange(unrelatedNS)
17361808

17371809
changed, _ := processor.Process()
17381810
Expect(changed).To(BeFalse())
@@ -1748,6 +1820,7 @@ var _ = Describe("ChangeProcessor", func() {
17481820
// these are non-changing changes
17491821
processor.CaptureUpsertChange(unrelatedSvc)
17501822
processor.CaptureUpsertChange(unrelatedSlice)
1823+
processor.CaptureUpsertChange(unrelatedNS)
17511824

17521825
changed, _ := processor.Process()
17531826
Expect(changed).To(BeTrue())

0 commit comments

Comments
 (0)