Skip to content

api: validate resource names with k8s declarative validation - #762

Merged
yongruilin merged 1 commit into
google:mainfrom
yongruilin:ax-dv
Nov 25, 2026
Merged

yongruilin merged 1 commit into
google:mainfrom
yongruilin:ax-dv

Conversation

@yongruilin

Copy link
Copy Markdown
Collaborator

Validate metadata.name and metadata.atespace with rules declared as +k8s: tags in the protos, from which Kubernetes validation-gen generates the checks, as Agent Substrate does. First step of #726.

  • make generate now also runs validation-gen (pinned in hack/tools/code-generator) and writes internal/apivalidation/zz_generated.validation.go; go.mod gains k8s.io/apimachinery at the same release, v0.38.0-beta.0.
  • Each create and update handler calls one request validator, such as ValidateCreateTaskRequest, which runs the generated checks and then the checks that are still written by hand.
  • A request gets all its problems back at once, with paths that start at the request field: task.metadata.name: Required value. A problem found by a hand-written check reads task: Invalid value: spec.profile: ... until that check is moved.

Follow-ups:

  • Move the hand-written checks to tags and custom validators, one proto file per PR: common.proto, task.proto, gateway.proto, workspace.proto.
  • Clear the server-assigned fields before validating, as Agent Substrate does, together with the common.proto PR.
  • Generate the egress rules that Agent Substrate declares for Gateway, and add rules for the fields that have none.
  • Move both pins to v0.38.0 when Kubernetes 1.38 is released.

@ghost
ghost requested review from mayawang and rakyll as code owners November 25, 2026 07:03

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not very familiar with the k8s declarative validation but it looked good to me.

validation-gen generates request validators from +k8s: tags in the protos.
Handlers call them; the checks still written by hand run inside them.
@ghost
ghost merged commit 40cfb18 into google:main Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants