diff --git a/src/runtime/cmd/kata-runtime/kata-volume.go b/src/runtime/cmd/kata-runtime/kata-volume.go index 55274f7d8..b33febe19 100644 --- a/src/runtime/cmd/kata-runtime/kata-volume.go +++ b/src/runtime/cmd/kata-runtime/kata-volume.go @@ -163,5 +163,5 @@ func Resize(volumePath string, size uint64) error { if err != nil { return err } - return shimclient.DoPost(sandboxId, defaultTimeout, containerdshim.DirectVolumeResizeUrl, encoded) + return shimclient.DoPost(sandboxId, defaultTimeout, containerdshim.DirectVolumeResizeUrl, "application/json", encoded) } diff --git a/src/runtime/pkg/utils/shimclient/shim_management_client.go b/src/runtime/pkg/utils/shimclient/shim_management_client.go index c9ed3ad69..835b6f9b9 100644 --- a/src/runtime/pkg/utils/shimclient/shim_management_client.go +++ b/src/runtime/pkg/utils/shimclient/shim_management_client.go @@ -65,15 +65,40 @@ func DoGet(sandboxID string, timeoutInSeconds time.Duration, urlPath string) ([] return body, nil } -func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath string, payload []byte) error { +// DoPut will make a PUT request to the shim endpoint that handles the given sandbox ID +func DoPut(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentType string, payload []byte) error { client, err := BuildShimClient(sandboxID, timeoutInSeconds) if err != nil { return err } - resp, err := client.Post(fmt.Sprintf("http://shim/%s", urlPath), "application/json", bytes.NewBuffer(payload)) + req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("http://shim/%s", urlPath), bytes.NewBuffer(payload)) + if err != nil { + return err + } + req.Header.Set("Content-Type", contentType) + + resp, err := client.Do(req) defer func() { - resp.Body.Close() + if resp != nil { + resp.Body.Close() + } + }() + return err +} + +// DoPost will make a POST request to the shim endpoint that handles the given sandbox ID +func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentType string, payload []byte) error { + client, err := BuildShimClient(sandboxID, timeoutInSeconds) + if err != nil { + return err + } + + resp, err := client.Post(fmt.Sprintf("http://shim/%s", urlPath), contentType, bytes.NewBuffer(payload)) + defer func() { + if resp != nil { + resp.Body.Close() + } }() return err }