Skip to content

Add namespace validation to catch invalid names before build/deploy#3133

Merged
knative-prow[bot] merged 7 commits intoknative:mainfrom
RayyanSeliya:namespace-check
Nov 13, 2025
Merged

Add namespace validation to catch invalid names before build/deploy#3133
knative-prow[bot] merged 7 commits intoknative:mainfrom
RayyanSeliya:namespace-check

Conversation

@RayyanSeliya
Copy link
Copy Markdown
Contributor

Changes

  • 🎁 Add early namespace validation with user-friendly error messages
  • 🐛 Prevent wasted build time when using invalid namespace names
  • 🧹 Add comprehensive unit tests for namespace validation

Adds DNS-1123 validation for namespace names before build/deploy operations. Invalid namespace names now fail immediately with clear error messages instead of proceeding through lengthy builds.

Implementation:

  • Add ValidateNamespace() function using Kubernetes DNS-1123 validation (pkg/utils/names.go)
  • Add validation check in deployConfig.Validate() and error handling in runDeploy() (cmd/deploy.go)
  • Add ErrInvalidNamespace error type (pkg/functions/errors.go) with user-friendly CLI message

/kind enhancement

Fixes #3132

Release Note

Invalid namespace names are now caught immediately with helpful error messages, preventing wasted build time

@knative-prow knative-prow Bot added the kind/enhancement Feature additions or improvements to existing label Oct 22, 2025
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Oct 22, 2025

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.

Details

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 size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Oct 22, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 38.88889% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.10%. Comparing base (b785e68) to head (a8a0ec9).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/deploy.go 15.38% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3133      +/-   ##
==========================================
+ Coverage   62.37%   63.10%   +0.73%     
==========================================
  Files         150      150              
  Lines       13501    13519      +18     
==========================================
+ Hits         8421     8531     +110     
+ Misses       4103     3981     -122     
- Partials      977     1007      +30     
Flag Coverage Δ
e2e-tests 42.25% <16.66%> (+1.42%) ⬆️
integration-tests 57.51% <11.11%> (+1.59%) ⬆️
unit-tests 49.44% <38.88%> (-0.03%) ⬇️

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
Copy Markdown
Contributor Author

Hey @gauron99 can u have alook when u have some moments am I doing right ?

Comment thread pkg/utils/names_test.go Outdated
@gauron99 gauron99 self-assigned this Nov 1, 2025
@gauron99 gauron99 requested review from jrangelramos and matejvasek and removed request for dsimansk and jrangelramos November 1, 2025 12:51
@RayyanSeliya RayyanSeliya requested a review from gauron99 November 2, 2025 18:31
@gauron99
Copy link
Copy Markdown
Contributor

gauron99 commented Nov 4, 2025

same here as with my other comment on different PR. I think we could put the utils stuff inside cmd/deploy because its only used there.

WDYT @lkingland ?

Comment thread pkg/utils/names.go
// ValidateNamespace validates that the input name is a valid Kubernetes namespace name, ie. valid DNS-1035 label.
// It must consist of lower case alphanumeric characters or '-',
// start with an alphabetic character, and end with an alphanumeric character
// (e.g. 'my-namespace', 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
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 would like it if there could be a link in the comment to the k8s docs so the source is easily accessible for what the limits here are.

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.

@matejvasek @lkingland anything you can think of we are missing here for the namespace rules? or any other labels?

@RayyanSeliya
Copy link
Copy Markdown
Contributor Author

Hey @gauron99 should I wait for luke and other member for opinion or should I implement as you have described ?

Copy link
Copy Markdown
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow knative-prow Bot added lgtm 🤖 PR is ready to be merged. approved 🤖 PR has been approved by an approver from all required OWNERS files. labels Nov 11, 2025
@lkingland lkingland added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels Nov 11, 2025
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 11, 2025
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label Nov 11, 2025
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 11, 2025
@RayyanSeliya
Copy link
Copy Markdown
Contributor Author

same here some of the test are failing @lkingland @gauron99 dont know why !

@gauron99
Copy link
Copy Markdown
Contributor

/override "On Cluster RT Test (ubuntu-latest, pack)" "E2E Test (ubuntu-latest, springboot)"
These fails are due to custom pack builder issue with springboot
/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 11, 2025
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Nov 11, 2025

@gauron99: Overrode contexts on behalf of gauron99: E2E Test (ubuntu-latest, springboot), On Cluster RT Test (ubuntu-latest, pack)

Details

In response to this:

/override "On Cluster RT Test (ubuntu-latest, pack)" "E2E Test (ubuntu-latest, springboot)"
These fails are due to custom pack builder issue with springboot
/lgtm
/approve

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-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 11, 2025
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label Nov 12, 2025
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 12, 2025
@gauron99
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 13, 2025
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Nov 13, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauron99, lkingland, RayyanSeliya

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

@knative-prow knative-prow Bot merged commit af45a47 into knative:main Nov 13, 2025
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. kind/enhancement Feature additions or improvements to existing lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid Namespace Names Bypass Validation, Waste Build Time and Show Confusing Errors

4 participants