@@ -18,17 +18,13 @@ import (
1818 "k8s.io/apimachinery/pkg/util/sets"
1919
2020 "github.com/cilium/cilium/pkg/defaults"
21- "github.com/cilium/cilium/pkg/fqdn/re"
2221 "github.com/cilium/cilium/pkg/ip"
2322)
2423
2524// TestUpdateLookup tests that we can insert DNS data and retrieve it. We
2625// iterate through time, ensuring that data is expired as appropriate. We also
2726// insert redundant DNS entries that should not change the output.
2827func TestUpdateLookup (t * testing.T ) {
29- logger := hivetest .Logger (t )
30- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
31-
3228 name := "test.com"
3329 now := time .Now ()
3430 cache := NewDNSCache (0 )
@@ -79,9 +75,6 @@ func TestUpdateLookup(t *testing.T) {
7975
8076// TestDelete tests that we can forcibly clear parts of the cache.
8177func TestDelete (t * testing.T ) {
82- logger := hivetest .Logger (t )
83- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
84-
8578 names := map [string ]netip.Addr {
8679 "test1.com" : netip .MustParseAddr ("2.2.2.1" ),
8780 "test2.com" : netip .MustParseAddr ("2.2.2.2" ),
@@ -152,9 +145,6 @@ func TestDelete(t *testing.T) {
152145}
153146
154147func Test_forceExpiredByNames (t * testing.T ) {
155- logger := hivetest .Logger (t )
156- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
157-
158148 names := []string {"test1.com" , "test2.com" }
159149 cache := NewDNSCache (0 )
160150 for i := 1 ; i < 4 ; i ++ {
@@ -171,9 +161,6 @@ func Test_forceExpiredByNames(t *testing.T) {
171161}
172162
173163func TestReverseUpdateLookup (t * testing.T ) {
174- logger := hivetest .Logger (t )
175- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
176-
177164 names := map [string ]netip.Addr {
178165 "test1.com" : netip .MustParseAddr ("2.2.2.1" ),
179166 "test2.com" : netip .MustParseAddr ("2.2.2.2" ),
@@ -241,9 +228,6 @@ func TestReverseUpdateLookup(t *testing.T) {
241228}
242229
243230func TestJSONMarshal (t * testing.T ) {
244- logger := hivetest .Logger (t )
245- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
246-
247231 names := map [string ]netip.Addr {
248232 "test1.com" : netip .MustParseAddr ("2.2.2.1" ),
249233 "test2.com" : netip .MustParseAddr ("2.2.2.2" ),
@@ -296,9 +280,6 @@ func TestJSONMarshal(t *testing.T) {
296280}
297281
298282func TestCountIPs (t * testing.T ) {
299- logger := hivetest .Logger (t )
300- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
301-
302283 names := map [string ]netip.Addr {
303284 "test1.com" : netip .MustParseAddr ("1.1.1.1" ),
304285 "test2.com" : netip .MustParseAddr ("2.2.2.2" ),
@@ -386,9 +367,6 @@ func makeEntries(now time.Time, live, redundant, expired uint32) (entries []*cac
386367
387368// Note: each "op" works on size things
388369func BenchmarkGetIPs (b * testing.B ) {
389- logger := hivetest .Logger (b )
390- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
391-
392370 now := time .Now ()
393371 cache := NewDNSCache (0 )
394372 cache .Update (now , "test.com" , []netip.Addr {netip .MustParseAddr ("1.2.3.4" )}, 60 )
@@ -404,9 +382,6 @@ func BenchmarkGetIPs(b *testing.B) {
404382
405383// Note: each "op" works on size things
406384func BenchmarkUpdateIPs (b * testing.B ) {
407- logger := hivetest .Logger (b )
408- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
409-
410385 for b .Loop () {
411386 b .StopTimer ()
412387 now := time .Now ()
@@ -456,9 +431,6 @@ func BenchmarkMarshalJSON1000Repeat2(b *testing.B) {
456431// Note: It assumes the JSON only uses data in DNSCache.forward when generating
457432// the data. Changes to the implementation need to also change this benchmark.
458433func benchmarkMarshalJSON (b * testing.B , numDNSEntries int ) {
459- logger := hivetest .Logger (b )
460- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
461-
462434 ips := makeIPs (uint32 (numIPsPerEntry ))
463435
464436 cache := NewDNSCache (0 )
@@ -478,9 +450,6 @@ func benchmarkMarshalJSON(b *testing.B, numDNSEntries int) {
478450// Note: It assumes the JSON only uses data in DNSCache.forward when generating
479451// the data. Changes to the implementation need to also change this benchmark.
480452func benchmarkUnmarshalJSON (b * testing.B , numDNSEntries int ) {
481- logger := hivetest .Logger (b )
482- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
483-
484453 ips := makeIPs (uint32 (numIPsPerEntry ))
485454
486455 cache := NewDNSCache (0 )
@@ -505,9 +474,6 @@ func benchmarkUnmarshalJSON(b *testing.B, numDNSEntries int) {
505474}
506475
507476func TestTTLInsertWithMinValue (t * testing.T ) {
508- logger := hivetest .Logger (t )
509- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
510-
511477 now := time .Now ()
512478 cache := NewDNSCache (60 )
513479 cache .Update (now , "test.com" , []netip.Addr {netip .MustParseAddr ("1.2.3.4" )}, 3 )
@@ -529,9 +495,6 @@ func TestTTLInsertWithMinValue(t *testing.T) {
529495}
530496
531497func TestTTLInsertWithZeroValue (t * testing.T ) {
532- logger := hivetest .Logger (t )
533- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
534-
535498 now := time .Now ()
536499 cache := NewDNSCache (0 )
537500 cache .Update (now , "test.com" , []netip.Addr {netip .MustParseAddr ("1.2.3.4" )}, 10 )
@@ -553,9 +516,6 @@ func TestTTLInsertWithZeroValue(t *testing.T) {
553516}
554517
555518func TestTTLCleanupEntries (t * testing.T ) {
556- logger := hivetest .Logger (t )
557- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
558-
559519 cache := NewDNSCache (0 )
560520 cache .Update (now , "test.com" , []netip.Addr {netip .MustParseAddr ("1.2.3.4" )}, 3 )
561521 require .Len (t , cache .cleanup , 1 )
@@ -566,9 +526,6 @@ func TestTTLCleanupEntries(t *testing.T) {
566526}
567527
568528func TestTTLCleanupWithoutForward (t * testing.T ) {
569- logger := hivetest .Logger (t )
570- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
571-
572529 cache := NewDNSCache (0 )
573530 now := time .Now ()
574531 cache .cleanup [now .Unix ()] = []string {"test.com" }
@@ -580,9 +537,6 @@ func TestTTLCleanupWithoutForward(t *testing.T) {
580537}
581538
582539func TestOverlimitEntriesWithValidLimit (t * testing.T ) {
583- logger := hivetest .Logger (t )
584- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
585-
586540 limit := 5
587541 cache := NewDNSCacheWithLimit (0 , limit )
588542
@@ -603,9 +557,6 @@ func TestOverlimitEntriesWithValidLimit(t *testing.T) {
603557}
604558
605559func TestOverlimitEntriesWithoutLimit (t * testing.T ) {
606- logger := hivetest .Logger (t )
607- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
608-
609560 limit := 0
610561 cache := NewDNSCacheWithLimit (0 , limit )
611562 for i := range 5 {
@@ -617,9 +568,6 @@ func TestOverlimitEntriesWithoutLimit(t *testing.T) {
617568}
618569
619570func TestGCOverlimitAfterTTLCleanup (t * testing.T ) {
620- logger := hivetest .Logger (t )
621- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
622-
623571 limit := 5
624572 cache := NewDNSCacheWithLimit (0 , limit )
625573
@@ -641,9 +589,6 @@ func TestGCOverlimitAfterTTLCleanup(t *testing.T) {
641589}
642590
643591func TestOverlimitAfterDeleteForwardEntry (t * testing.T ) {
644- logger := hivetest .Logger (t )
645- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
646-
647592 // Validate if something delete the forward entry no invalid key access on
648593 // CG operation
649594 dnsCache := NewDNSCache (0 )
@@ -653,9 +598,6 @@ func TestOverlimitAfterDeleteForwardEntry(t *testing.T) {
653598}
654599
655600func assertZombiesContain (t * testing.T , zombies []* DNSZombieMapping , expected map [string ][]string ) {
656- logger := hivetest .Logger (t )
657- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
658-
659601 t .Helper ()
660602 require .Lenf (t , zombies , len (expected ), "Different number of zombies than expected: %+v" , zombies )
661603
@@ -675,7 +617,6 @@ func assertZombiesContain(t *testing.T, zombies []*DNSZombieMapping, expected ma
675617
676618func TestZombiesSiblingsGC (t * testing.T ) {
677619 logger := hivetest .Logger (t )
678- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
679620
680621 now := time .Now ()
681622 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , defaults .ToFQDNsMaxIPsPerHost )
@@ -706,7 +647,6 @@ func TestZombiesSiblingsGC(t *testing.T) {
706647
707648func TestZombiesGC (t * testing.T ) {
708649 logger := hivetest .Logger (t )
709- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
710650
711651 now := time .Now ()
712652 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , defaults .ToFQDNsMaxIPsPerHost )
@@ -808,7 +748,6 @@ func TestZombiesGC(t *testing.T) {
808748
809749func TestZombiesGCOverLimit (t * testing.T ) {
810750 logger := hivetest .Logger (t )
811- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
812751
813752 now := time .Now ()
814753 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , 1 )
@@ -835,7 +774,6 @@ func TestZombiesGCOverLimit(t *testing.T) {
835774
836775func TestZombiesGCOverLimitWithCTGC (t * testing.T ) {
837776 logger := hivetest .Logger (t )
838- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
839777
840778 now := time .Now ()
841779 afterNow := now .Add (1 * time .Nanosecond )
@@ -873,7 +811,6 @@ func TestZombiesGCOverLimitWithCTGC(t *testing.T) {
873811
874812func TestZombiesGCDeferredDeletes (t * testing.T ) {
875813 logger := hivetest .Logger (t )
876- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
877814
878815 now := time .Now ()
879816 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , defaults .ToFQDNsMaxIPsPerHost )
@@ -935,7 +872,6 @@ func TestZombiesGCDeferredDeletes(t *testing.T) {
935872
936873func TestZombiesForceExpire (t * testing.T ) {
937874 logger := hivetest .Logger (t )
938- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
939875
940876 now := time .Now ()
941877 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , defaults .ToFQDNsMaxIPsPerHost )
@@ -1008,7 +944,6 @@ func TestZombiesForceExpire(t *testing.T) {
1008944
1009945func TestCacheToZombiesGCCascade (t * testing.T ) {
1010946 logger := hivetest .Logger (t )
1011- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
1012947
1013948 now := time .Now ()
1014949 cache := NewDNSCache (0 )
@@ -1056,7 +991,6 @@ func TestCacheToZombiesGCCascade(t *testing.T) {
1056991
1057992func TestZombiesDumpAlive (t * testing.T ) {
1058993 logger := hivetest .Logger (t )
1059- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
1060994
1061995 now := time .Now ()
1062996 zombies := NewDNSZombieMappings (logger , defaults .ToFQDNsMaxDeferredConnectionDeletes , defaults .ToFQDNsMaxIPsPerHost )
@@ -1134,7 +1068,6 @@ func TestZombiesDumpAlive(t *testing.T) {
11341068
11351069func TestOverlimitPreferNewerEntries (t * testing.T ) {
11361070 logger := hivetest .Logger (t )
1137- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
11381071
11391072 toFQDNsMinTTL := 100
11401073 toFQDNsMaxIPsPerHost := 5
@@ -1223,7 +1156,6 @@ func TestOverlimitPreferNewerEntries(t *testing.T) {
12231156// the front).
12241157func TestPerHostLimitBehaviourForS3 (t * testing.T ) {
12251158 logger := hivetest .Logger (t )
1226- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
12271159
12281160 someDomain := "s3.example.com"
12291161 maxIPs := 5
@@ -1376,9 +1308,6 @@ func validateZombieSort(t *testing.T, zombies []*DNSZombieMapping) {
13761308}
13771309
13781310func Test_sortZombieMappingSlice (t * testing.T ) {
1379- logger := hivetest .Logger (t )
1380- re .InitRegexCompileLRU (logger , defaults .FQDNRegexCompileLRUSize )
1381-
13821311 // Create three moments in time, so we can have before, equal and after.
13831312 moments := []time.Time {
13841313 time .Date (2001 , time .January , 1 , 1 , 1 , 1 , 0 , time .Local ),
0 commit comments