@@ -16,13 +16,15 @@ import (
1616 ciliumClientset "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned"
1717 "github.com/pkg/errors"
1818 "github.com/stretchr/testify/require"
19+ "golang.org/x/exp/rand"
1920)
2021
2122const (
22- ciliumManifestsDir = "../manifests/cilium/lrp/"
23- kubeSystemNamespace = "kube-system"
24- dnsService = "kube-dns"
25- // envCiliumDir = "DIR"
23+ ciliumConfigmapName = "cilium-config"
24+ ciliumManifestsDir = "../manifests/cilium/lrp/"
25+ enableLRPFlag = "enable-local-redirect-policy"
26+ kubeSystemNamespace = "kube-system"
27+ dnsService = "kube-dns"
2628 retryAttempts = 10
2729 retryDelay = 5 * time .Second
2830 promAddress = "http://localhost:9253/metrics"
@@ -62,8 +64,12 @@ func TestLRP(t *testing.T) {
6264 require .NoError (t , err )
6365 kubeDNS := svc .Spec .ClusterIP
6466
67+ // ensure lrp flag is enabled
68+ ciliumCM , err := kubernetes .GetConfigmap (ctx , cs , kubeSystemNamespace , ciliumConfigmapName )
69+ require .NoError (t , err )
70+ require .Equal (t , "true" , ciliumCM .Data [enableLRPFlag ], "enable-local-redirect-policy not set to true in cilium-config" )
71+
6572 // 1.17 and 1.13 cilium versions of both files are identical
66- // directory := os.Getenv(string(envCiliumDir))
6773 // read file
6874 nodeLocalDNSContent , err := os .ReadFile (nodeLocalDNSDaemonsetPath )
6975 require .NoError (t , err )
@@ -167,10 +173,13 @@ func TestLRP(t *testing.T) {
167173 require .Greater (t , afterMetric .GetCounter ().GetValue (), beforeMetric .GetCounter ().GetValue (), "dns metric count did not increase after nslookup" )
168174}
169175
176+ // TakeOne takes one item from the slice randomly; if empty, it returns the empty value for the type
177+ // Use in testing only
170178func TakeOne [T any ](slice []T ) T {
171179 if len (slice ) == 0 {
172180 var zero T
173181 return zero
174182 }
175- return slice [0 ]
183+ rand .Seed (uint64 (time .Now ().UnixNano ()))
184+ return slice [rand .Intn (len (slice ))]
176185}
0 commit comments