Skip to content

Correct Flavor Assignment in Pod Importer - #12924

Open
mszadkow wants to merge 5 commits into
kubernetes-sigs:mainfrom
epam:fix/importer-resource-to-flavor-mapping
Open

Correct Flavor Assignment in Pod Importer#12924
mszadkow wants to merge 5 commits into
kubernetes-sigs:mainfrom
epam:fix/importer-resource-to-flavor-mapping

Conversation

@mszadkow

@mszadkow mszadkow commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR improves behavior of Flavor Assignment in Pod Importer and test coverage for additional resources.

It introduces structured error handling for uncovered resources, keeps resource-to-flavor selection deterministic, and consolidates importer tests into a cleaner table-driven structure.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Importer: Improved pod importer admission by resolving flavors per requested resource.

Summary by CodeRabbit

  • Bug Fixes

    • Pod imports now assign admission flavors per requested resource, including mixed CPU/GPU workloads.
    • Imports reject missing flavors, uncovered resources, conflicting queue labels, empty requests, and unknown priority classes.
    • Invalid workloads no longer create resources or mutate the original Pod.
    • Admission retries now handle conflicts and cancellation reliably, with terminal errors after repeated failures.
    • Pod validation consistently checks queues, flavors, resource coverage, workload requests, and priority metadata.
  • Documentation

    • Updated importer validation guidance and the local dry-run command.
  • Tests

    • Added coverage for GPU workloads, queue conflicts, priority classes, missing flavors, uncovered resources, and deterministic errors.

@kubernetes-prow

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Jul 9, 2026
@netlify

netlify Bot commented Jul 9, 2026

Copy link
Copy Markdown

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 369bff7
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-kueue/deploys/6a7f149459fca80008fa25d8

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pod importer now resolves and validates ClusterQueue state, constructs workloads through shared validation, assigns flavors per requested resource, and centralizes retry handling. Tests cover GPU scenarios, uncovered resources, priority classes, invalid configurations, and deterministic errors.

Changes

Pod flavor assignment

Layer / File(s) Summary
Resource flavor lookup
cmd/importer/cache/cache.go, cmd/importer/cache/cache_test.go
ImportCache validates referenced flavors, caches resource mappings, and selects the first flavor for each covered resource.
ClusterQueue and workload validation
cmd/importer/pod/check.go, cmd/importer/pod/check_test.go, cmd/importer/pod/errors.go
Pod checks resolve queues, construct labeled workloads, reject empty requests, validate resource coverage, and resolve priority metadata.
Pod admission assignment
cmd/importer/pod/import.go, cmd/importer/pod/import_test.go
Import uses checked workloads, applies managed labels, centralizes retries, and passes per-resource flavors to admission.
Validation documentation
cmd/importer/README.md
Documentation covers ResourceFlavor references, resource coverage, workload construction, PriorityClass checks, and the corrected dry-run command.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PodImporter
  participant ImportCache
  participant Workload
  participant Admission
  PodImporter->>ImportCache: resolve queue and validate flavors
  ImportCache-->>PodImporter: return flavor assignments
  PodImporter->>Workload: construct validated workload
  Workload-->>PodImporter: return checked workload
  PodImporter->>Admission: submit workload with assignments
Loading

Possibly related PRs

Suggested labels: area/integrations

Suggested reviewers: kannon92, olekzabl, kshalot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the primary change: correcting flavor assignment in the pod importer.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 9, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from kannon92 and pajakd July 9, 2026 19:43
@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2026
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from becaf7f to 93e6229 Compare July 10, 2026 05:51
@mszadkow
mszadkow marked this pull request as ready for review July 10, 2026 05:52
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from kshalot and olekzabl July 10, 2026 05:52
@mszadkow

Copy link
Copy Markdown
Contributor Author

/test pull-kueue-test-e2e-baseline-main-1-36

@mszadkow

Copy link
Copy Markdown
Contributor Author

/cc @ivnovakov @vladikkuzn ptal

@kubernetes-prow

Copy link
Copy Markdown

@mszadkow: GitHub didn't allow me to request PR reviews from the following users: ptal.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @ivnovakov @vladikkuzn ptal

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ArangoGutierrez ArangoGutierrez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through this. The core fix is right: each requested resource is mapped to the flavor of the resource group that actually covers it, instead of assigning ResourceGroups[0].Flavors[0] to every resource. The two new table cases pin the exact per-resource flavors (cpu-flavor for cpu, gpu-flavor for gpu) and the uncovered-resource error, so they fail against the old code. That is the right discriminator.

Two questions before I approve, neither blocking:

  • Within a covered group you always take Flavors[0]. For a group with several flavors, say on-demand and spot, a pod actually running on spot gets imported as on-demand. Is first-flavor a deliberate simplification, or should the importer match the flavor to the pod's node labels? This is pre-existing behavior, I just want the choice recorded.
  • Re-import: if a pod was already imported and its resource is no longer covered by the target CQ, admitWorkload now returns ResourceNotCoveredError and the earlier admission is left in place. That is fine for a one-shot run, but worth confirming it is the intended behavior.

Scope and tests look good otherwise. Nits inline.

Following the repo AI policy: I used an AI assistant while preparing this review and verified the findings myself.

Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import.go Outdated
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 93e6229 to 530666d Compare July 20, 2026 13:50
@mszadkow

Copy link
Copy Markdown
Contributor Author

@ArangoGutierrez ptal

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/importer/pod/import_test.go (1)

260-316: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Consider migrating this new test to Ginkgo/Gomega.

While the use of table-driven testing perfectly aligns with the project preferences, this test relies on standard Go testing (t.Run, t.Fatalf). As per path instructions, ensure tests follow the existing Ginkgo/Gomega patterns in the project (e.g. using DescribeTable and Entry), unless this specific package is intentionally exempted from the project-wide Ginkgo usage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/importer/pod/import_test.go` around lines 260 - 316, Migrate
TestResourceFlavorForResource to the package’s existing Ginkgo/Gomega style,
replacing t.Run and t.Fatalf with a DescribeTable containing Entry cases and an
assertion for the expected flavor. Preserve all current test scenarios and
inputs, unless this package is explicitly exempt from the project-wide Ginkgo
usage.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/importer/pod/import_test.go`:
- Around line 260-316: Migrate TestResourceFlavorForResource to the package’s
existing Ginkgo/Gomega style, replacing t.Run and t.Fatalf with a DescribeTable
containing Entry cases and an assertion for the expected flavor. Preserve all
current test scenarios and inputs, unless this package is explicitly exempt from
the project-wide Ginkgo usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a78c8ad9-75d4-4d8f-b603-3557be77e362

📥 Commits

Reviewing files that changed from the base of the PR and between 93e6229 and 530666d.

📒 Files selected for processing (2)
  • cmd/importer/pod/import.go
  • cmd/importer/pod/import_test.go

@mszadkow

Copy link
Copy Markdown
Contributor Author

The plan is the follow up with exact flavor match.
@vladikkuzn @ivnovakov any further thoughts?

@vladikkuzn

Copy link
Copy Markdown
Contributor

The plan is the follow up with exact flavor match.
@vladikkuzn @ivnovakov any further thoughts?

Nothing from my side

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2026
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 530666d to 877d050 Compare July 27, 2026 07:57
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 27, 2026

@ArangoGutierrez ArangoGutierrez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass, now on 877d050.

The first-flavor question from the last round is resolved well: the behavior is documented on resourceFlavorForResource and pinned by a unit test, so the decision lives in the code rather than in a review thread. The new ErrCQNotFound guard and the nil-labels guard are both good additions. ResourceNotCoveredError is still exported.

One new issue is worth looking at before merge. Turning the uncovered-resource case into a hard failure is the right call, but the failure is not mirrored into the dry-run check, so --dry-run passes for exactly the pods the real import will reject, and it rejects them after it has already labeled the running pod. Details inline.

Following the repo AI policy: I used an AI assistant while preparing this review and verified the findings myself against the tree.

Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/pod/import_test.go Outdated
@mimowo

mimowo commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@mszadkow ptal

@mimowo

mimowo commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

/lgtm cancel
so that I get notified again with lgtm when the comments are addressed

@kubernetes-prow kubernetes-prow Bot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 7, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from dkaluza and mykysha August 7, 2026 08:44
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 9b692e0 to 08fe5cd Compare August 10, 2026 10:39
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
cmd/importer/pod/import.go (1)

112-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Return ctx.Err() instead of a new error.

waitForRetry reports every context termination as "context canceled". A deadline expiry is then indistinguishable from a cancellation, and callers cannot use errors.Is(err, context.Canceled).

♻️ Proposed refactor
 	select {
 	case <-ctx.Done():
-		return errors.New("context canceled")
+		return ctx.Err()
 	case <-t.C:
 		return nil
 	}

AI-assisted review. As per coding guidelines, "Disclose AI usage in pull request descriptions, comments, and issue filings."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/importer/pod/import.go` around lines 112 - 126, Update waitForRetry to
return ctx.Err() directly when ctx.Done() is selected instead of constructing a
new error, preserving the existing timeout and negative-timeout behavior.
cmd/importer/cache/cache_test.go (1)

30-99: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a test for ValidateClusterQueueFlavors.

The new cache exposes two memoized APIs. This file tests only FlavorsByResource. ValidateClusterQueueFlavors carries behavior that is easy to regress: it memoizes nil results, it memoizes errors, and it sorts flavor references so the error message is deterministic when several flavors are missing. None of that is pinned here. check_test.go reaches ErrCQInvalid only through Check, so it cannot detect a change in which flavor name the message reports.

Add a table-driven case set with: all flavors known, one missing flavor, two missing flavors asserting the lexicographically first name in the message, and a repeat call after mutating cq.Spec.ResourceGroups to confirm memoization.

Prefer table-driven tests for multiple scenarios, as per path instructions.

AI-assisted review. As per coding guidelines, "Disclose AI usage in pull request descriptions, comments, and issue filings."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/importer/cache/cache_test.go` around lines 30 - 99, Add a table-driven
TestValidateClusterQueueFlavors covering all-known flavors, one missing flavor,
and two missing flavors; assert successful validation, the expected error, and
the lexicographically first missing flavor in the multi-missing message. In each
case, call ValidateClusterQueueFlavors again after clearing
clusterQueue.Spec.ResourceGroups to verify both nil results and errors are
memoized.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/importer/pod/import.go`:
- Around line 229-238: Update the admission patch retry loop around
PatchAdmissionStatus to honor checkError’s reload result by re-reading the
current Workload and refreshing wl before retrying, then reapply the admission
update. Add bounded retry attempts with backoff for zero-timeout conflicts,
returning the final error when the limit is reached; follow the existing
addLabels retry pattern and preserve cancellation handling in waitForRetry.

---

Nitpick comments:
In `@cmd/importer/cache/cache_test.go`:
- Around line 30-99: Add a table-driven TestValidateClusterQueueFlavors covering
all-known flavors, one missing flavor, and two missing flavors; assert
successful validation, the expected error, and the lexicographically first
missing flavor in the multi-missing message. In each case, call
ValidateClusterQueueFlavors again after clearing
clusterQueue.Spec.ResourceGroups to verify both nil results and errors are
memoized.

In `@cmd/importer/pod/import.go`:
- Around line 112-126: Update waitForRetry to return ctx.Err() directly when
ctx.Done() is selected instead of constructing a new error, preserving the
existing timeout and negative-timeout behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ac4d82f-fad2-4a3c-9921-b9f40ba72f09

📥 Commits

Reviewing files that changed from the base of the PR and between 2236ced and 08fe5cd.

📒 Files selected for processing (8)
  • cmd/importer/README.md
  • cmd/importer/cache/cache.go
  • cmd/importer/cache/cache_test.go
  • cmd/importer/pod/check.go
  • cmd/importer/pod/check_test.go
  • cmd/importer/pod/errors.go
  • cmd/importer/pod/import.go
  • cmd/importer/pod/import_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/importer/README.md

Comment thread cmd/importer/pod/import.go Outdated
Comment thread cmd/importer/cache/cache.go Outdated
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 08fe5cd to 6cc6e53 Compare August 10, 2026 14:39
@mszadkow

Copy link
Copy Markdown
Contributor Author

@dkaluza all addressed, I have changed the approach and now all that can be is calculated at Load

@dkaluza dkaluza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't manage to go fully through the implementation today, will try to follow up tomorrow with the remaining files.

Comment thread cmd/importer/cache/cache.go Outdated
Comment thread cmd/importer/cache/cache.go Outdated
Comment thread cmd/importer/cache/cache.go Outdated
Comment thread cmd/importer/cache/cache.go Outdated
Comment thread cmd/importer/cache/cache_test.go Outdated
Comment thread cmd/importer/pod/check.go Outdated
Comment thread cmd/importer/README.md
@mimowo

mimowo commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

/approve
Leaving lgtm to @dkaluza. Thank you for working on that 👍
/cherrypick release-0.19
/cherrypick release-0.18

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@mimowo: once the present PR merges, I will cherry-pick it on top of release-0.18, release-0.19 in new PRs and assign them to you.

Details

In response to this:

/approve
Leaving lgtm to @dkaluza. Thank you for working on that 👍
/cherrypick release-0.19
/cherrypick release-0.18

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mimowo, mszadkow

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 12, 2026
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 6cc6e53 to 60395ca Compare August 13, 2026 08:04
@mszadkow
mszadkow force-pushed the fix/importer-resource-to-flavor-mapping branch from 60395ca to b8a4956 Compare August 13, 2026 08:25
in order to match with configurable Kueue behavior
@mszadkow

Copy link
Copy Markdown
Contributor Author

@dkaluza ptal :)

Comment thread cmd/importer/pod/check.go
if len(info.TotalRequests) == 0 {
return nil, fmt.Errorf("workload has no total requests: %w", cache.ErrPodInvalid)
}
flavors, err := flavorAssignmentsForRequests(importCache.FlavorsByResourceForClusterQueue(kueue.ClusterQueueReference(cq.Name)), cq.Name, info.TotalRequests[0].Requests)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming total requests from the workload info does not include excluded resources, is this right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the "filtering" happens inside workload.NewInfo()

wantError: &resourceNotCoveredError{Resource: corev1.ResourceName("nvidia.com/gpu"), ClusterQueue: "cq1"},
},
"excluded resource request is ignored": {
pods: []corev1.Pod{*basePodWrapper.Clone().Request(corev1.ResourceName("vendor.com/special"), "1").Obj()},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work?

Shouldn't this lead to ErrPodInvalid since there are no requests then?

Or there is an entry with empty requests and this is why this passes but flavors will be empty?
Is workload with empty flavors permitted? I'm guessing it is not. Is the current behavior intended?

Btw. can we have a test with ErrPodInvalid - I couldn't find it right now...

@mszadkow mszadkow Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this lead to ErrPodInvalid since there are no requests then?

No. ErrPodInvalid is only returned when len(info.TotalRequests) == 0, i.e. when the workload has zero PodSets. It is not returned when a PodSet exists but its Requests map is empty.

Or there is an entry with empty requests and this is why this passes but flavors will be empty?

Yes — this is exactly what happens. The pod becomes one PodSet, so TotalRequests has length 1 (len(info.TotalRequests) == 1, not 0). That one entry's Requests map is empty because the only requested resource (vendor.com/special) was dropped by the exclusion filter. So the ErrPodInvalid check is skipped, flavorAssignmentsForRequests iterates over zero requests, and it returns an empty flavors map with no error.

Is workload with empty flavors permitted?

It's a hard question, it's not directly forbidden - a Workload can be admitted with an empty Flavors map for a PodSet, but it varies with outcome.

Btw. can we have a test with ErrPodInvalid - I couldn't find it right now...

Yes, but it needs a case where wl.Spec.PodSets is empty, which a single plain pod cannot produce (a pod always yields exactly one PodSet, regardless of what it requests). To hit ErrPodInvalid you'd need to go through ConstructComposableWorkload with an input that results in zero constructed PodSets

However, it seems to be a dead code condition anyways.
I will drop it
AI suggests:
Importer is a pod-by-pod tool, entirely blind to Kueue's pod-group feature.
Each Pod is treated in isolation via pod.FromObject (which never sets isGroup), which is precisely why ConstructComposableWorkload always takes the single-pod branch and always yields exactly one PodSet.
The ErrPodInvalid (zero-PodSets) guard in check.go:138-140 isn't guarding against some importer-specific edge case — it's dead code for a more general path that the importer's current single-pod design never exercises.

Comment thread cmd/importer/pod/import.go Outdated
// waitForRetry blocks for timeout, or returns early with an error if ctx is
// done first. A negative timeout returns immediately.
func waitForRetry(ctx context.Context, timeout time.Duration) error {
if timeout < 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if timeout < 0 {
if timeout <= 0 {

Maybe it is worth it to return immediately for non-positive timeout?

IIUC 0 still means retry immediately

Comment thread cmd/importer/pod/import.go Outdated
}

// waitForRetry blocks for timeout, or returns early with an error if ctx is
// done first. A negative timeout returns immediately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// done first. A negative timeout returns immediately.
// done first. A non-positive timeout returns immediately.

for range maxAttempts {
err := workloadpatching.PatchAdmissionStatus(ctx, c, wl, realClock, update, workloadpatching.WithForceApply())
retry, _, timeout := checkError(err)
retry, reload, timeout := checkError(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if PatchAdmissionStatus returned nil? Is it handled gracefully by checkError?

This is not trivial right now for me that this code returns nil if there was no error in status patching at all.
Can we add an explicit return nil when error is nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I will add it

Comment thread cmd/importer/pod/import_test.go Outdated
}
}

func TestFlavorAssignmentsForRequests(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this test is in import_test when tested function is not in import.go?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, thanks

@dkaluza

dkaluza commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

@mszadkow reviewed, generally looks good, but I'm still concerned about this ErrPodInvalid, see #12924 (comment)

* remove dead condition - due to nature of importer
* minor fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants