From fd55f6cc339c52d4668bb73e532c140abce171a7 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Fri, 1 Aug 2025 19:24:41 +0100 Subject: [PATCH] feat(source/istio): speed up processing with indexers Signed-off-by: ivan katliarchuk --- source/istio_gateway.go | 3 ++- source/istio_gateway_test.go | 4 ++-- source/istio_virtualservice.go | 7 ++++--- source/istio_virtualservice_test.go | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/istio_gateway.go b/source/istio_gateway.go index b91660abd..784a477c7 100644 --- a/source/istio_gateway.go +++ b/source/istio_gateway.go @@ -191,7 +191,7 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e endpoints = append(endpoints, gwEndpoints...) } - // TODO: sort on endpoint creation + // TODO: sort on endpoint creation (performance) for _, ep := range endpoints { sort.Sort(ep.Targets) } @@ -241,6 +241,7 @@ func (sc *gatewaySource) targetsFromIngress(ctx context.Context, ingressStr stri targets := make(endpoint.Targets, 0) + // TODO: should be informer as currently this is make an API call for each gateway (performance) ingress, err := sc.kubeClient.NetworkingV1().Ingresses(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { log.Error(err) diff --git a/source/istio_gateway_test.go b/source/istio_gateway_test.go index 21f57009e..61479620c 100644 --- a/source/istio_gateway_test.go +++ b/source/istio_gateway_test.go @@ -1477,7 +1477,7 @@ func testGatewayEndpoints(t *testing.T) { t.Run(ti.title, func(t *testing.T) { t.Parallel() - fakeKubernetesClient := fake.NewSimpleClientset() + fakeKubernetesClient := fake.NewClientset() for _, lb := range ti.lbServices { service := lb.Service() @@ -1524,7 +1524,7 @@ func testGatewayEndpoints(t *testing.T) { // gateway specific helper functions func newTestGatewaySource(loadBalancerList []fakeIngressGatewayService, ingressList []fakeIngress) (*gatewaySource, error) { - fakeKubernetesClient := fake.NewSimpleClientset() + fakeKubernetesClient := fake.NewClientset() fakeIstioClient := istiofake.NewSimpleClientset() for _, lb := range loadBalancerList { diff --git a/source/istio_virtualservice.go b/source/istio_virtualservice.go index 5e7f6ab40..11a46ad78 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -109,10 +109,10 @@ func NewIstioVirtualServiceSource( istioInformerFactory.Start(ctx.Done()) // wait for the local cache to be populated. - if err := informers.WaitForCacheSync(context.Background(), informerFactory); err != nil { + if err := informers.WaitForCacheSync(ctx, informerFactory); err != nil { return nil, err } - if err := informers.WaitForCacheSync(context.Background(), istioInformerFactory); err != nil { + if err := informers.WaitForCacheSync(ctx, istioInformerFactory); err != nil { return nil, err } @@ -183,7 +183,7 @@ func (sc *virtualServiceSource) Endpoints(ctx context.Context) ([]*endpoint.Endp endpoints = append(endpoints, gwEndpoints...) } - // TODO: sort on endpoint creation + // TODO: sort on endpoint creation (performance) for _, ep := range endpoints { sort.Sort(ep.Targets) } @@ -419,6 +419,7 @@ func (sc *virtualServiceSource) targetsFromIngress(ctx context.Context, ingressS namespace = gateway.Namespace } + // TODO: should be informer as currently this is making an API call for each gateway (performance) ingress, err := sc.kubeClient.NetworkingV1().Ingresses(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { log.Error(err) diff --git a/source/istio_virtualservice_test.go b/source/istio_virtualservice_test.go index 3bedf05fd..77875879c 100644 --- a/source/istio_virtualservice_test.go +++ b/source/istio_virtualservice_test.go @@ -49,7 +49,7 @@ type VirtualServiceSuite struct { } func (suite *VirtualServiceSuite) SetupTest() { - fakeKubernetesClient := fake.NewSimpleClientset() + fakeKubernetesClient := fake.NewClientset() fakeIstioClient := istiofake.NewSimpleClientset() var err error @@ -188,7 +188,7 @@ func TestNewIstioVirtualServiceSource(t *testing.T) { _, err := NewIstioVirtualServiceSource( context.TODO(), - fake.NewSimpleClientset(), + fake.NewClientset(), istiofake.NewSimpleClientset(), "", ti.annotationFilter,