Merge pull request #2253 from lifupan/fix_socket_address

shimv2: fix the issue of kata-runtime exec failed
This commit is contained in:
Fabiano Fidêncio 2021-07-19 10:38:06 +02:00 committed by GitHub
commit f8d71eb96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -186,5 +186,5 @@ func (s *service) mountPprofHandle(m *http.ServeMux, ociSpec *specs.Spec) {
// SocketAddress returns the address of the abstract domain socket for communicating with the // SocketAddress returns the address of the abstract domain socket for communicating with the
// shim management endpoint // shim management endpoint
func SocketAddress(id string) string { func SocketAddress(id string) string {
return filepath.Join(string(filepath.Separator), "run", "vc", id, "shim-monitor") return fmt.Sprintf("unix://%s", filepath.Join(string(filepath.Separator), "run", "vc", id, "shim-monitor"))
} }

View File

@ -7,6 +7,7 @@ package katamonitor
import ( import (
"fmt" "fmt"
cdshim "github.com/containerd/containerd/runtime/v2/shim"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -37,7 +38,7 @@ func (km *KataMonitor) composeSocketAddress(r *http.Request) (string, error) {
func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) { func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Type-Options", "nosniff")
socket, err := km.composeSocketAddress(r) socketAddress, err := km.composeSocketAddress(r)
if err != nil { if err != nil {
monitorLog.WithError(err).Error("failed to get shim monitor address") monitorLog.WithError(err).Error("failed to get shim monitor address")
serveError(w, http.StatusBadRequest, "sandbox may be stopped or deleted") serveError(w, http.StatusBadRequest, "sandbox may be stopped or deleted")
@ -47,7 +48,7 @@ func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) {
transport := &http.Transport{ transport := &http.Transport{
DisableKeepAlives: true, DisableKeepAlives: true,
Dial: func(proto, addr string) (conn net.Conn, err error) { Dial: func(proto, addr string) (conn net.Conn, err error) {
return net.Dial("unix", "\x00"+socket) return cdshim.AnonDialer(socketAddress, defaultTimeout)
}, },
} }

View File

@ -12,6 +12,7 @@ import (
"net/http" "net/http"
"time" "time"
cdshim "github.com/containerd/containerd/runtime/v2/shim"
shim "github.com/kata-containers/kata-containers/src/runtime/containerd-shim-v2" shim "github.com/kata-containers/kata-containers/src/runtime/containerd-shim-v2"
) )
@ -45,7 +46,7 @@ func buildUnixSocketClient(socketAddr string, timeout time.Duration) (*http.Clie
transport := &http.Transport{ transport := &http.Transport{
DisableKeepAlives: true, DisableKeepAlives: true,
Dial: func(proto, addr string) (conn net.Conn, err error) { Dial: func(proto, addr string) (conn net.Conn, err error) {
return net.Dial("unix", "\x00"+socketAddr) return cdshim.AnonDialer(socketAddr, timeout)
}, },
} }