mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 05:04:26 +00:00
runtime: direct-volume stats update to use GET parameter
The go default http mux AFAIK doesn’t support pattern routing so right now client is padding the url for direct-volume stats with a subpath of the volume path and this will always result in 404 not found returned by the shim. This change will update the shim to take the volume path as a GET query parameter instead of a subpath. If the parameter is missing or empty, then return 400 BadRequest to the client. Fixes: #4297 Signed-off-by: Yibo Zhuang <yibzhuang@gmail.com>
This commit is contained in:
parent
2c238c8504
commit
ffdc065b4c
@ -32,6 +32,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
DirectVolumePathKey = "path"
|
||||||
|
|
||||||
DirectVolumeStatUrl = "/direct-volume/stats"
|
DirectVolumeStatUrl = "/direct-volume/stats"
|
||||||
DirectVolumeResizeUrl = "/direct-volume/resize"
|
DirectVolumeResizeUrl = "/direct-volume/resize"
|
||||||
)
|
)
|
||||||
@ -139,7 +141,16 @@ func decodeAgentMetrics(body string) []*dto.MetricFamily {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) serveVolumeStats(w http.ResponseWriter, r *http.Request) {
|
func (s *service) serveVolumeStats(w http.ResponseWriter, r *http.Request) {
|
||||||
volumePath, err := url.PathUnescape(strings.TrimPrefix(r.URL.Path, DirectVolumeStatUrl))
|
val := r.URL.Query().Get(DirectVolumePathKey)
|
||||||
|
if val == "" {
|
||||||
|
msg := fmt.Sprintf("Required parameter %s not found", DirectVolumePathKey)
|
||||||
|
shimMgtLog.Info(msg)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
w.Write([]byte(msg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
volumePath, err := url.PathUnescape(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
shimMgtLog.WithError(err).Error("failed to unescape the volume stat url path")
|
shimMgtLog.WithError(err).Error("failed to unescape the volume stat url path")
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
Loading…
Reference in New Issue
Block a user