func
func copied to clipboard
Add domain validation to catch invalid names before build/deploy
Changes
- :gift: Add early domain validation with user-friendly error messages
- :bug: Prevent wasted build time when using invalid domain names
- :broom: Add comprehensive unit tests for domain validation
Adds DNS-1123 subdomain validation for domain names before build/deploy operations. Invalid domain names now fail immediately with clear error messages instead of proceeding through lengthy builds.
Implementation:
- Add
ValidateDomain()function using Kubernetes DNS-1123 subdomain validation (pkg/utils/names.go) - Add validation check in
deployConfig.Validate()and error handling inrunDeploy()(cmd/deploy.go) - Add
ErrInvalidDomainerror type (pkg/functions/errors.go) with user-friendly CLI message - Add comprehensive test coverage with 49+ test cases covering valid/invalid domains
Fixes #3151
Before:
$ func deploy --registry ghcr.io/user --domain "my app.com"
Building function image
Still building
^CError: executing lifecycle: context canceled
After:
$ func deploy --registry ghcr.io/user --domain "my app.com"
Error: invalid domain
Domain names must be valid DNS subdomains:
- Lowercase letters, numbers, hyphens (-), and dots (.) only
- Start and end with a letter or number
- Max 253 characters total, each part between dots max 63 characters
Valid examples:
func deploy --registry ghcr.io/user --domain example.com
func deploy --registry ghcr.io/user --domain api.example.com
Note: Domain must be configured on your Knative cluster, or it will be ignored.
For more options, run 'func deploy --help'
/kind enhancement
Release Note
Invalid domain names are now caught immediately with helpful error messages, preventing wasted build time
Hi @RayyanSeliya. Thanks for your PR.
I'm waiting for a github.com 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.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 60.22%. Comparing base (0a41919) to head (67f7f32).
:warning: Report is 19 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #3152 +/- ##
==========================================
+ Coverage 59.41% 60.22% +0.81%
==========================================
Files 134 134
Lines 13495 13526 +31
==========================================
+ Hits 8018 8146 +128
+ Misses 4537 4408 -129
- Partials 940 972 +32
| Flag | Coverage Δ | |
|---|---|---|
| e2e-tests | 41.64% <0.00%> (+1.40%) |
:arrow_up: |
| integration-tests | 54.67% <53.84%> (+1.68%) |
:arrow_up: |
| unit-tests | 46.82% <100.00%> (+0.07%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
/ok-to-test
/retest
Hey @gauron99 I thinks it's ready now all clear !
I think it would be better to keep the utils as small as possible, since this PR addresses domains, we need domains only in deploy so it would be better to keep the error definitions in errors and any CLI errors in cmd/deploy.go. And any validation function also to be kept the cmd/deploy.go (where its used)
WDYT @matejvasek @lkingland ?
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: lkingland, RayyanSeliya
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [lkingland]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment