Repository: kubernetes-sigs/kueue
Pull request #592 (2023-02-23 07:43:56)

Consolidate indexes in a single package
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?
/kind cleanup

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes https://github.com/kubernetes-sigs/kueue/pull/588#issuecomment-1440675522 https://github.com/kubernetes-sigs/kueue/pull/588#discussion_r1114641290

#### Special notes for your reviewer:



k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kueue/pull/592#" title="Author self-approved">kerthcet</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign ahg-g for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkueue).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/kueue/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["ahg-g"]} -->
netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *kubernetes-sigs-kueue* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | a36ebc39ab5234e279f11c5761df66181a0814e8 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/63f7193ebdb3930008908e1e |
k8s-ci-robot: @kerthcet: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @kerthcet: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`
pull-kueue-test-unit-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-unit-main/1628661931160113152) | true | `/test pull-kueue-test-unit-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @kerthcet: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`
pull-kueue-test-unit-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-unit-main/1628661931160113152) | true | `/test pull-kueue-test-unit-main`
pull-kueue-test-integration-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-integration-main/1628661931206250496) | true | `/test pull-kueue-test-integration-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @kerthcet: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`
pull-kueue-test-unit-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-unit-main/1628661931160113152) | true | `/test pull-kueue-test-unit-main`
pull-kueue-test-integration-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-integration-main/1628661931206250496) | true | `/test pull-kueue-test-integration-main`
pull-kueue-test-e2e-main-1-23 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-1-23/1628661931256582144) | true | `/test pull-kueue-test-e2e-main-1-23`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @kerthcet: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`
pull-kueue-test-unit-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-unit-main/1628661931160113152) | true | `/test pull-kueue-test-unit-main`
pull-kueue-test-integration-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-integration-main/1628661931206250496) | true | `/test pull-kueue-test-integration-main`
pull-kueue-test-e2e-main-1-23 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-1-23/1628661931256582144) | true | `/test pull-kueue-test-e2e-main-1-23`
pull-kueue-test-e2e-main-k8-1-25 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-k8-1-25/1628661931353051136) | true | `/test pull-kueue-test-e2e-main-k8-1-25`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @kerthcet: The following tests **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-kueue-verify-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-verify-main/1628661931394994176) | true | `/test pull-kueue-verify-main`
pull-kueue-test-unit-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-unit-main/1628661931160113152) | true | `/test pull-kueue-test-unit-main`
pull-kueue-test-integration-main | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-integration-main/1628661931206250496) | true | `/test pull-kueue-test-integration-main`
pull-kueue-test-e2e-main-1-23 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-1-23/1628661931256582144) | true | `/test pull-kueue-test-e2e-main-1-23`
pull-kueue-test-e2e-main-k8-1-25 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-k8-1-25/1628661931353051136) | true | `/test pull-kueue-test-e2e-main-k8-1-25`
pull-kueue-test-e2e-main-1-24 | a36ebc39ab5234e279f11c5761df66181a0814e8 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/592/pull-kueue-test-e2e-main-1-24/1628661931298525184) | true | `/test pull-kueue-test-e2e-main-1-24`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=592). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Akerthcet). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/kueue/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
alculquicondor: /retitle Consolidate indexes in a single package
k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kueue/pull/592#pullrequestreview-1311569296" title="Approved">alculquicondor</a>*, *<a href="https://github.com/kubernetes-sigs/kueue/pull/592#" title="Author self-approved">kerthcet</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkueue).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/kueue/blob/main/OWNERS)~~ [alculquicondor]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/main.go b/main.go
index 7d7ba3c2c..84a86bfc8 100644
--- a/main.go
+++ b/main.go
@@ -44,6 +44,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/constants"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/controller/workload/job"
 	"sigs.k8s.io/kueue/pkg/metrics"
 	"sigs.k8s.io/kueue/pkg/queue"
@@ -141,11 +142,8 @@ func main() {
 }
 
 func setupIndexes(ctx context.Context, mgr ctrl.Manager) {
-	if err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer()); err != nil {
-		setupLog.Error(err, "Unable to setup queue indexes")
-	}
-	if err := cache.SetupIndexes(ctx, mgr.GetFieldIndexer()); err != nil {
-		setupLog.Error(err, "Unable to setup cache indexes")
+	if err := indexer.Setup(ctx, mgr.GetFieldIndexer()); err != nil {
+		setupLog.Error(err, "Unable to setup core api indexes")
 	}
 	if err := job.SetupIndexes(ctx, mgr.GetFieldIndexer()); err != nil {
 		setupLog.Error(err, "Unable to setup job indexes")
diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go
index 09514a7f3..77e4b2366 100644
--- a/pkg/cache/cache.go
+++ b/pkg/cache/cache.go
@@ -32,8 +32,8 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
+	utilindexer "sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/metrics"
-	utilindexer "sigs.k8s.io/kueue/pkg/util/indexer"
 	"sigs.k8s.io/kueue/pkg/util/pointer"
 	"sigs.k8s.io/kueue/pkg/workload"
 )
@@ -876,10 +876,6 @@ func resourcesByName(in []kueue.Resource) map[corev1.ResourceName]*Resource {
 	return out
 }
 
-func SetupIndexes(ctx context.Context, indexer client.FieldIndexer) error {
-	return indexer.IndexField(ctx, &kueue.Workload{}, utilindexer.WorkloadClusterQueueKey, utilindexer.IndexWorkloadClusterQueue)
-}
-
 func workloadBelongsToLocalQueue(wl *kueue.Workload, q *kueue.LocalQueue) bool {
 	return wl.Namespace == q.Namespace && wl.Spec.QueueName == q.Name
 }
diff --git a/pkg/controller/core/indexer/indexer.go b/pkg/controller/core/indexer/indexer.go
new file mode 100644
index 000000000..3b121ea0f
--- /dev/null
+++ b/pkg/controller/core/indexer/indexer.go
@@ -0,0 +1,73 @@
+/*
+Copyright 2023 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package indexer
+
+import (
+	"context"
+	"fmt"
+
+	"sigs.k8s.io/controller-runtime/pkg/client"
+
+	kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
+)
+
+const (
+	WorkloadQueueKey        = "spec.queueName"
+	WorkloadClusterQueueKey = "spec.admission.clusterQueue"
+	QueueClusterQueueKey    = "spec.clusterQueue"
+)
+
+func IndexQueueClusterQueue(obj client.Object) []string {
+	q, ok := obj.(*kueue.LocalQueue)
+	if !ok {
+		return nil
+	}
+	return []string{string(q.Spec.ClusterQueue)}
+}
+
+func IndexWorkloadQueue(obj client.Object) []string {
+	wl, ok := obj.(*kueue.Workload)
+	if !ok {
+		return nil
+	}
+	return []string{wl.Spec.QueueName}
+}
+
+func IndexWorkloadClusterQueue(obj client.Object) []string {
+	wl, ok := obj.(*kueue.Workload)
+	if !ok {
+		return nil
+	}
+	if wl.Spec.Admission == nil {
+		return nil
+	}
+	return []string{string(wl.Spec.Admission.ClusterQueue)}
+}
+
+// Setup sets the index with the given fields for core apis.
+func Setup(ctx context.Context, indexer client.FieldIndexer) error {
+	if err := indexer.IndexField(ctx, &kueue.Workload{}, WorkloadQueueKey, IndexWorkloadQueue); err != nil {
+		return fmt.Errorf("setting index on queue for Workload: %w", err)
+	}
+	if err := indexer.IndexField(ctx, &kueue.Workload{}, WorkloadClusterQueueKey, IndexWorkloadClusterQueue); err != nil {
+		return fmt.Errorf("setting index on clusterQueue for Workload: %w", err)
+	}
+	if err := indexer.IndexField(ctx, &kueue.LocalQueue{}, QueueClusterQueueKey, IndexQueueClusterQueue); err != nil {
+		return fmt.Errorf("setting index on clusterQueue for localQueue: %w", err)
+	}
+	return nil
+}
diff --git a/pkg/queue/manager.go b/pkg/queue/manager.go
index 2126f2169..a13137879 100644
--- a/pkg/queue/manager.go
+++ b/pkg/queue/manager.go
@@ -28,8 +28,8 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
+	utilindexer "sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/metrics"
-	utilindexer "sigs.k8s.io/kueue/pkg/util/indexer"
 	"sigs.k8s.io/kueue/pkg/workload"
 )
 
@@ -169,8 +169,7 @@ func (m *Manager) AddLocalQueue(ctx context.Context, q *kueue.LocalQueue) error
 	}
 	for _, w := range workloads.Items {
 		w := w
-		// Checking queue name again because the field index is not available in tests.
-		if w.Spec.QueueName != q.Name || w.Spec.Admission != nil {
+		if w.Spec.Admission != nil {
 			continue
 		}
 		qImpl.AddOrUpdate(workload.NewInfo(&w))
@@ -552,15 +551,3 @@ func (m *Manager) reportPendingWorkloads(cqName string, cq ClusterQueue) {
 	}
 	metrics.ReportPendingWorkloads(cqName, active, inadmissible)
 }
-
-func SetupIndexes(ctx context.Context, indexer client.FieldIndexer) error {
-	err := indexer.IndexField(ctx, &kueue.Workload{}, utilindexer.WorkloadQueueKey, utilindexer.IndexWorkloadQueue)
-	if err != nil {
-		return fmt.Errorf("setting index on queue for Workload: %w", err)
-	}
-	err = indexer.IndexField(ctx, &kueue.LocalQueue{}, utilindexer.QueueClusterQueueKey, utilindexer.IndexQueueClusterQueue)
-	if err != nil {
-		return fmt.Errorf("setting index on clusterQueue for Queue: %w", err)
-	}
-	return nil
-}
diff --git a/pkg/util/indexer/indexer.go b/pkg/util/indexer/indexer.go
deleted file mode 100644
index 3cb0f7d2d..000000000
--- a/pkg/util/indexer/indexer.go
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-Copyright 2023 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package indexer
-
-import (
-	"sigs.k8s.io/controller-runtime/pkg/client"
-
-	kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
-)
-
-const (
-	WorkloadQueueKey        = "spec.queueName"
-	WorkloadClusterQueueKey = "spec.admission.clusterQueue"
-	QueueClusterQueueKey    = "spec.clusterQueue"
-)
-
-var (
-	IndexQueueClusterQueue = func(obj client.Object) []string {
-		q, ok := obj.(*kueue.LocalQueue)
-		if !ok {
-			return nil
-		}
-		return []string{string(q.Spec.ClusterQueue)}
-	}
-
-	IndexWorkloadQueue = func(obj client.Object) []string {
-		wl, ok := obj.(*kueue.Workload)
-		if !ok {
-			return nil
-		}
-		return []string{wl.Spec.QueueName}
-	}
-
-	IndexWorkloadClusterQueue = func(obj client.Object) []string {
-		wl, ok := obj.(*kueue.Workload)
-		if !ok {
-			return nil
-		}
-		if wl.Spec.Admission == nil {
-			return nil
-		}
-		return []string{string(wl.Spec.Admission.ClusterQueue)}
-	}
-)


Test patch:
diff --git a/pkg/util/testing/client.go b/pkg/util/testing/client.go
index 1f0664361..4080e0bb4 100644
--- a/pkg/util/testing/client.go
+++ b/pkg/util/testing/client.go
@@ -23,7 +23,7 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/client/fake"
 
 	kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
-	"sigs.k8s.io/kueue/pkg/util/indexer"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 )
 
 func NewFakeClient(objs ...client.Object) client.Client {
diff --git a/test/integration/controller/core/suite_test.go b/test/integration/controller/core/suite_test.go
index 073b4330b..14e5ec923 100644
--- a/test/integration/controller/core/suite_test.go
+++ b/test/integration/controller/core/suite_test.go
@@ -31,6 +31,7 @@ import (
 	"sigs.k8s.io/kueue/apis/kueue/webhooks"
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/test/integration/framework"
 	//+kubebuilder:scaffold:imports
@@ -65,10 +66,7 @@ var _ = ginkgo.AfterSuite(func() {
 })
 
 func managerSetup(mgr manager.Manager, ctx context.Context) {
-	err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer())
-	gomega.Expect(err).NotTo(gomega.HaveOccurred())
-
-	err = cache.SetupIndexes(ctx, mgr.GetFieldIndexer())
+	err := indexer.Setup(ctx, mgr.GetFieldIndexer())
 	gomega.Expect(err).NotTo(gomega.HaveOccurred())
 
 	failedWebhook, err := webhooks.Setup(mgr)
diff --git a/test/integration/controller/job/suite_test.go b/test/integration/controller/job/suite_test.go
index cf1f5ae7a..8a5c962b1 100644
--- a/test/integration/controller/job/suite_test.go
+++ b/test/integration/controller/job/suite_test.go
@@ -31,6 +31,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/constants"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/controller/workload/job"
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/pkg/scheduler"
@@ -73,10 +74,7 @@ func managerSetup(opts ...job.Option) framework.ManagerSetup {
 
 func managerAndSchedulerSetup(opts ...job.Option) framework.ManagerSetup {
 	return func(mgr manager.Manager, ctx context.Context) {
-		err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer())
-		gomega.Expect(err).NotTo(gomega.HaveOccurred())
-
-		err = cache.SetupIndexes(ctx, mgr.GetFieldIndexer())
+		err := indexer.Setup(ctx, mgr.GetFieldIndexer())
 		gomega.Expect(err).NotTo(gomega.HaveOccurred())
 
 		cCache := cache.New(mgr.GetClient())
diff --git a/test/integration/scheduler/podsready/suite_test.go b/test/integration/scheduler/podsready/suite_test.go
index 708235e1b..4f62ecd25 100644
--- a/test/integration/scheduler/podsready/suite_test.go
+++ b/test/integration/scheduler/podsready/suite_test.go
@@ -33,6 +33,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/constants"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	workloadjob "sigs.k8s.io/kueue/pkg/controller/workload/job"
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/pkg/scheduler"
@@ -63,10 +64,7 @@ func managerAndSchedulerSetupWithTimeout(mgr manager.Manager, ctx context.Contex
 		},
 	}
 
-	err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer())
-	gomega.Expect(err).NotTo(gomega.HaveOccurred())
-
-	err = cache.SetupIndexes(ctx, mgr.GetFieldIndexer())
+	err := indexer.Setup(ctx, mgr.GetFieldIndexer())
 	gomega.Expect(err).NotTo(gomega.HaveOccurred())
 
 	cCache := cache.New(mgr.GetClient(), cache.WithPodsReadyTracking(cfg.WaitForPodsReady.Enable))
diff --git a/test/integration/scheduler/suite_test.go b/test/integration/scheduler/suite_test.go
index 8a8ba4aa6..f97ee0fc8 100644
--- a/test/integration/scheduler/suite_test.go
+++ b/test/integration/scheduler/suite_test.go
@@ -32,6 +32,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/constants"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	workloadjob "sigs.k8s.io/kueue/pkg/controller/workload/job"
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/pkg/scheduler"
@@ -68,10 +69,7 @@ var _ = ginkgo.AfterSuite(func() {
 })
 
 func managerAndSchedulerSetup(mgr manager.Manager, ctx context.Context) {
-	err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer())
-	gomega.Expect(err).NotTo(gomega.HaveOccurred())
-
-	err = cache.SetupIndexes(ctx, mgr.GetFieldIndexer())
+	err := indexer.Setup(ctx, mgr.GetFieldIndexer())
 	gomega.Expect(err).NotTo(gomega.HaveOccurred())
 
 	cCache := cache.New(mgr.GetClient())
diff --git a/test/integration/webhook/v1alpha2/suite_test.go b/test/integration/webhook/v1alpha2/suite_test.go
index 6a639c2ca..7dd7a48db 100644
--- a/test/integration/webhook/v1alpha2/suite_test.go
+++ b/test/integration/webhook/v1alpha2/suite_test.go
@@ -31,6 +31,7 @@ import (
 	"sigs.k8s.io/kueue/apis/kueue/webhooks"
 	"sigs.k8s.io/kueue/pkg/cache"
 	"sigs.k8s.io/kueue/pkg/controller/core"
+	"sigs.k8s.io/kueue/pkg/controller/core/indexer"
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/test/integration/framework"
 	// +kubebuilder:scaffold:imports
@@ -55,10 +56,7 @@ var _ = ginkgo.BeforeSuite(func() {
 		CRDPath:     filepath.Join("..", "..", "..", "..", "config", "components", "crd", "bases"),
 		WebhookPath: filepath.Join("..", "..", "..", "..", "config", "components", "webhook"),
 		ManagerSetup: func(mgr manager.Manager, ctx context.Context) {
-			err := queue.SetupIndexes(ctx, mgr.GetFieldIndexer())
-			gomega.Expect(err).NotTo(gomega.HaveOccurred())
-
-			err = cache.SetupIndexes(ctx, mgr.GetFieldIndexer())
+			err := indexer.Setup(ctx, mgr.GetFieldIndexer())
 			gomega.Expect(err).NotTo(gomega.HaveOccurred())
 
 			failedWebhook, err := webhooks.Setup(mgr)