-
Notifications
You must be signed in to change notification settings - Fork 68
feat: add Kubernetes-layer dry-run validation for WorkspaceKind … #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bhaktinarvekar
wants to merge
1
commit into
kubeflow:notebooks-v2
Choose a base branch
from
bhaktinarvekar:issue_417_v1
base: notebooks-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,8 +154,24 @@ func (a *App) GetWorkspaceKindsHandler(w http.ResponseWriter, r *http.Request, _ | |
| // @Router /workspacekinds [post] | ||
| func (a *App) CreateWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
|
|
||
| // Parse dry_run query parameter using helper | ||
| isDryRun, err := a.GetBooleanQueryParameter(w, r, "dry_run") | ||
| if err != nil { | ||
| return | ||
| } | ||
| hasDryRun := r.URL.Query().Get("dry_run") != "" | ||
|
|
||
| // validate the Content-Type header | ||
| if success := a.ValidateContentType(w, r, MediaTypeYaml); !success { | ||
| 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)) | ||
| } | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -204,7 +220,7 @@ func (a *App) CreateWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, | |
| } | ||
| // ============================================================ | ||
|
|
||
| createdWorkspaceKind, err := a.repositories.WorkspaceKind.Create(r.Context(), workspaceKind) | ||
| createdWorkspaceKind, err := a.repositories.WorkspaceKind.Create(r.Context(), workspaceKind, isDryRun) | ||
| if err != nil { | ||
| if errors.Is(err, repository.ErrWorkspaceKindAlreadyExists) { | ||
| a.conflictResponse(w, r, err) | ||
|
|
@@ -219,6 +235,13 @@ func (a *App) CreateWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, | |
| return | ||
| } | ||
|
|
||
| // Return appropriate response based on dry-run | ||
| if isDryRun { | ||
| responseEnvelope := &WorkspaceKindEnvelope{Data: *createdWorkspaceKind} | ||
| a.dataResponse(w, r, responseEnvelope) | ||
| return | ||
| } | ||
|
|
||
|
Comment on lines
+238
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
But i think refactoring this into an |
||
| // calculate the GET location for the created workspace kind (for the Location header) | ||
| location := a.LocationGetWorkspaceKind(createdWorkspaceKind.Name) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_runparameter... if theValidateContentTypecheck fails... we should just be doingThis also means we don't need this additional "look up":
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!