forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: add stat and resize APIs to containerd-shim-v2
To query fs stats and resize fs, the requests need to be passed to kata agent through containerd-shim-v2. So we're adding to rest APIs on the shim management endpoint. Also refactor shim management client to its own go file. Fixes: kata-containers#3454 Signed-off-by: Feng Wang <[email protected]>
- Loading branch information
1 parent
6e0090a
commit e9b5a25
Showing
7 changed files
with
189 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
79 changes: 79 additions & 0 deletions
79
src/runtime/pkg/utils/shimclient/shim_management_client.go
This file contains 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2022 Databricks Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package shimclient | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
cdshim "github.com/containerd/containerd/runtime/v2/shim" | ||
shim "github.com/kata-containers/kata-containers/src/runtime/pkg/containerd-shim-v2" | ||
) | ||
|
||
// BuildShimClient builds and returns an http client for communicating with the provided sandbox | ||
func BuildShimClient(sandboxID string, timeout time.Duration) (*http.Client, error) { | ||
return buildUnixSocketClient(shim.SocketAddress(sandboxID), timeout) | ||
} | ||
|
||
// buildUnixSocketClient build http client for Unix socket | ||
func buildUnixSocketClient(socketAddr string, timeout time.Duration) (*http.Client, error) { | ||
transport := &http.Transport{ | ||
DisableKeepAlives: true, | ||
Dial: func(proto, addr string) (conn net.Conn, err error) { | ||
return cdshim.AnonDialer(socketAddr, timeout) | ||
}, | ||
} | ||
|
||
client := &http.Client{ | ||
Transport: transport, | ||
} | ||
|
||
if timeout > 0 { | ||
client.Timeout = timeout | ||
} | ||
|
||
return client, nil | ||
} | ||
|
||
func DoGet(sandboxID string, timeoutInSeconds time.Duration, urlPath string) ([]byte, error) { | ||
client, err := BuildShimClient(sandboxID, timeoutInSeconds) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := client.Get(fmt.Sprintf("http://shim/%s", urlPath)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer func() { | ||
resp.Body.Close() | ||
}() | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath 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)) | ||
defer func() { | ||
resp.Body.Close() | ||
}() | ||
return err | ||
} |