Skip to content

Commit 3af01d8

Browse files
authored
Merge pull request #612 from Kern--/remote-snapshotter-minor
Fix minor demux snapshotter issues
2 parents 5b7fa79 + 786f02c commit 3af01d8

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

snapshotter/app/service.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"context"
1818
"fmt"
1919
"net"
20-
"net/url"
2120
"os"
2221
"os/signal"
2322
"strconv"
@@ -153,11 +152,7 @@ func initSnapshotter(ctx context.Context, config config.Config, cache cache.Cach
153152
if err != nil {
154153
return nil, err
155154
}
156-
u, err := url.Parse(response.Address)
157-
if err != nil {
158-
return nil, err
159-
}
160-
host := u.Hostname()
155+
host := response.Address
161156
port, err := strconv.ParseUint(response.SnapshotterPort, base10, bits32)
162157
if err != nil {
163158
return nil, err

snapshotter/internal/http_address_resolver.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"net/http"
2222
"os"
2323
"os/signal"
24+
"strconv"
2425
"syscall"
2526

27+
"github.com/containerd/containerd/namespaces"
2628
"github.com/sirupsen/logrus"
2729
"golang.org/x/sync/errgroup"
2830

@@ -33,13 +35,15 @@ import (
3335

3436
var (
3537
port int
38+
remotePort int
3639
containerdSockPath string
3740
logger *logrus.Logger
3841
)
3942

4043
func init() {
4144
flag.IntVar(&port, "port", 10001, "service port for address resolver")
4245
flag.StringVar(&containerdSockPath, "containerdSocket", "/run/firecracker-containerd/containerd.sock", "filepath to the containerd socket")
46+
flag.IntVar(&remotePort, "remotePort", 10000, "the remote port on which the remote snapshotter is listening")
4347
logger = logrus.New()
4448
}
4549

@@ -71,7 +75,7 @@ func main() {
7175

7276
http.HandleFunc("/address", queryAddress)
7377
httpServer := &http.Server{
74-
Addr: fmt.Sprintf(":%d", port),
78+
Addr: fmt.Sprintf("127.0.0.1:%d", port),
7579
}
7680

7781
logger.Info(fmt.Sprintf("http resolver serving at port %d", port))
@@ -117,7 +121,8 @@ func queryAddress(writ http.ResponseWriter, req *http.Request) {
117121
}
118122
defer fcClient.Close()
119123

120-
vmInfo, err := fcClient.GetVMInfo(req.Context(), &proto.GetVMInfoRequest{VMID: namespace})
124+
ctx := namespaces.WithNamespace(req.Context(), namespace)
125+
vmInfo, err := fcClient.GetVMInfo(ctx, &proto.GetVMInfoRequest{VMID: namespace})
121126
if err != nil {
122127
logger.WithField("VMID", namespace).WithError(err).Error("unable to retrieve VM Info")
123128
http.Error(writ, "Internal server error", http.StatusInternalServerError)
@@ -127,8 +132,9 @@ func queryAddress(writ http.ResponseWriter, req *http.Request) {
127132
writ.WriteHeader(http.StatusOK)
128133

129134
response, err := json.Marshal(proxyaddress.Response{
130-
Network: "unix",
131-
Address: vmInfo.VSockPath,
135+
Network: "unix",
136+
Address: vmInfo.VSockPath,
137+
SnapshotterPort: strconv.Itoa(remotePort),
132138
})
133139
if err != nil {
134140
http.Error(writ, "Internal server error", http.StatusInternalServerError)

0 commit comments

Comments
 (0)