Skip to content

Reject incomplete image specs in ImagePath - #2682

Open
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:imagepath-validation
Open

Reject incomplete image specs in ImagePath#2682
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:imagepath-validation

Conversation

@abrarshivani

Copy link
Copy Markdown
Contributor

Description

ImagePath (internal/image) and its duplicate imagePath (api/nvidia/v1, used by v1.ImagePath) build a component's image reference from the CR's repository/image/version fields. When repository or version is set (so the CR branch is taken) but repository or image is empty, they previously concatenated the parts into a structurally invalid reference"/image:tag", "repo/:tag", or "/@sha256:..." — which then failed much later at image-pull time with an opaque error.

This change makes both functions fail fast with a clear error when repository or image is empty in that branch:

invalid image specification: both repository and image must be set (repository=%q, image=%q, version=%q)

The kbld/carvel passthrough (repository and version both empty → image used verbatim) and the env-var fallback are unchanged.

Tests

  • internal/image: TestImagePath_ValidSpec (fully-specified specs still resolve) and TestImagePath_InvalidSpec (incomplete specs are rejected, and an env value does not rescue a partial CR spec).
  • api/nvidia/v1: TestImagePath covering valid, kbld, incomplete-spec and unsupported-type paths.

Split out of #2656 (test-coverage PR) per review, so the validation logic is tracked on its own. Affected suites (api, controllers, internal/state) pass unchanged — no caller relied on the malformed-path behavior.

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Lint checks passing (make lint)
  • Generated assets in-sync (make validate-generated-assets)
  • Go mod artifacts in-sync (make validate-modules)
  • Test cases are added for new code paths

Testing

go test ./internal/image/... ./api/nvidia/... ./internal/state/... ./controllers/...
golangci-lint run ./internal/image/... ./api/nvidia/v1/...   # 0 issues (GOOS=linux)

Comment thread api/nvidia/v1/clusterpolicy_types.go Outdated
@abrarshivani
abrarshivani force-pushed the imagepath-validation branch from 331b892 to 4c09df4 Compare July 27, 2026 18:37
@abrarshivani
abrarshivani marked this pull request as ready for review July 27, 2026 18:41
Comment thread api/nvidia/v1/clusterpolicy_types.go Outdated
Comment thread internal/image/image.go Outdated
@tariq1890
tariq1890 enabled auto-merge July 27, 2026 20:02
@tariq1890
tariq1890 disabled auto-merge July 27, 2026 20:02
@tariq1890

Copy link
Copy Markdown
Contributor

Can you squash the commit history?

@abrarshivani
abrarshivani force-pushed the imagepath-validation branch from 685eb4a to 7455df7 Compare July 27, 2026 20:07
Comment thread api/nvidia/v1/clusterpolicy_types.go Outdated
@abrarshivani

Copy link
Copy Markdown
Contributor Author

@rahulait PTAL. I have addressed the comments.

When a CR component sets repository or version but leaves repository, image or
version empty, ImagePath/imagePath previously concatenated the parts into a
structurally invalid reference such as "/image:tag", "repo/:tag" or
"repo/image:", which only failed much later at image pull with an opaque
error.

Validate the branch that builds "repo/image:tag"/"@digest" and return a
clear error when repository, image or version is empty, in both
image.ImagePath (internal/image) and the duplicated api/nvidia/v1 imagePath
used by v1.ImagePath. The error uses %s (not %q) so the field values stay
readable in the operator's JSON logs. The kbld/carvel passthrough (repository
and version both empty) and the env-var fallback are unchanged.

Add tests covering the valid tag/digest, kbld passthrough, env fallback,
all-empty error, incomplete-spec and unsupported-type paths.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
@abrarshivani
abrarshivani force-pushed the imagepath-validation branch from 2ea4504 to 7dbfffc Compare July 27, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants