Repository: kubernetes-sigs/kueue
Pull request #115 (2022-03-11 15:01:15)

Kueue.ClusterQueue.Status Add pendingWorkloads
Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>

<!--  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 feature
/kind api-change
<!--
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`_*
-->
Remaining implementation for #7

#### Special notes for your reviewer:
 Add pendingWrkloads to Kueue.ClusterQueue.Status

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/115#" title="Author self-approved">ArangoGutierrez</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **alculquicondor** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @alculquicondor` in a comment when ready.

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":["alculquicondor"]} -->
ArangoGutierrez: typo on title
/retitle Kueue.ClusterQueue.Status Add pendingWorkloads
ArangoGutierrez: /assign @alculquicondor 
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/115#" title="Author self-approved">ArangoGutierrez</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please ask for approval from **alculquicondor** after the PR has been reviewed.

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":["alculquicondor"]} -->
k8s-ci-robot: @ArangoGutierrez: 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 | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-verify-main/1502361608620347392) | true | `/test pull-kueue-verify-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=115). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AArangoGutierrez). 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: @ArangoGutierrez: 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 | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-verify-main/1502361608620347392) | true | `/test pull-kueue-verify-main`
pull-kueue-test-integration-main | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-test-integration-main/1502361608582598656) | true | `/test pull-kueue-test-integration-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=115). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AArangoGutierrez). 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 -->
ArangoGutierrez: /retest-required
k8s-ci-robot: @ArangoGutierrez: 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 | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-verify-main/1502361608620347392) | true | `/test pull-kueue-verify-main`
pull-kueue-test-integration-main | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-test-integration-main/1502362170938101760) | true | `/test pull-kueue-test-integration-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=115). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AArangoGutierrez). 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: @ArangoGutierrez: 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-test-integration-main | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-test-integration-main/1502362170938101760) | true | `/test pull-kueue-test-integration-main`
pull-kueue-verify-main | 93e41f58770448131b4455d07d6ca6d7de4563f7 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-verify-main/1502362170980044800) | true | `/test pull-kueue-verify-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=115). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AArangoGutierrez). 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: @ArangoGutierrez: 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 | b3c2c064eeb0ed2139e5931495c11bb3de85133f | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kueue/115/pull-kueue-verify-main/1502385475455815680) | true | `/test pull-kueue-verify-main`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=kueue&pr=115). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AArangoGutierrez). 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 -->

Patch:
diff --git a/api/v1alpha1/clusterqueue_types.go b/api/v1alpha1/clusterqueue_types.go
index 7c999dacd..c0899fc8a 100644
--- a/api/v1alpha1/clusterqueue_types.go
+++ b/api/v1alpha1/clusterqueue_types.go
@@ -264,7 +264,11 @@ type ClusterQueueStatus struct {
 	// workloads assigned to this clusterQueue.
 	UsedResources UsedResources `json:"usedResources,omitempty"`
 
-	// AdmittedWorkloads is the number of workloads currently assigned to this
+	// PendingWorkloads is the number of workloads currently waiting to be
+	// admitted to this clusterQueue.
+	PendingWorkloads int32 `json:"pendingdWorkloads,omitempty"`
+
+	// AdmittedWorkloads is the number of workloads currently admitted to this
 	// clusterQueue.
 	AdmittedWorkloads int32 `json:"admittedWorkloads,omitempty"`
 }
diff --git a/api/v1alpha1/queue_types.go b/api/v1alpha1/queue_types.go
index 94b175fa2..9e7f3e49b 100644
--- a/api/v1alpha1/queue_types.go
+++ b/api/v1alpha1/queue_types.go
@@ -33,7 +33,6 @@ type ClusterQueueReference string
 type QueueStatus struct {
 	// PendingWorkloads is the number of workloads currently admitted to this
 	// queue not yet admitted to a ClusterQueue.
-	// +optional
 	PendingWorkloads int32 `json:"pendingWorkloads"`
 }
 
diff --git a/config/crd/bases/kueue.x-k8s.io_clusterqueues.yaml b/config/crd/bases/kueue.x-k8s.io_clusterqueues.yaml
index 9dd809e57..6db135b72 100644
--- a/config/crd/bases/kueue.x-k8s.io_clusterqueues.yaml
+++ b/config/crd/bases/kueue.x-k8s.io_clusterqueues.yaml
@@ -285,7 +285,12 @@ spec:
             properties:
               admittedWorkloads:
                 description: AdmittedWorkloads is the number of workloads currently
-                  assigned to this clusterQueue.
+                  admitted to this clusterQueue.
+                format: int32
+                type: integer
+              pendingdWorkloads:
+                description: PendingWorkloads is the number of workloads currently
+                  waiting to be admitted to this clusterQueue.
                 format: int32
                 type: integer
               usedResources:
diff --git a/config/crd/bases/kueue.x-k8s.io_queues.yaml b/config/crd/bases/kueue.x-k8s.io_queues.yaml
index cd468bf46..743b1ccae 100644
--- a/config/crd/bases/kueue.x-k8s.io_queues.yaml
+++ b/config/crd/bases/kueue.x-k8s.io_queues.yaml
@@ -48,6 +48,8 @@ spec:
                   admitted to this queue not yet admitted to a ClusterQueue.
                 format: int32
                 type: integer
+            required:
+            - pendingWorkloads
             type: object
         type: object
     served: true
diff --git a/pkg/controller/core/clusterqueue_controller.go b/pkg/controller/core/clusterqueue_controller.go
index 2c6d15bdc..4990d345c 100644
--- a/pkg/controller/core/clusterqueue_controller.go
+++ b/pkg/controller/core/clusterqueue_controller.go
@@ -20,6 +20,7 @@ import (
 	"context"
 
 	"github.com/go-logr/logr"
+
 	"k8s.io/apimachinery/pkg/api/equality"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/client-go/util/workqueue"
@@ -67,21 +68,18 @@ func (r *ClusterQueue) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
 	ctx = ctrl.LoggerInto(ctx, log)
 	log.V(2).Info("Reconciling ClusterQueue")
 
-	usage, workloads, err := r.cache.Usage(&cqObj)
+	status, err := r.Status(&cqObj)
 	if err != nil {
-		log.Error(err, "Failed getting usage from cache")
-		// This is likely because the cluster queue was recently removed,
-		// but we didn't process that event yet.
+		log.Error(err, "Failed getting status from cache")
 		return ctrl.Result{}, err
 	}
-	// Shallow copy enough for now.
-	oldStatus := cqObj.Status
-	cqObj.Status.UsedResources = usage
-	cqObj.Status.AdmittedWorkloads = int32(workloads)
-	if !equality.Semantic.DeepEqual(oldStatus, cqObj.Status) {
-		err = r.client.Status().Update(ctx, &cqObj)
+
+	if !equality.Semantic.DeepEqual(status, cqObj.Status) {
+		cqObj.Status = status
+		err := r.client.Status().Update(ctx, &cqObj)
 		return ctrl.Result{}, client.IgnoreNotFound(err)
 	}
+
 	return ctrl.Result{}, nil
 }
 
@@ -188,3 +186,19 @@ func (r *ClusterQueue) SetupWithManager(mgr ctrl.Manager) error {
 		WithEventFilter(r).
 		Complete(r)
 }
+
+func (r *ClusterQueue) Status(cq *kueue.ClusterQueue) (kueue.ClusterQueueStatus, error) {
+	usage, workloads, err := r.cache.Usage(cq)
+	if err != nil {
+		r.log.Error(err, "Failed getting usage from cache")
+		// This is likely because the cluster queue was recently removed,
+		// but we didn't process that event yet.
+		return kueue.ClusterQueueStatus{}, err
+	}
+
+	return kueue.ClusterQueueStatus{
+		UsedResources:     usage,
+		AdmittedWorkloads: int32(workloads),
+		PendingWorkloads:  r.qManager.Pending(cq),
+	}, nil
+}
diff --git a/pkg/controller/core/queue_controller.go b/pkg/controller/core/queue_controller.go
index ecdf4184d..471ff9bf0 100644
--- a/pkg/controller/core/queue_controller.go
+++ b/pkg/controller/core/queue_controller.go
@@ -64,16 +64,14 @@ func (r *QueueReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
 	ctx = ctrl.LoggerInto(ctx, log)
 	log.V(2).Info("Reconciling Queue")
 
-	// Shallow copy enough for now.
-	oldStatus := queueObj.Status
-
-	pending, err := r.queues.PendingWorkloads(&queueObj)
+	pendingJobs, err := r.queues.Status(&queueObj)
 	if err != nil {
 		r.log.Error(err, "Failed to retrieve queue status")
 		return ctrl.Result{}, err
 	}
 
-	queueObj.Status.PendingWorkloads = pending
+	oldStatus := queueObj.Status
+	queueObj.Status.PendingWorkloads = int32(pendingJobs)
 	if !equality.Semantic.DeepEqual(oldStatus, queueObj.Status) {
 		err := r.client.Status().Update(ctx, &queueObj)
 		return ctrl.Result{}, client.IgnoreNotFound(err)
diff --git a/pkg/queue/manager.go b/pkg/queue/manager.go
index d5e24d1ad..827876fe1 100644
--- a/pkg/queue/manager.go
+++ b/pkg/queue/manager.go
@@ -36,9 +36,9 @@ const (
 )
 
 var (
-	errQueueDoesNotExist         = errors.New("queue doesn't exist")
-	errClusterQueueDoesNotExist  = errors.New("clusterQueue doesn't exist")
-	errClusterQueueAlreadyExists = errors.New("clusterQueue already exists")
+	queueDoesNotExistErr         = errors.New("queue doesn't exist")
+	clusterQueueDoesNotExistErr  = errors.New("clusterQueue doesn't exist")
+	clusterQueueAlreadyExistsErr = errors.New("clusterQueue already exists")
 )
 
 type Manager struct {
@@ -65,7 +65,7 @@ func (m *Manager) AddClusterQueue(ctx context.Context, cq *kueue.ClusterQueue) e
 	defer m.Unlock()
 
 	if _, ok := m.clusterQueues[cq.Name]; ok {
-		return errClusterQueueAlreadyExists
+		return clusterQueueAlreadyExistsErr
 	}
 	cqImpl := newClusterQueue(cq)
 	m.clusterQueues[cq.Name] = cqImpl
@@ -99,7 +99,7 @@ func (m *Manager) UpdateClusterQueue(cq *kueue.ClusterQueue) error {
 	defer m.Unlock()
 	cqImpl, ok := m.clusterQueues[cq.Name]
 	if !ok {
-		return errClusterQueueDoesNotExist
+		return clusterQueueDoesNotExistErr
 	}
 	// TODO(#8): recreate heap based on a change of queueing policy.
 	cqImpl.update(cq)
@@ -152,7 +152,7 @@ func (m *Manager) UpdateQueue(q *kueue.Queue) error {
 	defer m.Unlock()
 	qImpl, ok := m.queues[Key(q)]
 	if !ok {
-		return errQueueDoesNotExist
+		return queueDoesNotExistErr
 	}
 	if qImpl.ClusterQueue != string(q.Spec.ClusterQueue) {
 		oldCQ := m.clusterQueues[qImpl.ClusterQueue]
@@ -183,16 +183,19 @@ func (m *Manager) DeleteQueue(q *kueue.Queue) {
 	delete(m.queues, key)
 }
 
-func (m *Manager) PendingWorkloads(q *kueue.Queue) (int32, error) {
+func (m *Manager) Status(q *kueue.Queue) (int, error) {
 	m.RLock()
 	defer m.RUnlock()
-
-	qImpl, ok := m.queues[Key(q)]
-	if !ok {
-		return 0, errQueueDoesNotExist
+	if q := m.queues[Key(q)]; q != nil {
+		return len(q.items), nil
 	}
+	return 0, queueDoesNotExistErr
+}
 
-	return int32(len(qImpl.items)), nil
+func (m *Manager) Pending(cq *kueue.ClusterQueue) int32 {
+	m.RLock()
+	defer m.RUnlock()
+	return int32(len(m.clusterQueues[cq.Name].heap.heap))
 }
 
 // AddOrUpdateWorkload adds or updates workload to the corresponding queue.


Test patch:
diff --git a/pkg/queue/manager_test.go b/pkg/queue/manager_test.go
index a4ccc0903..acb6ce407 100644
--- a/pkg/queue/manager_test.go
+++ b/pkg/queue/manager_test.go
@@ -272,15 +272,7 @@ func TestStatus(t *testing.T) {
 			},
 			Spec: kueue.QueuedWorkloadSpec{QueueName: "foo"},
 		},
-		{
-			ObjectMeta: metav1.ObjectMeta{
-				Name:              "d",
-				CreationTimestamp: metav1.NewTime(now),
-			},
-			Spec: kueue.QueuedWorkloadSpec{QueueName: "foo"},
-		},
 	}
-
 	manager := NewManager(fake.NewClientBuilder().WithScheme(scheme).Build())
 	for _, q := range queues {
 		if err := manager.AddQueue(ctx, &q); err != nil {
@@ -294,12 +286,12 @@ func TestStatus(t *testing.T) {
 
 	cases := map[string]struct {
 		queue      *kueue.Queue
-		wantStatus int32
+		wantStatus int
 		wantErr    error
 	}{
 		"foo": {
 			queue:      &queues[0],
-			wantStatus: 3,
+			wantStatus: 2,
 			wantErr:    nil,
 		},
 		"bar": {
@@ -310,12 +302,12 @@ func TestStatus(t *testing.T) {
 		"fake": {
 			queue:      &kueue.Queue{ObjectMeta: metav1.ObjectMeta{Name: "fake"}},
 			wantStatus: 0,
-			wantErr:    errQueueDoesNotExist,
+			wantErr:    queueDoesNotExistErr,
 		},
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			status, err := manager.PendingWorkloads(tc.queue)
+			status, err := manager.Status(tc.queue)
 			if err != tc.wantErr {
 				t.Errorf("Should have failed with: %s", err)
 			}
diff --git a/test/integration/controller/core/clusterqueue_controller_test.go b/test/integration/controller/core/clusterqueue_controller_test.go
index b9a3289df..b81d19974 100644
--- a/test/integration/controller/core/clusterqueue_controller_test.go
+++ b/test/integration/controller/core/clusterqueue_controller_test.go
@@ -45,6 +45,7 @@ var _ = ginkgo.Describe("ClusterQueue controller", func() {
 	var (
 		ns            *corev1.Namespace
 		clusterQueue  *kueue.ClusterQueue
+		queue         *kueue.Queue
 		emptyCqStatus kueue.ClusterQueueStatus
 	)
 
@@ -70,6 +71,8 @@ var _ = ginkgo.Describe("ClusterQueue controller", func() {
 				Flavor(testing.MakeFlavor(flavorModelA, "5").Ceiling("10").Obj()).
 				Flavor(testing.MakeFlavor(flavorModelB, "5").Ceiling("10").Obj()).Obj()).Obj()
 		gomega.Expect(k8sClient.Create(ctx, clusterQueue)).To(gomega.Succeed())
+		queue = testing.MakeQueue("queue", ns.Name).ClusterQueue(clusterQueue.Name).Obj()
+		gomega.Expect(k8sClient.Create(ctx, queue)).To(gomega.Succeed())
 		emptyCqStatus = kueue.ClusterQueueStatus{
 			AdmittedWorkloads: 0,
 			UsedResources: kueue.UsedResources{
@@ -91,17 +94,17 @@ var _ = ginkgo.Describe("ClusterQueue controller", func() {
 
 	ginkgo.It("Should update status when workloads are assigned and finish", func() {
 		workloads := []*kueue.QueuedWorkload{
-			testing.MakeQueuedWorkload("one", ns.Name).
+			testing.MakeQueuedWorkload("one", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "2").Request(resourceGPU, "2").Obj(),
-			testing.MakeQueuedWorkload("two", ns.Name).
+			testing.MakeQueuedWorkload("two", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "3").Request(resourceGPU, "3").Obj(),
-			testing.MakeQueuedWorkload("three", ns.Name).
+			testing.MakeQueuedWorkload("three", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "1").Request(resourceGPU, "1").Obj(),
-			testing.MakeQueuedWorkload("four", ns.Name).
+			testing.MakeQueuedWorkload("four", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "1").Request(resourceGPU, "1").Obj(),
-			testing.MakeQueuedWorkload("five", ns.Name).
+			testing.MakeQueuedWorkload("five", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "1").Request(resourceGPU, "1").Obj(),
-			testing.MakeQueuedWorkload("six", ns.Name).
+			testing.MakeQueuedWorkload("six", ns.Name).Queue(queue.Name).
 				Request(corev1.ResourceCPU, "1").Request(resourceGPU, "1").Obj(),
 		}
 
@@ -115,7 +118,7 @@ var _ = ginkgo.Describe("ClusterQueue controller", func() {
 			return updatedCq.Status
 		}, framework.Timeout, framework.Interval).Should(testing.Equal(emptyCqStatus))
 
-		ginkgo.By("Assigning workloads")
+		ginkgo.By("Admitting workloads")
 		admissions := []*kueue.Admission{
 			testing.MakeAdmission(clusterQueue.Name).
 				Flavor(corev1.ResourceCPU, flavorOnDemand).Flavor(resourceGPU, flavorModelA).Obj(),
@@ -138,6 +141,7 @@ var _ = ginkgo.Describe("ClusterQueue controller", func() {
 			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(clusterQueue), &updatedCQ)).To(gomega.Succeed())
 			return updatedCQ.Status
 		}, framework.Timeout, framework.Interval).Should(testing.Equal(kueue.ClusterQueueStatus{
+			PendingWorkloads:  1,
 			AdmittedWorkloads: 4,
 			UsedResources: kueue.UsedResources{
 				corev1.ResourceCPU: {
diff --git a/test/integration/controller/core/queue_controller_test.go b/test/integration/controller/core/queue_controller_test.go
index 3a127d050..c8fe4500a 100644
--- a/test/integration/controller/core/queue_controller_test.go
+++ b/test/integration/controller/core/queue_controller_test.go
@@ -33,7 +33,7 @@ import (
 var _ = ginkgo.Describe("Queue controller", func() {
 	var (
 		ns           *corev1.Namespace
-		queue        *kueue.Queue
+		Queue        *kueue.Queue
 		clusterQueue *kueue.ClusterQueue
 	)
 
@@ -51,26 +51,26 @@ var _ = ginkgo.Describe("Queue controller", func() {
 			Resource(testing.MakeResource(resourceGPU).
 				Flavor(testing.MakeFlavor(flavorModelA, "5").Ceiling("10").Obj()).
 				Flavor(testing.MakeFlavor(flavorModelB, "5").Ceiling("10").Obj()).Obj()).Obj()
-		queue = testing.MakeQueue("queue", ns.Name).ClusterQueue(clusterQueue.Name).Obj()
-		gomega.Expect(k8sClient.Create(ctx, queue)).To(gomega.Succeed())
+		Queue = testing.MakeQueue("queue", ns.Name).ClusterQueue("cluster-queue").Obj()
+		gomega.Expect(k8sClient.Create(ctx, Queue)).To(gomega.Succeed())
 	})
 
 	ginkgo.AfterEach(func() {
-		gomega.Expect(framework.DeleteQueue(ctx, k8sClient, queue)).To(gomega.Succeed())
+		gomega.Expect(framework.DeleteQueue(ctx, k8sClient, Queue)).To(gomega.Succeed())
 		gomega.Expect(framework.DeleteClusterQueue(ctx, k8sClient, clusterQueue)).To(gomega.Succeed())
 	})
 
 	ginkgo.It("Should update status when workloads are created", func() {
 		workloads := []*kueue.QueuedWorkload{
 			testing.MakeQueuedWorkload("one", ns.Name).
-				Queue(queue.Name).
-				Request(corev1.ResourceCPU, "2").Obj(),
+				Queue(Queue.Name).
+				Request(corev1.ResourceCPU, "2").Request(resourceGPU, "1").Obj(),
 			testing.MakeQueuedWorkload("two", ns.Name).
-				Queue(queue.Name).
-				Request(corev1.ResourceCPU, "3").Obj(),
+				Queue(Queue.Name).
+				Request(corev1.ResourceCPU, "3").Request(resourceGPU, "1").Obj(),
 			testing.MakeQueuedWorkload("three", ns.Name).
-				Queue(queue.Name).
-				Request(corev1.ResourceCPU, "1").Obj(),
+				Queue(Queue.Name).
+				Request(corev1.ResourceCPU, "1").Request(resourceGPU, "1").Obj(),
 		}
 
 		ginkgo.By("Creating workloads")
@@ -79,22 +79,10 @@ var _ = ginkgo.Describe("Queue controller", func() {
 		}
 		gomega.Eventually(func() kueue.QueueStatus {
 			var updatedQueue kueue.Queue
-			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(queue), &updatedQueue)).To(gomega.Succeed())
+			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(Queue), &updatedQueue)).To(gomega.Succeed())
 			return updatedQueue.Status
 		}, framework.Timeout, framework.Interval).Should(testing.Equal(kueue.QueueStatus{PendingWorkloads: 3}))
 
-		ginkgo.By("Admitting workloads")
-		for _, w := range workloads {
-			w.Spec.Admission = testing.MakeAdmission(clusterQueue.Name).
-				Flavor(corev1.ResourceCPU, flavorOnDemand).Obj()
-			gomega.Expect(k8sClient.Update(ctx, w)).To(gomega.Succeed())
-		}
-		gomega.Eventually(func() kueue.QueueStatus {
-			var updatedQueue kueue.Queue
-			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(queue), &updatedQueue)).To(gomega.Succeed())
-			return updatedQueue.Status
-		}, framework.Timeout, framework.Interval).Should(testing.Equal(kueue.QueueStatus{PendingWorkloads: 0}))
-
 		ginkgo.By("Finishing workloads")
 		for _, w := range workloads {
 			w.Status.Conditions = append(w.Status.Conditions, kueue.QueuedWorkloadCondition{
@@ -105,7 +93,7 @@ var _ = ginkgo.Describe("Queue controller", func() {
 		}
 		gomega.Eventually(func() kueue.QueueStatus {
 			var updatedQueue kueue.Queue
-			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(queue), &updatedQueue)).To(gomega.Succeed())
+			gomega.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(Queue), &updatedQueue)).To(gomega.Succeed())
 			return updatedQueue.Status
 		}, framework.Timeout, framework.Interval).Should(testing.Equal(kueue.QueueStatus{}))
 	})