Skip to content

Conversation

RayyanSeliya
Copy link
Contributor

Changes

  • 🐛 Fix confusing UX when using conflicting --image and --registry flags
  • 🧹 Implement 2-layer error system for image/registry validation
  • 🎁 Add clear guidance for resolving flag conflicts

/kind enhancement

Fixes #3065

Solution:

Implement a 2-layer error system:

  • Layer 1 (Technical): Return ErrConflictingImageAndRegistry from validation in pkg/functions/errors.go
  • Layer 2 (CLI): Catch the error in cmd/build.go and cmd/deploy.go and wrap with user-friendly guidance

Implementation Details:

  • Add validation logic in buildConfig.Validate() and deployConfig.Validate() methods
  • Use strings.HasPrefix() to check if image starts with registry (allows subnamespaces)
  • Maintain backward compatibility with existing test cases
  • Ensure error messages are consistent between build and deploy commands

Release Note

func build and func deploy commands now validate conflicting --image and --registry flags before starting the build process, providing clear error messages and actionable guidance instead of misleading build failures.

…between image and registry with different specified resgistry

Signed-off-by: RayyanSeliya <[email protected]>
Copy link

knative-prow bot commented Oct 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: RayyanSeliya
Once this PR has been reviewed and has the lgtm label, please assign salaboy for approval. For more information see the Code Review Process.

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

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

Copy link

knative-prow bot commented Oct 4, 2025

Hi @RayyanSeliya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@knative-prow knative-prow bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 4, 2025
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.60%. Comparing base (7cb458e) to head (73b89f5).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/build.go 0.00% 26 Missing and 1 partial ⚠️
cmd/deploy.go 0.00% 18 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7cb458e) and HEAD (73b89f5). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (7cb458e) HEAD (73b89f5)
1 0
unit-tests 3 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3066       +/-   ##
===========================================
- Coverage   56.94%   40.60%   -16.34%     
===========================================
  Files         133      116       -17     
  Lines       17094    16582      -512     
===========================================
- Hits         9734     6733     -3001     
- Misses       6451     9034     +2583     
+ Partials      909      815       -94     
Flag Coverage Δ
e2e-tests 40.60% <0.00%> (+1.19%) ⬆️
unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RayyanSeliya
Copy link
Contributor Author

I think i am missing some edge cases @gauron99 @lkingland please point out if any the test are still failing :(

@gauron99
Copy link
Contributor

gauron99 commented Oct 4, 2025

im gonna take a look tomorrow

@RayyanSeliya
Copy link
Contributor Author

Sure no worries !! Good night !

Copy link
Contributor

@gauron99 gauron99 left a comment

Choose a reason for hiding this comment

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

perhaps we could simply check that -registry and --image are not given together at all? Image takes precedence now which is correct. But we want to avoid having the need to remove FUNC_REGISTRY or your registry in config file when trying to once specify --image for a different registry.
In other words --image should just take precedence and work even when FUNC_REGISTRY is specified BUT --image and --registry could just return an error saying "just choose one or the other" for simplicity?

Otherwise you would need to check both registries, determine what parts image contains and prepend (which I dont think works currently? check my other comment) and that would require a bit more work and consideration.

@lkingland WDYT?

// Skip validation if image has digest (@sha256:...) - digests are immutable overrides
if !strings.Contains(c.Image, "@sha256:") {
// Only validate if image has explicit registry (contains "/" or ":")
// Simple names like "myimage" are compatible - registry will be prepended
Copy link
Contributor

Choose a reason for hiding this comment

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

are they really prepended?

Copy link
Contributor

Choose a reason for hiding this comment

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

❯ func build --image mine --registry quay.io/dfridric
Building function image
Still building
🙌 Function built: mine

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2025
@knative-prow-robot
Copy link

PR needs rebase.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

func build/deploy proceeds with build despite conflicting --image and --registry flags
3 participants