From 653945f85654b021073a34210e46a31ea82b3874 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 30 Oct 2025 18:45:08 +0200 Subject: [PATCH 1/6] feat(core): add indexers for slowest client.List operations Signed-off-by: Daniil Antoshin --- .../pkg/controller/indexer/indexer.go | 12 ++++++++++++ .../pkg/controller/vd/internal/inuse.go | 5 +++-- .../pkg/controller/vmip/internal/attached_handler.go | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/indexer/indexer.go b/images/virtualization-artifact/pkg/controller/indexer/indexer.go index 146d3f75ca..d8289ccb1e 100644 --- a/images/virtualization-artifact/pkg/controller/indexer/indexer.go +++ b/images/virtualization-artifact/pkg/controller/indexer/indexer.go @@ -34,6 +34,7 @@ const ( IndexFieldVMByVD = "spec.blockDeviceRefs.VirtualDisk" IndexFieldVMByVI = "spec.blockDeviceRefs.VirtualImage" IndexFieldVMByCVI = "spec.blockDeviceRefs.ClusterVirtualImage" + IndexFieldVMByIP = "status.ipAddress" IndexFieldVMByNode = "status.node" IndexFieldVDByVDSnapshot = "vd,spec.DataSource.ObjectRef.Name,.Kind=VirtualDiskSnapshot" @@ -64,6 +65,7 @@ var IndexGetters = []IndexGetter{ IndexVMByVD, IndexVMByVI, IndexVMByCVI, + IndexVMByIP, IndexVMByNode, IndexVMSnapshotByVM, IndexVMSnapshotByVDSnapshot, @@ -121,6 +123,16 @@ func IndexVMByCVI() (obj client.Object, field string, extractValue client.Indexe } } +func IndexVMByIP() (obj client.Object, field string, extractValue client.IndexerFunc) { + return &v1alpha2.VirtualMachine{}, IndexFieldVMByIP, func(object client.Object) []string { + vm, ok := object.(*v1alpha2.VirtualMachine) + if !ok || vm == nil || vm.Status.IPAddress == "" { + return nil + } + return []string{vm.Status.IPAddress} + } +} + func IndexVMByNode() (obj client.Object, field string, extractValue client.IndexerFunc) { return &v1alpha2.VirtualMachine{}, IndexFieldVMByNode, func(object client.Object) []string { vm, ok := object.(*v1alpha2.VirtualMachine) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go index e581028475..d3af6aa454 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go @@ -33,6 +33,7 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/object" commonvd "github.com/deckhouse/virtualization-controller/pkg/common/vd" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" + "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition" ) @@ -152,8 +153,8 @@ func (h InUseHandler) checkImageUsage(ctx context.Context, vd *v1alpha2.VirtualD func (h InUseHandler) updateAttachedVirtualMachines(ctx context.Context, vd *v1alpha2.VirtualDisk) error { var vms v1alpha2.VirtualMachineList - err := h.client.List(ctx, &vms, &client.ListOptions{ - Namespace: vd.GetNamespace(), + err := h.client.List(ctx, &vms, &client.MatchingFields{ + indexer.IndexFieldVMByVD: vd.Name, }) if err != nil { return fmt.Errorf("error getting virtual machines: %w", err) diff --git a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go index 9bf4a651b0..299b72f142 100644 --- a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go +++ b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go @@ -29,6 +29,7 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/annotations" "github.com/deckhouse/virtualization-controller/pkg/common/object" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" + "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization-controller/pkg/eventrecord" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vmipcondition" @@ -83,7 +84,9 @@ func (h *AttachedHandler) Handle(ctx context.Context, vmip *v1alpha2.VirtualMach func (h *AttachedHandler) getAttachedVirtualMachine(ctx context.Context, vmip *v1alpha2.VirtualMachineIPAddress) (*v1alpha2.VirtualMachine, error) { var vms v1alpha2.VirtualMachineList - err := h.client.List(ctx, &vms, &client.ListOptions{Namespace: vmip.Namespace}) + err := h.client.List(ctx, &vms, &client.MatchingFields{ + indexer.IndexFieldVMByIP: vmip.Status.Address, + }) if err != nil { return nil, fmt.Errorf("list vms: %w", err) } From 40cabe471c8ecf0e1b0ab77c0ab6ae33720f57fb Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Sat, 1 Nov 2025 10:53:27 +0200 Subject: [PATCH 2/6] fix tests Signed-off-by: Daniil Antoshin --- .../pkg/controller/vd/internal/inuse_test.go | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse_test.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse_test.go index fe5e4b17b0..c11fd330d2 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse_test.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse_test.go @@ -27,9 +27,9 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" virtv1 "kubevirt.io/api/core/v1" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/deckhouse/virtualization-controller/pkg/common/annotations" + "github.com/deckhouse/virtualization-controller/pkg/common/testutil" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition" @@ -150,7 +150,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vm, vm2, vm3).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vm, vm2, vm3) + Expect(err).ToNot(HaveOccurred()) handler = &InUseHandler{client: k8sClient} result, err := handler.Handle(ctx, vd) @@ -215,7 +216,9 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vm).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vm) + Expect(err).ToNot(HaveOccurred()) + handler = &InUseHandler{client: k8sClient} result, err := handler.Handle(ctx, vd) @@ -243,7 +246,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) handler = &InUseHandler{client: k8sClient} result, err := handler.Handle(ctx, vd) @@ -272,7 +276,9 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) + handler = &InUseHandler{client: k8sClient} result, err := handler.Handle(ctx, vd) @@ -300,7 +306,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -331,7 +338,8 @@ var _ = Describe("InUseHandler", func() { } vd.Generation = 3 - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -380,7 +388,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vm).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vm) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -431,7 +440,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vm).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vm) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -477,7 +487,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vi).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vi) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -525,7 +536,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, cvi).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, cvi) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -587,7 +599,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vi, vm).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vi, vm) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -635,7 +648,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vm).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vm) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -688,7 +702,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, vi).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, vi) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -720,7 +735,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -752,7 +768,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) @@ -792,7 +809,8 @@ var _ = Describe("InUseHandler", func() { }, } - k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vd, pvc).Build() + k8sClient, err := testutil.NewFakeClientWithObjects(vd, pvc) + Expect(err).ToNot(HaveOccurred()) handler = NewInUseHandler(k8sClient) result, err := handler.Handle(ctx, vd) From 63cb6c9f1702f93bbecc14084c2a253d8cf506ba Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 6 Nov 2025 10:42:34 +0200 Subject: [PATCH 3/6] try to fix e2e Signed-off-by: Daniil Antoshin --- .../pkg/controller/vd/internal/inuse.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go index d3af6aa454..e80918ca9e 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go @@ -23,6 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" virtv1 "kubevirt.io/api/core/v1" @@ -153,8 +154,9 @@ func (h InUseHandler) checkImageUsage(ctx context.Context, vd *v1alpha2.VirtualD func (h InUseHandler) updateAttachedVirtualMachines(ctx context.Context, vd *v1alpha2.VirtualDisk) error { var vms v1alpha2.VirtualMachineList - err := h.client.List(ctx, &vms, &client.MatchingFields{ - indexer.IndexFieldVMByVD: vd.Name, + err := h.client.List(ctx, &vms, &client.ListOptions{ + Namespace: vd.GetNamespace(), + FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByVD, vd.Name), }) if err != nil { return fmt.Errorf("error getting virtual machines: %w", err) From a143866fe67b6567ba70ed536d837428fbee1cf7 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 6 Nov 2025 12:12:01 +0200 Subject: [PATCH 4/6] fix vmip Signed-off-by: Daniil Antoshin --- .../pkg/controller/vmip/internal/attached_handler.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go index 299b72f142..bc47720414 100644 --- a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go +++ b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -84,8 +85,9 @@ func (h *AttachedHandler) Handle(ctx context.Context, vmip *v1alpha2.VirtualMach func (h *AttachedHandler) getAttachedVirtualMachine(ctx context.Context, vmip *v1alpha2.VirtualMachineIPAddress) (*v1alpha2.VirtualMachine, error) { var vms v1alpha2.VirtualMachineList - err := h.client.List(ctx, &vms, &client.MatchingFields{ - indexer.IndexFieldVMByIP: vmip.Status.Address, + err := h.client.List(ctx, &vms, &client.ListOptions{ + Namespace: vmip.GetNamespace(), + FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByIP, vmip.Status.Address), }) if err != nil { return nil, fmt.Errorf("list vms: %w", err) From fdccc7030ce3dc28a6a72886e9718bc0bbc42f81 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 6 Nov 2025 14:30:29 +0200 Subject: [PATCH 5/6] test without Signed-off-by: Daniil Antoshin --- .../pkg/controller/vd/internal/inuse.go | 6 ++---- .../pkg/controller/vmip/internal/attached_handler.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go index e80918ca9e..0a6c5b0da3 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go @@ -23,7 +23,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" virtv1 "kubevirt.io/api/core/v1" @@ -34,7 +33,6 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/object" commonvd "github.com/deckhouse/virtualization-controller/pkg/common/vd" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" - "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition" ) @@ -155,8 +153,8 @@ func (h InUseHandler) checkImageUsage(ctx context.Context, vd *v1alpha2.VirtualD func (h InUseHandler) updateAttachedVirtualMachines(ctx context.Context, vd *v1alpha2.VirtualDisk) error { var vms v1alpha2.VirtualMachineList err := h.client.List(ctx, &vms, &client.ListOptions{ - Namespace: vd.GetNamespace(), - FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByVD, vd.Name), + Namespace: vd.Namespace, + // FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByVD, vd.Name), }) if err != nil { return fmt.Errorf("error getting virtual machines: %w", err) diff --git a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go index bc47720414..f394224b2d 100644 --- a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go +++ b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go @@ -22,7 +22,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -30,7 +29,6 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/annotations" "github.com/deckhouse/virtualization-controller/pkg/common/object" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" - "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization-controller/pkg/eventrecord" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vmipcondition" @@ -86,8 +84,8 @@ func (h *AttachedHandler) Handle(ctx context.Context, vmip *v1alpha2.VirtualMach func (h *AttachedHandler) getAttachedVirtualMachine(ctx context.Context, vmip *v1alpha2.VirtualMachineIPAddress) (*v1alpha2.VirtualMachine, error) { var vms v1alpha2.VirtualMachineList err := h.client.List(ctx, &vms, &client.ListOptions{ - Namespace: vmip.GetNamespace(), - FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByIP, vmip.Status.Address), + Namespace: vmip.Namespace, + // FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByIP, vmip.Status.Address), }) if err != nil { return nil, fmt.Errorf("list vms: %w", err) From 59b7fc8e37ec772ff538c8e4ebb5c55161366322 Mon Sep 17 00:00:00 2001 From: Daniil Antoshin Date: Thu, 6 Nov 2025 16:36:39 +0200 Subject: [PATCH 6/6] test again Signed-off-by: Daniil Antoshin --- .../pkg/controller/vd/internal/inuse.go | 6 ++++-- .../pkg/controller/vmip/internal/attached_handler.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go index 0a6c5b0da3..9c45483364 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/inuse.go @@ -23,6 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" virtv1 "kubevirt.io/api/core/v1" @@ -33,6 +34,7 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/object" commonvd "github.com/deckhouse/virtualization-controller/pkg/common/vd" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" + "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition" ) @@ -153,8 +155,8 @@ func (h InUseHandler) checkImageUsage(ctx context.Context, vd *v1alpha2.VirtualD func (h InUseHandler) updateAttachedVirtualMachines(ctx context.Context, vd *v1alpha2.VirtualDisk) error { var vms v1alpha2.VirtualMachineList err := h.client.List(ctx, &vms, &client.ListOptions{ - Namespace: vd.Namespace, - // FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByVD, vd.Name), + Namespace: vd.Namespace, + FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByVD, vd.Name), }) if err != nil { return fmt.Errorf("error getting virtual machines: %w", err) diff --git a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go index f394224b2d..0190343d3c 100644 --- a/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go +++ b/images/virtualization-artifact/pkg/controller/vmip/internal/attached_handler.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -29,6 +30,7 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/annotations" "github.com/deckhouse/virtualization-controller/pkg/common/object" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" + "github.com/deckhouse/virtualization-controller/pkg/controller/indexer" "github.com/deckhouse/virtualization-controller/pkg/eventrecord" "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/api/core/v1alpha2/vmipcondition" @@ -84,8 +86,8 @@ func (h *AttachedHandler) Handle(ctx context.Context, vmip *v1alpha2.VirtualMach func (h *AttachedHandler) getAttachedVirtualMachine(ctx context.Context, vmip *v1alpha2.VirtualMachineIPAddress) (*v1alpha2.VirtualMachine, error) { var vms v1alpha2.VirtualMachineList err := h.client.List(ctx, &vms, &client.ListOptions{ - Namespace: vmip.Namespace, - // FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByIP, vmip.Status.Address), + Namespace: vmip.Namespace, + FieldSelector: fields.OneTermEqualSelector(indexer.IndexFieldVMByIP, vmip.Status.Address), }) if err != nil { return nil, fmt.Errorf("list vms: %w", err)