Skip to content

Commit 21f5d52

Browse files
authored
Merge pull request firecracker-microvm#509 from kzys/upgrade-ctrd-15
Upgrade to containerd 1.5.2
2 parents 7e9026a + 486caaa commit 21f5d52

File tree

12 files changed

+888
-227
lines changed

12 files changed

+888
-227
lines changed

firecracker-control/client/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func New(ttrpcAddress string) (*Client, error) {
3434
return nil, errors.Wrap(err, "failed to create ttrpc client")
3535
}
3636

37-
fcClient := fccontrol.NewFirecrackerClient(ttrpcClient.Client())
37+
client, err := ttrpcClient.Client()
38+
if err != nil {
39+
return nil, err
40+
}
41+
fcClient := fccontrol.NewFirecrackerClient(client)
3842

3943
return &Client{
4044
FirecrackerService: fcClient,

firecracker-control/cmd/containerd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ import (
4747
_ "github.com/containerd/containerd/runtime/v2/runc/options"
4848

4949
// Snapshotters
50-
_ "github.com/containerd/containerd/snapshots/devmapper"
51-
_ "github.com/containerd/containerd/snapshots/overlay"
50+
_ "github.com/containerd/containerd/snapshots/devmapper/plugin"
51+
_ "github.com/containerd/containerd/snapshots/overlay/plugin"
5252

5353
// Register fc-control plugin
5454
_ "github.com/firecracker-microvm/firecracker-containerd/firecracker-control"

firecracker-control/local.go

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os"
2121
"os/exec"
2222
"strconv"
23-
"strings"
2423
"sync"
2524
"syscall"
2625
"time"
@@ -115,15 +114,15 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
115114
// We determine if there is already a shim managing a VM with the current VMID by attempting
116115
// to listen on the abstract socket address (which is parameterized by VMID). If we get
117116
// EADDRINUSE, then we assume there is already a shim for the VM and return an AlreadyExists error.
118-
shimSocketAddress, err := fcShim.SocketAddress(requestCtx, id)
117+
shimSocketAddress, err := shim.SocketAddress(requestCtx, s.containerdAddress, id)
119118
if err != nil {
120119
err = errors.Wrap(err, "failed to obtain shim socket address")
121120
s.logger.WithError(err).Error()
122121
return nil, err
123122
}
124123

125124
shimSocket, err := shim.NewSocket(shimSocketAddress)
126-
if isEADDRINUSE(err) {
125+
if shim.SocketEaddrinuse(err) {
127126
return nil, status.Errorf(codes.AlreadyExists, "VM with ID %q already exists (socket: %q)", id, shimSocketAddress)
128127
} else if err != nil {
129128
err = errors.Wrapf(err, "failed to open shim socket at address %q", shimSocketAddress)
@@ -132,7 +131,6 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
132131
}
133132

134133
// If we're here, there is no pre-existing shim for this VMID, so we spawn a new one
135-
defer shimSocket.Close()
136134
if err := os.Mkdir(s.config.ShimBaseDir, 0700); err != nil && !os.IsExist(err) {
137135
s.logger.WithError(err).Error()
138136
return nil, errors.Wrapf(err, "failed to make shim base directory: %s", s.config.ShimBaseDir)
@@ -165,7 +163,7 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
165163
// containerd does not currently expose the shim server for us to register the fccontrol service with too.
166164
// This is likely addressable through some relatively small upstream contributions; the following is a stop-gap
167165
// solution until that time.
168-
fcSocketAddress, err := fcShim.FCControlSocketAddress(requestCtx, id)
166+
fcSocketAddress, err := fcShim.FCControlSocketAddress(requestCtx, s.containerdAddress, id)
169167
if err != nil {
170168
err = errors.Wrap(err, "failed to obtain shim socket address")
171169
s.logger.WithError(err).Error()
@@ -179,8 +177,6 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
179177
return nil, err
180178
}
181179

182-
defer fcSocket.Close()
183-
184180
cmd, err := s.newShim(ns, id, s.containerdAddress, shimSocket, fcSocket)
185181
if err != nil {
186182
return nil, err
@@ -223,14 +219,14 @@ func (s *local) shimFirecrackerClient(requestCtx context.Context, vmID string) (
223219
return nil, errors.Wrap(err, "invalid id")
224220
}
225221

226-
socketAddr, err := fcShim.FCControlSocketAddress(requestCtx, vmID)
222+
socketAddr, err := fcShim.FCControlSocketAddress(requestCtx, s.containerdAddress, vmID)
227223
if err != nil {
228224
err = errors.Wrap(err, "failed to get shim's fccontrol socket address")
229225
s.logger.WithError(err).Error()
230226
return nil, err
231227
}
232228

233-
return fcclient.New("\x00" + socketAddr)
229+
return fcclient.New(socketAddr)
234230
}
235231

236232
// StopVM stops running VM instance by VM ID. This stops the VM, all tasks within the VM and the runtime shim
@@ -289,7 +285,7 @@ func (s *local) ResumeVM(ctx context.Context, req *proto.ResumeVMRequest) (*empt
289285
}
290286

291287
func (s *local) waitForShimToExit(ctx context.Context, vmID string) error {
292-
socketAddr, err := fcShim.SocketAddress(ctx, vmID)
288+
socketAddr, err := shim.SocketAddress(ctx, s.containerdAddress, vmID)
293289
if err != nil {
294290
return err
295291
}
@@ -458,14 +454,18 @@ func (s *local) newShim(ns, vmID, containerdAddress string, shimSocket *net.Unix
458454
}
459455
}
460456

461-
// Close all Unix abstract sockets.
457+
// Close all Unix sockets.
462458
if err := shimSocketFile.Close(); err != nil {
463459
logger.WithError(err).Errorf("failed to close %q", shimSocketFile.Name())
464460
}
465461
if err := fcSocketFile.Close(); err != nil {
466462
logger.WithError(err).Errorf("failed to close %q", fcSocketFile.Name())
467463
}
468464

465+
if err := s.removeSockets(ns, vmID); err != nil {
466+
logger.WithError(err).Errorf("failed to remove sockets")
467+
}
468+
469469
if err := os.RemoveAll(shimDir.RootPath()); err != nil {
470470
logger.WithError(err).Errorf("failed to remove %q", shimDir.RootPath())
471471
}
@@ -480,8 +480,33 @@ func (s *local) newShim(ns, vmID, containerdAddress string, shimSocket *net.Unix
480480
return cmd, nil
481481
}
482482

483-
func isEADDRINUSE(err error) bool {
484-
return err != nil && strings.Contains(err.Error(), "address already in use")
483+
func (s *local) removeSockets(ns string, vmID string) error {
484+
var result *multierror.Error
485+
486+
// This context is only used for passing the namespace.
487+
ctx := namespaces.WithNamespace(context.Background(), ns)
488+
489+
address, err := shim.SocketAddress(ctx, s.containerdAddress, vmID)
490+
if err != nil {
491+
result = multierror.Append(result, err)
492+
} else {
493+
err := shim.RemoveSocket(address)
494+
if err != nil {
495+
result = multierror.Append(result, err)
496+
}
497+
}
498+
499+
address, err = fcShim.FCControlSocketAddress(ctx, s.containerdAddress, vmID)
500+
if err != nil {
501+
result = multierror.Append(result, err)
502+
} else {
503+
err = shim.RemoveSocket(address)
504+
if err != nil {
505+
result = multierror.Append(result, err)
506+
}
507+
}
508+
509+
return result.ErrorOrNil()
485510
}
486511

487512
func setShimOOMScore(shimPid int) error {

go.mod

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,42 @@
11
module github.com/firecracker-microvm/firecracker-containerd
22

33
require (
4-
github.com/Microsoft/go-winio v0.4.14 // indirect
54
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
65
github.com/awslabs/tc-redirect-tap v0.0.0-20200708224642-a0300978797d
7-
github.com/containerd/cgroups v0.0.0-20181105182409-82cb49fc1779 // indirect
8-
github.com/containerd/console v0.0.0-20191219165238-8375c3424e4d // indirect
9-
github.com/containerd/containerd v1.3.8-0.20200824223617-f99bb2cc4483
10-
github.com/containerd/continuity v0.0.0-20181027224239-bea7585dbfac // indirect
11-
github.com/containerd/fifo v0.0.0-20191213151349-ff969a566b00
12-
github.com/containerd/go-runc v0.0.0-20190226155025-7d11b49dc076
13-
github.com/containerd/ttrpc v0.0.0-20190613183316-1fb3814edf44
14-
github.com/containerd/typeurl v0.0.0-20181015155603-461401dc8f19
15-
github.com/containernetworking/cni v0.8.0
16-
github.com/containernetworking/plugins v0.8.7
17-
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 // indirect
18-
github.com/docker/distribution v2.7.1+incompatible // indirect
19-
github.com/docker/go-events v0.0.0-20170721190031-9461782956ad // indirect
20-
github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 // indirect
6+
github.com/containerd/containerd v1.5.2
7+
github.com/containerd/fifo v1.0.0
8+
github.com/containerd/go-runc v1.0.0
9+
github.com/containerd/ttrpc v1.0.2
10+
github.com/containerd/typeurl v1.0.2
11+
github.com/containernetworking/cni v0.8.1
12+
github.com/containernetworking/plugins v0.9.1
2113
github.com/firecracker-microvm/firecracker-go-sdk v0.22.1-0.20201117001223-cd822c0d457c
2214
github.com/go-ole/go-ole v1.2.4 // indirect
23-
github.com/godbus/dbus v0.0.0-20181025153459-66d97aec3384 // indirect
2415
github.com/gofrs/uuid v3.3.0+incompatible
25-
github.com/gogo/googleapis v1.1.0 // indirect
26-
github.com/gogo/protobuf v1.3.0
27-
github.com/golang/protobuf v1.3.1
28-
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
16+
github.com/gogo/protobuf v1.3.2
17+
github.com/golang/protobuf v1.4.3
2918
github.com/hashicorp/go-multierror v1.1.0
30-
github.com/imdario/mergo v0.3.8 // indirect
3119
github.com/mdlayher/vsock v0.0.0-20190329173812-a92c53d5dcab
3220
github.com/miekg/dns v1.1.16
33-
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
34-
github.com/opencontainers/image-spec v1.0.1 // indirect
35-
github.com/opencontainers/runc v1.0.0-rc9
36-
github.com/opencontainers/runtime-spec v0.1.2-0.20181106065543-31e0d16c1cb7
21+
github.com/opencontainers/runc v1.0.0-rc93
22+
github.com/opencontainers/runtime-spec v1.0.3-0.20200929063507-e6143ca7d51d
3723
github.com/pkg/errors v0.9.1
38-
github.com/prometheus/client_golang v0.9.2 // indirect
3924
github.com/shirou/gopsutil v2.18.12+incompatible
4025
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
4126
github.com/sirupsen/logrus v1.7.0
4227
github.com/stretchr/testify v1.6.1
43-
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
44-
github.com/urfave/cli v1.20.0 // indirect
45-
github.com/vishvananda/netlink v1.1.0
46-
go.etcd.io/bbolt v1.3.1-etcd.8 // indirect
47-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
48-
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
49-
google.golang.org/genproto v0.0.0-20181109154231-b5d43981345b // indirect
50-
google.golang.org/grpc v1.21.0
51-
gotest.tools v2.2.0+incompatible // indirect
28+
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
29+
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
30+
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
31+
google.golang.org/grpc v1.34.0
5232
)
5333

54-
// Workaround for github.com/containerd/containerd issue #3031
55-
replace github.com/docker/distribution v2.7.1+incompatible => github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible
34+
replace (
35+
// Pin gPRC-related dependencies as like containerd v1.5.1
36+
github.com/gogo/googleapis => github.com/gogo/googleapis v1.3.2
37+
github.com/golang/protobuf => github.com/golang/protobuf v1.3.5
38+
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63
39+
google.golang.org/grpc => google.golang.org/grpc v1.27.1
40+
)
5641

5742
go 1.11

0 commit comments

Comments
 (0)