mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-22 13:38:26 +00:00
kata-runtime: shmgmt: make url usage consistent
Before, we had a mix of slash, etc. Unfortunately, when cleaning URL paths, serve mux seems to mangle the request method, resulting in each request being a GET (instead of PUT or POST). Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
2a09378dd9
commit
0706fb28ac
@ -33,12 +33,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DirectVolumePathKey = "path"
|
DirectVolumePathKey = "path"
|
||||||
|
AgentUrl = "/agent-url"
|
||||||
DirectVolumeStatUrl = "/direct-volume/stats"
|
DirectVolumeStatUrl = "/direct-volume/stats"
|
||||||
DirectVolumeResizeUrl = "/direct-volume/resize"
|
DirectVolumeResizeUrl = "/direct-volume/resize"
|
||||||
IPTablesUrl = "/iptables"
|
IPTablesUrl = "/iptables"
|
||||||
IP6TablesUrl = "/ip6tables"
|
IP6TablesUrl = "/ip6tables"
|
||||||
|
MetricsUrl = "/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -260,8 +261,8 @@ func (s *service) startManagementServer(ctx context.Context, ociSpec *specs.Spec
|
|||||||
|
|
||||||
// bind handler
|
// bind handler
|
||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
m.Handle("/metrics", http.HandlerFunc(s.serveMetrics))
|
m.Handle(MetricsUrl, http.HandlerFunc(s.serveMetrics))
|
||||||
m.Handle("/agent-url", http.HandlerFunc(s.agentURL))
|
m.Handle(AgentUrl, http.HandlerFunc(s.agentURL))
|
||||||
m.Handle(DirectVolumeStatUrl, http.HandlerFunc(s.serveVolumeStats))
|
m.Handle(DirectVolumeStatUrl, http.HandlerFunc(s.serveVolumeStats))
|
||||||
m.Handle(DirectVolumeResizeUrl, http.HandlerFunc(s.serveVolumeResize))
|
m.Handle(DirectVolumeResizeUrl, http.HandlerFunc(s.serveVolumeResize))
|
||||||
m.Handle(IPTablesUrl, http.HandlerFunc(s.ipTablesHandler))
|
m.Handle(IPTablesUrl, http.HandlerFunc(s.ipTablesHandler))
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
containerdshim "github.com/kata-containers/kata-containers/src/runtime/pkg/containerd-shim-v2"
|
||||||
mutils "github.com/kata-containers/kata-containers/src/runtime/pkg/utils"
|
mutils "github.com/kata-containers/kata-containers/src/runtime/pkg/utils"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/utils/shimclient"
|
"github.com/kata-containers/kata-containers/src/runtime/pkg/utils/shimclient"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -239,7 +240,7 @@ func (km *KataMonitor) aggregateSandboxMetrics(encoder expfmt.Encoder) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getParsedMetrics(sandboxID string, sandboxMetadata sandboxCRIMetadata) ([]*dto.MetricFamily, error) {
|
func getParsedMetrics(sandboxID string, sandboxMetadata sandboxCRIMetadata) ([]*dto.MetricFamily, error) {
|
||||||
body, err := shimclient.DoGet(sandboxID, defaultTimeout, "metrics")
|
body, err := shimclient.DoGet(sandboxID, defaultTimeout, containerdshim.MetricsUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -249,7 +250,7 @@ func getParsedMetrics(sandboxID string, sandboxMetadata sandboxCRIMetadata) ([]*
|
|||||||
|
|
||||||
// GetSandboxMetrics will get sandbox's metrics from shim
|
// GetSandboxMetrics will get sandbox's metrics from shim
|
||||||
func GetSandboxMetrics(sandboxID string) (string, error) {
|
func GetSandboxMetrics(sandboxID string) (string, error) {
|
||||||
body, err := shimclient.DoGet(sandboxID, defaultTimeout, "metrics")
|
body, err := shimclient.DoGet(sandboxID, defaultTimeout, containerdshim.MetricsUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func DoGet(sandboxID string, timeoutInSeconds time.Duration, urlPath string) ([]
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get(fmt.Sprintf("http://shim/%s", urlPath))
|
resp, err := client.Get(fmt.Sprintf("http://shim%s", urlPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func DoPut(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTyp
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("http://shim/%s", urlPath), bytes.NewBuffer(payload))
|
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("http://shim%s", urlPath), bytes.NewBuffer(payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTy
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Post(fmt.Sprintf("http://shim/%s", urlPath), contentType, bytes.NewBuffer(payload))
|
resp, err := client.Post(fmt.Sprintf("http://shim%s", urlPath), contentType, bytes.NewBuffer(payload))
|
||||||
defer func() {
|
defer func() {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user