mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
virtcontainers: clh: Do not use the default HTTP client
When enabling tracing with Cloud Hypervisor, we end up establishing 2 connections to 2 different HTTP servers: The Cloud Hypervisor API one that runs over a UNIX socket and the Jaeger endpoint running over UDP. Both connections use the default HTTP golang client instance, and thus share the same transport layer. As the Cloud Hypervisor implementation sets it up to be over a Unix socket, the jaeger uploader ends up going through that transport as well, and sending its spans to the Cloud Hypervisor API server. We fix that by giving the Cloud Hypervisor implementation its own HTTP client instance and we avoid sharing it with anything else in the shim. Fixes #2364 Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>
This commit is contained in:
parent
0c913040b6
commit
760ec4e58a
@ -281,6 +281,22 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
||||
}
|
||||
clh.state.apiSocket = apiSocketPath
|
||||
|
||||
cfg := chclient.NewConfiguration()
|
||||
cfg.HTTPClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, path string) (net.Conn, error) {
|
||||
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return net.DialUnix("unix", nil, addr)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clh.APIClient = chclient.NewAPIClient(cfg).DefaultApi
|
||||
|
||||
clh.virtiofsd = &virtiofsd{
|
||||
path: clh.config.VirtioFSDaemon,
|
||||
sourcePath: filepath.Join(getSharePath(clh.id)),
|
||||
@ -968,34 +984,9 @@ func (clh *cloudHypervisor) isClhRunning(timeout uint) (bool, error) {
|
||||
}
|
||||
|
||||
func (clh *cloudHypervisor) client() clhClient {
|
||||
if clh.APIClient == nil {
|
||||
clh.APIClient = clh.newAPIClient()
|
||||
}
|
||||
|
||||
return clh.APIClient
|
||||
}
|
||||
|
||||
func (clh *cloudHypervisor) newAPIClient() *chclient.DefaultApiService {
|
||||
|
||||
cfg := chclient.NewConfiguration()
|
||||
|
||||
socketTransport := &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, path string) (net.Conn, error) {
|
||||
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return net.DialUnix("unix", nil, addr)
|
||||
},
|
||||
}
|
||||
|
||||
cfg.HTTPClient = http.DefaultClient
|
||||
cfg.HTTPClient.Transport = socketTransport
|
||||
|
||||
return chclient.NewAPIClient(cfg).DefaultApi
|
||||
}
|
||||
|
||||
func openAPIClientError(err error) error {
|
||||
|
||||
if err == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user