Skip to content

Conversation

@bhaktinarvekar
Copy link

…creation

This update enhances the WorkspaceKind POST API to properly perform dry-run validation at the Kubernetes API layer. When dry_run=true is specified, the request now invokes controller-runtime’s Create API with dry-run semantics, allowing validation errors to be surfaced directly from Kubernetes (e.g., schema or webhook errors).

Changes include:

  • Added CreateOptions with DryRunAll for dry-run requests
  • Unified create logic for both dry-run and normal requests
  • Improved error propagation and response mapping
  • Updated tests for dry-run and standard create flows

@github-project-automation github-project-automation bot moved this to Needs Triage in Kubeflow Notebooks Oct 5, 2025
@google-oss-prow google-oss-prow bot added the area/backend area - related to backend components label Oct 5, 2025
@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andyatmiami for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

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

@google-oss-prow google-oss-prow bot added area/v2 area - version - kubeflow notebooks v2 size/L labels Oct 5, 2025
@bhaktinarvekar bhaktinarvekar changed the title feat(api): add Kubernetes-layer dry-run validation for WorkspaceKind … feat: add Kubernetes-layer dry-run validation for WorkspaceKind … Oct 5, 2025
…creation

This update enhances the WorkspaceKind POST API to properly perform
dry-run validation at the Kubernetes API layer. When `dry_run=true` is
specified, the request now invokes controller-runtime’s Create API with
dry-run semantics, allowing validation errors to be surfaced directly
from Kubernetes (e.g., schema or webhook errors).

Changes include:
- Added CreateOptions with DryRunAll for dry-run requests
- Unified create logic for both dry-run and normal requests
- Improved error propagation and response mapping
- Updated tests for dry-run and standard create flows

Signed-off-by: Bhakti Narvekar <[email protected]>
@andyatmiami
Copy link
Contributor

/ok-to-test

Copy link
Contributor

@andyatmiami andyatmiami left a comment

Choose a reason for hiding this comment

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

Thanks for your continued diligence on this PR - we are very close 💯

In addition to addressing the requested changes below (reach out to me if you have questions/concerns) - I noticed the make test invocation also results in errors...

While I did add the ok-to-test label to see this failures in GitHub - in future please me mindful of running make test locally before submitting a PR to ensure the tests you are adding are in fact passing before marking the PR ready.

🙇

Comment on lines +165 to +174
if !a.ValidateContentType(w, r, MediaTypeYaml) {
if hasDryRun {
// Special case: dry_run provided with wrong media type → 400
a.badRequestResponse(w, r,
fmt.Errorf("dry_run is only supported when Content-Type: %s", MediaTypeYaml))
} else {
// Normal case: wrong media type → 415
a.unsupportedMediaTypeResponse(w, r,
fmt.Errorf("only %s is supported", MediaTypeYaml))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this implementation is specifically following the GH issue guidance... but now that I am re-reviewing things (and note: i wrote that issue!) - I can't for the life of me think why this would be desirable!

We shouldn't carve out a specific error message here for dry_run parameter... if the ValidateContentType check fails... we should just be doing

Suggested change
if !a.ValidateContentType(w, r, MediaTypeYaml) {
if hasDryRun {
// Special case: dry_run provided with wrong media type → 400
a.badRequestResponse(w, r,
fmt.Errorf("dry_run is only supported when Content-Type: %s", MediaTypeYaml))
} else {
// Normal case: wrong media type → 415
a.unsupportedMediaTypeResponse(w, r,
fmt.Errorf("only %s is supported", MediaTypeYaml))
}
if !a.ValidateContentType(w, r, MediaTypeYaml) {
a.unsupportedMediaTypeResponse(w, r,
fmt.Errorf("only %s is supported", MediaTypeYaml))

This also means we don't need this additional "look up":

hasDryRun := r.URL.Query().Get("dry_run") != ""

which is a nice added benefit - as the URL.Query.Get(...) code now can purely be contained within the helper function.

sorry for that poor initial guidance!

Comment on lines +238 to +244
// Return appropriate response based on dry-run
if isDryRun {
responseEnvelope := &WorkspaceKindEnvelope{Data: *createdWorkspaceKind}
a.dataResponse(w, r, responseEnvelope)
return
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do a little better job here combining L239-243 with L246-249

in both cases - the following invocation is the same:

responseEnvelope := &WorkspaceKindCreateEnvelope{Data: createdWorkspaceKind}
  • I notice you are passing a pointer in your newly added code (which is preferred style now!)

But i think refactoring this into an if/else (pullin gout the responseEnvelope declaration) might be a little clearer expressing intent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend area - related to backend components area/v2 area - version - kubeflow notebooks v2 ok-to-test size/L

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants