Skip to content

[Bug] resource.IsZero returns false for non-empty zero-valued ResourceLists #14545

Description

@junnhwan

What happened:

pkg/util/resource.IsZero returns false for any non-empty corev1.ResourceList, including a list whose quantities are all zero.

The implementation at pkg/util/resource/resource.go:117-129 returns false immediately when len(rl) != 0, so the subsequent per-quantity zero check is unreachable for non-empty lists.

What you expected to happen:

A ResourceList containing only zero-valued quantities should be treated as zero.

Expected results:

  • Empty list: true
  • Zero-only list, for example {cpu: 0}: true
  • Mixed list, for example {cpu: 0, memory: 1Gi}: false

How to reproduce it (as minimally and precisely as possible):

Using the current Kueue source:

empty := corev1.ResourceList{}
zero := corev1.ResourceList{
    corev1.ResourceCPU: resource.MustParse("0"),
}
mixed := corev1.ResourceList{
    corev1.ResourceCPU:    resource.MustParse("0"),
    corev1.ResourceMemory: resource.MustParse("1Gi"),
}

fmt.Println(kueueresource.IsZero(empty)) // true
fmt.Println(kueueresource.IsZero(zero))  // false
fmt.Println(kueueresource.IsZero(mixed)) // false

The expected result for zero is true.

go test ./pkg/util/resource currently passes, but the existing tests do not cover this behavior.

Anything else we need to know?:

A repository-wide source search did not find a current Kueue production caller of this exported helper. Please confirm whether the intended contract is that a non-empty ResourceList containing only zero-valued quantities should be considered zero before a focused fix and regression test are prepared.

This issue was prepared with AI assistance. The source location and reproduction were verified locally.

Environment:

  • Kubernetes version: N/A
  • Kueue version: a081b4f-dirty
  • Cloud provider or hardware configuration: N/A
  • OS: macOS
  • Kernel: N/A
  • Install tools: Go toolchain
  • Others: N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions