Skip to content

Commit 635178b

Browse files
committed
Add secret resources to change processor tests
1 parent 3146c18 commit 635178b

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

internal/mode/static/state/change_processor_test.go

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,15 +1465,16 @@ var _ = Describe("ChangeProcessor", func() {
14651465
// -- this is done in 'Normal cases of processing changes'
14661466

14671467
var (
1468-
processor *state.ChangeProcessorImpl
1469-
gcNsName, gwNsName, hrNsName, hr2NsName, rgNsName, svcNsName, sliceNsName types.NamespacedName
1470-
gc, gcUpdated *v1.GatewayClass
1471-
gw1, gw1Updated, gw2 *v1.Gateway
1472-
hr1, hr1Updated, hr2 *v1.HTTPRoute
1473-
rg1, rg1Updated, rg2 *v1beta1.ReferenceGrant
1474-
svc, barSvc, unrelatedSvc *apiv1.Service
1475-
slice, barSlice, unrelatedSlice *discoveryV1.EndpointSlice
1476-
ns, unrelatedNS, testNs, barNs *apiv1.Namespace
1468+
processor *state.ChangeProcessorImpl
1469+
gcNsName, gwNsName, hrNsName, hr2NsName, rgNsName, svcNsName, sliceNsName, secretNsName types.NamespacedName
1470+
gc, gcUpdated *v1.GatewayClass
1471+
gw1, gw1Updated, gw2 *v1.Gateway
1472+
hr1, hr1Updated, hr2 *v1.HTTPRoute
1473+
rg1, rg1Updated, rg2 *v1beta1.ReferenceGrant
1474+
svc, barSvc, unrelatedSvc *apiv1.Service
1475+
slice, barSlice, unrelatedSlice *discoveryV1.EndpointSlice
1476+
ns, unrelatedNS, testNs, barNs *apiv1.Namespace
1477+
secret, secretUpdated, unrelatedSecret, barSecret, barSecretUpdated *apiv1.Secret
14771478
)
14781479

14791480
BeforeEach(OncePerOrdered, func() {
@@ -1484,6 +1485,48 @@ var _ = Describe("ChangeProcessor", func() {
14841485
Scheme: createScheme(),
14851486
})
14861487

1488+
secretNsName = types.NamespacedName{Namespace: "test", Name: "tls-secret"}
1489+
secret = &apiv1.Secret{
1490+
ObjectMeta: metav1.ObjectMeta{
1491+
Name: secretNsName.Name,
1492+
Namespace: secretNsName.Namespace,
1493+
Generation: 1,
1494+
},
1495+
Type: apiv1.SecretTypeTLS,
1496+
Data: map[string][]byte{
1497+
apiv1.TLSCertKey: cert,
1498+
apiv1.TLSPrivateKeyKey: key,
1499+
},
1500+
}
1501+
secretUpdated = secret.DeepCopy()
1502+
secretUpdated.Generation++
1503+
barSecret = &apiv1.Secret{
1504+
ObjectMeta: metav1.ObjectMeta{
1505+
Name: "bar-secret",
1506+
Namespace: "test",
1507+
Generation: 1,
1508+
},
1509+
Type: apiv1.SecretTypeTLS,
1510+
Data: map[string][]byte{
1511+
apiv1.TLSCertKey: cert,
1512+
apiv1.TLSPrivateKeyKey: key,
1513+
},
1514+
}
1515+
barSecretUpdated = barSecret.DeepCopy()
1516+
barSecretUpdated.Generation++
1517+
unrelatedSecret = &apiv1.Secret{
1518+
ObjectMeta: metav1.ObjectMeta{
1519+
Name: "unrelated-tls-secret",
1520+
Namespace: "unrelated-ns",
1521+
Generation: 1,
1522+
},
1523+
Type: apiv1.SecretTypeTLS,
1524+
Data: map[string][]byte{
1525+
apiv1.TLSCertKey: cert,
1526+
apiv1.TLSPrivateKeyKey: key,
1527+
},
1528+
}
1529+
14871530
gcNsName = types.NamespacedName{Name: "test-class"}
14881531

14891532
gc = &v1.GatewayClass{
@@ -1525,6 +1568,38 @@ var _ = Describe("ChangeProcessor", func() {
15251568
},
15261569
},
15271570
},
1571+
{
1572+
Name: "listener-443-1",
1573+
Hostname: nil,
1574+
Port: 443,
1575+
Protocol: v1.HTTPSProtocolType,
1576+
TLS: &v1.GatewayTLSConfig{
1577+
Mode: helpers.GetPointer(v1.TLSModeTerminate),
1578+
CertificateRefs: []v1.SecretObjectReference{
1579+
{
1580+
Kind: (*v1.Kind)(helpers.GetPointer("Secret")),
1581+
Name: v1.ObjectName(secret.Name),
1582+
Namespace: (*v1.Namespace)(&secret.Namespace),
1583+
},
1584+
},
1585+
},
1586+
},
1587+
{
1588+
Name: "listener-500-1",
1589+
Hostname: nil,
1590+
Port: 500,
1591+
Protocol: v1.HTTPSProtocolType,
1592+
TLS: &v1.GatewayTLSConfig{
1593+
Mode: helpers.GetPointer(v1.TLSModeTerminate),
1594+
CertificateRefs: []v1.SecretObjectReference{
1595+
{
1596+
Kind: (*v1.Kind)(helpers.GetPointer("Secret")),
1597+
Name: v1.ObjectName(barSecret.Name),
1598+
Namespace: (*v1.Namespace)(&barSecret.Namespace),
1599+
},
1600+
},
1601+
},
1602+
},
15281603
},
15291604
},
15301605
}
@@ -1731,6 +1806,8 @@ var _ = Describe("ChangeProcessor", func() {
17311806
processor.CaptureUpsertChange(gw1)
17321807
processor.CaptureUpsertChange(testNs)
17331808
processor.CaptureUpsertChange(hr1)
1809+
processor.CaptureUpsertChange(secret)
1810+
processor.CaptureUpsertChange(barSecret)
17341811
changed, _ := processor.Process()
17351812
Expect(changed).To(BeTrue())
17361813
})
@@ -1739,13 +1816,15 @@ var _ = Describe("ChangeProcessor", func() {
17391816
processor.CaptureUpsertChange(svc)
17401817
processor.CaptureUpsertChange(slice)
17411818
processor.CaptureUpsertChange(ns)
1819+
processor.CaptureUpsertChange(secretUpdated)
17421820
changed, _ := processor.Process()
17431821
Expect(changed).To(BeTrue())
17441822
})
17451823
It("should report not changed after multiple Upserts of unrelated resources", func() {
17461824
processor.CaptureUpsertChange(unrelatedSvc)
17471825
processor.CaptureUpsertChange(unrelatedSlice)
17481826
processor.CaptureUpsertChange(unrelatedNS)
1827+
processor.CaptureUpsertChange(unrelatedSecret)
17491828

17501829
changed, _ := processor.Process()
17511830
Expect(changed).To(BeFalse())
@@ -1756,11 +1835,13 @@ var _ = Describe("ChangeProcessor", func() {
17561835
processor.CaptureUpsertChange(barSvc)
17571836
processor.CaptureUpsertChange(barSlice)
17581837
processor.CaptureUpsertChange(barNs)
1838+
processor.CaptureUpsertChange(barSecretUpdated)
17591839

17601840
// there are non-changing changes
17611841
processor.CaptureUpsertChange(unrelatedSvc)
17621842
processor.CaptureUpsertChange(unrelatedSlice)
17631843
processor.CaptureUpsertChange(unrelatedNS)
1844+
processor.CaptureUpsertChange(unrelatedSecret)
17641845

17651846
changed, _ := processor.Process()
17661847
Expect(changed).To(BeTrue())
@@ -1772,11 +1853,13 @@ var _ = Describe("ChangeProcessor", func() {
17721853
processor.CaptureDeleteChange(&apiv1.Service{}, svcNsName)
17731854
processor.CaptureDeleteChange(&discoveryV1.EndpointSlice{}, sliceNsName)
17741855
processor.CaptureDeleteChange(&apiv1.Namespace{}, types.NamespacedName{Name: "ns"})
1856+
processor.CaptureDeleteChange(&apiv1.Secret{}, secretNsName)
17751857

17761858
// these are non-changing changes
17771859
processor.CaptureUpsertChange(unrelatedSvc)
17781860
processor.CaptureUpsertChange(unrelatedSlice)
17791861
processor.CaptureUpsertChange(unrelatedNS)
1862+
processor.CaptureUpsertChange(unrelatedSecret)
17801863

17811864
changed, _ := processor.Process()
17821865
Expect(changed).To(BeTrue())
@@ -1796,6 +1879,7 @@ var _ = Describe("ChangeProcessor", func() {
17961879
processor.CaptureUpsertChange(svc)
17971880
processor.CaptureUpsertChange(slice)
17981881
processor.CaptureUpsertChange(ns)
1882+
processor.CaptureUpsertChange(secret)
17991883

18001884
changed, _ := processor.Process()
18011885
Expect(changed).To(BeTrue())
@@ -1805,6 +1889,7 @@ var _ = Describe("ChangeProcessor", func() {
18051889
processor.CaptureUpsertChange(unrelatedSvc)
18061890
processor.CaptureUpsertChange(unrelatedSlice)
18071891
processor.CaptureUpsertChange(unrelatedNS)
1892+
processor.CaptureUpsertChange(unrelatedSecret)
18081893

18091894
changed, _ := processor.Process()
18101895
Expect(changed).To(BeFalse())
@@ -1821,6 +1906,7 @@ var _ = Describe("ChangeProcessor", func() {
18211906
processor.CaptureUpsertChange(unrelatedSvc)
18221907
processor.CaptureUpsertChange(unrelatedSlice)
18231908
processor.CaptureUpsertChange(unrelatedNS)
1909+
processor.CaptureUpsertChange(unrelatedSecret)
18241910

18251911
changed, _ := processor.Process()
18261912
Expect(changed).To(BeTrue())

0 commit comments

Comments
 (0)