databricks / click

The "Command Line Interactive Controller for Kubernetes"
Apache License 2.0
1.49k stars 85 forks source link

Validate namespace names before setting them #225

Closed hasnain-db closed 8 months ago

hasnain-db commented 8 months ago

Validate the namespace name inside Environment::set_namespace

This prevents user error when copying namespace names output from other commands and pulling in e.g. control characters. We saw user confusion with errors like the below when talking to the k8s server:

Got unexpected status 500 Internal Server Error (Other(Ok(Some(Object {"apiVersion": String("v1"), "code": Number(500), "kind": String("Status"), "message": String("net/http: invalid header field value for \"X-Forwarded-Path\""), "metadata": Object {}, "reason": String("InternalError"), "status": String("Failure")}))), 179)

With this change the error message now shows upfront when setting the namespace, e.g.:

[dev-aws-us-west-2] [test-shard-hasnain-lakhani-spark-tls] [none] > namespace foo&
Invalid namespace name. Namespaces must be valid RFC 1123 labels (less than 64 characters, lowercase alphanumeric or '-', and start and end with an alphanumeric character)
hasnain-db commented 8 months ago

clippy failures look unrelated to this PR, this PR isn't touching that code. I can fix them in a separate PR