Skip to content

func build/deploy proceeds with build despite conflicting --image and --registry flags #3065

@RayyanSeliya

Description

@RayyanSeliya

Current behavior:

When running func deploy or func build with both --image and --registry flags that specify different registries, the command proceeds to build instead of validating the conflict:

rayyan@rayyan-seliya:/mnt/c/Users/RAYYAN/Desktop/func/myfunction$ func deploy --image ghcr.io/user/func:latest --registry different-registry.com/user
Building function image
^CError: failed to fetch builder image 'ghcr.io/knative/builder-jammy-tiny:latest': context canceled

This forces users to:

  1. Wait through the entire build process before realizing the conflict
  2. Manually cancel (Ctrl+C) to stop the misleading build
  3. Guess what went wrong from a generic "failed to fetch builder image" error
  4. Not understand that the issue is with conflicting registry specifications

Proposed improvement:

Provide immediate validation and clear guidance when image and registry flags conflict:

Error: conflicting image and registry options

You cannot use both --image and --registry together when they specify different registries.

These are two different ways to specify where to push your function image.

Choose ONE of these approaches:

1. Use --image to specify the complete image name:
   func deploy --image <full-image-name>

2. Use --registry and let the system create the image name automatically:
   func deploy --registry <registry>

For more options, run 'func deploy --help'

For func build:

Error: conflicting image and registry options

You cannot use both --image and --registry together when they specify different registries.

These are two different ways to specify where to push your function image.

Choose ONE of these approaches:

1. Use --image to specify the complete image name:
   func build --image <full-image-name>

2. Use --registry and let the system create the image name automatically:
   func build --registry <registry>

For more options, run 'func build --help'

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 provide user-friendly guidance

Expected Workflow:

The validation should occur before any build attempts:

  1. Parse command flags
  2. Validate flag combinations for conflicts
  3. Return clear error if conflicts detected
  4. Only proceed to build if validation passes

Compatibility Notes:

The validation should allow compatible combinations:

  • --registry example.com/alice --image example.com/alice/subnamespace/myfunc (subnamespace)
  • --registry example.com/alice --image example.com/alice/func:latest (exact match)
  • --registry example.com/alice --image different.com/user/func (different registry)

User Impact:

  • Current: Confusing build failure → time wasted waiting → need to investigate → unclear error message
  • Improved: Immediate validation → clear error explanation → actionable guidance → better developer experience

Metadata

Metadata

Assignees

No one assigned

    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