-
Notifications
You must be signed in to change notification settings - Fork 427
Optimize the handling of the return messages of the extender scheduler #908
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,11 +19,11 @@ | |||||||
| import ( | ||||||||
| "bytes" | ||||||||
| "encoding/json" | ||||||||
| "fmt" | ||||||||
| "io" | ||||||||
| "net/http" | ||||||||
|
|
||||||||
| "github.com/julienschmidt/httprouter" | ||||||||
| "github.com/unrolled/render" | ||||||||
| "k8s.io/apimachinery/pkg/types" | ||||||||
| "k8s.io/klog/v2" | ||||||||
| extenderv1 "k8s.io/kube-scheduler/extender/v1" | ||||||||
|
|
@@ -65,15 +65,12 @@ | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| if resultBody, err := json.Marshal(extenderFilterResult); err != nil { | ||||||||
| klog.ErrorS(err, "Failed to marshal extender filter result", "result", extenderFilterResult) | ||||||||
| w.Header().Set("Content-Type", "application/json") | ||||||||
| w.WriteHeader(http.StatusInternalServerError) | ||||||||
| w.Write([]byte(err.Error())) | ||||||||
| } else { | ||||||||
| w.Header().Set("Content-Type", "application/json") | ||||||||
| w.WriteHeader(http.StatusOK) | ||||||||
| w.Write(resultBody) | ||||||||
| klog.V(5).InfoS("Returning predicate response", "result", extenderFilterResult) | ||||||||
|
|
||||||||
| err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderFilterResult) | ||||||||
| if err != nil { | ||||||||
| klog.ErrorS(err, "Failed to write JSON response") | ||||||||
|
||||||||
| klog.ErrorS(err, "Failed to write JSON response") | |
| klog.ErrorS(err, "Failed to write JSON response") | |
| http.Error(w, "Failed to write JSON response", http.StatusInternalServerError) |
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.
When render.New(...).JSON fails, should write error info to client. like before code:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Copilot
AI
Mar 4, 2025
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.
In the Bind handler, if JSON rendering fails, no error response is sent to the client. It is recommended to include fallback error handling, similar to how errors were handled in the previous implementation.
Copilot
AI
Apr 19, 2025
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.
If render.New().JSON fails here, the error is only logged; the client is not informed via an HTTP error status or message. Consider handling the error by setting a proper HTTP error response.
| klog.ErrorS(err, "Failed to write JSON response") | |
| klog.ErrorS(err, "Failed to write JSON response") | |
| http.Error(w, "Failed to process the response", http.StatusInternalServerError) |
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.
If render.New(...).JSON fails, the client receives no fallback error response, which may lead to unexpected behavior. Consider adding a mechanism to send an appropriate error message to the client.