Skip to content

Commit e708b47

Browse files
committed
Add nix-snapshotter support to the embedded containerd
1 parent de82584 commit e708b47

File tree

9 files changed

+45
-4
lines changed

9 files changed

+45
-4
lines changed

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ require (
135135
github.com/opencontainers/runc v1.1.12
136136
github.com/opencontainers/selinux v1.11.0
137137
github.com/otiai10/copy v1.7.0
138+
github.com/pdtpartners/nix-snapshotter v0.1.2-0.20240214230725-1c25427973e0
138139
github.com/pkg/errors v0.9.1
139140
github.com/prometheus/common v0.45.0
140141
github.com/rancher/dynamiclistener v0.3.6
@@ -184,6 +185,7 @@ require (
184185
require (
185186
cloud.google.com/go/compute v1.23.3 // indirect
186187
cloud.google.com/go/compute/metadata v0.2.3 // indirect
188+
dario.cat/mergo v1.0.0 // indirect
187189
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
188190
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
189191
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
@@ -219,7 +221,7 @@ require (
219221
github.com/checkpoint-restore/go-criu/v5 v5.3.0 // indirect
220222
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
221223
github.com/cilium/ebpf v0.9.1 // indirect
222-
github.com/container-orchestrated-devices/container-device-interface v0.5.4 // indirect
224+
github.com/container-orchestrated-devices/container-device-interface v0.6.0 // indirect
223225
github.com/container-storage-interface/spec v1.8.0 // indirect
224226
github.com/containerd/btrfs/v2 v2.0.0 // indirect
225227
github.com/containerd/cgroups v1.1.0 // indirect

go.sum

+8-2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ cloud.google.com/go/vpcaccess v1.6.0/go.mod h1:wX2ILaNhe7TlVa4vC5xce1bCnqE3AeH27
214214
cloud.google.com/go/webrisk v1.8.0/go.mod h1:oJPDuamzHXgUc+b8SiHRcVInZQuybnvEW72PqTc7sSg=
215215
cloud.google.com/go/websecurityscanner v1.5.0/go.mod h1:Y6xdCPy81yi0SQnDY1xdNTNpfY1oAgXUlcfN3B3eSng=
216216
cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw=
217+
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
218+
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
217219
dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU=
218220
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
219221
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
@@ -380,8 +382,9 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
380382
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
381383
github.com/cockroachdb/datadriven v1.0.2 h1:H9MtNqVoVhvd9nCBwOyDjUEdZCREqbIdCJD93PBm/jA=
382384
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
383-
github.com/container-orchestrated-devices/container-device-interface v0.5.4 h1:PqQGqJqQttMP5oJ/qNGEg8JttlHqGY3xDbbcKb5T9E8=
384385
github.com/container-orchestrated-devices/container-device-interface v0.5.4/go.mod h1:DjE95rfPiiSmG7uVXtg0z6MnPm/Lx4wxKCIts0ZE0vg=
386+
github.com/container-orchestrated-devices/container-device-interface v0.6.0 h1:aWwcz/Ep0Fd7ZuBjQGjU/jdPloM7ydhMW13h85jZNvk=
387+
github.com/container-orchestrated-devices/container-device-interface v0.6.0/go.mod h1:OQlgtJtDrOxSQ1BWODC8OZK1tzi9W69wek+Jy17ndzo=
385388
github.com/container-storage-interface/spec v1.8.0 h1:D0vhF3PLIZwlwZEf2eNbpujGCNwspwTYf2idJRJx4xI=
386389
github.com/container-storage-interface/spec v1.8.0/go.mod h1:ROLik+GhPslwwWRNFF1KasPzroNARibH2rfz1rkg4H0=
387390
github.com/containerd/aufs v1.0.0 h1:2oeJiwX5HstO7shSrPZjrohJZLzK36wvpdmzDRkL/LY=
@@ -1388,6 +1391,8 @@ github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH
13881391
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
13891392
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
13901393
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
1394+
github.com/pdtpartners/nix-snapshotter v0.1.2-0.20240214230725-1c25427973e0 h1:d3mKjpcgmkgaGl6RiMRabjSqo8bHdavPonv6P/zaqpw=
1395+
github.com/pdtpartners/nix-snapshotter v0.1.2-0.20240214230725-1c25427973e0/go.mod h1:MKa+V5fH15XmLCDt+s8qRQeIAaadaJ3/4+/oD7f0K0k=
13911396
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
13921397
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
13931398
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
@@ -2205,8 +2210,9 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
22052210
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
22062211
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
22072212
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
2208-
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
22092213
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
2214+
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
2215+
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
22102216
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
22112217
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
22122218
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

pkg/agent/config/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
556556
nodeConfig.Containerd.Root)
557557
}
558558
nodeConfig.AgentConfig.ImageServiceSocket = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock"
559+
case "nix":
560+
if err := containerd.NixSupported(nodeConfig.Containerd.Root); err != nil {
561+
return nil, errors.Wrapf(err, "\"nix\" snapshotter cannot be enabled for %q, try using \"overlayfs\" or \"native\"",
562+
nodeConfig.Containerd.Root)
563+
}
564+
nodeConfig.AgentConfig.ImageServiceSocket = "/run/k3s/nix-snapshotter/nix-snapshotter.sock"
559565
}
560566
} else {
561567
nodeConfig.AgentConfig.ImageServiceSocket = nodeConfig.ContainerRuntimeEndpoint

pkg/agent/containerd/config_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/k3s-io/k3s/pkg/daemons/config"
1717
"github.com/k3s-io/k3s/pkg/version"
1818
"github.com/opencontainers/runc/libcontainer/userns"
19+
"github.com/pdtpartners/nix-snapshotter/pkg/nix"
1920
"github.com/pkg/errors"
2021
"github.com/sirupsen/logrus"
2122
"golang.org/x/sys/unix"
@@ -117,3 +118,7 @@ func FuseoverlayfsSupported(root string) error {
117118
func StargzSupported(root string) error {
118119
return stargz.Supported(root)
119120
}
121+
122+
func NixSupported(root string) error {
123+
return nix.Supported(root)
124+
}

pkg/agent/containerd/config_windows.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ func FuseoverlayfsSupported(root string) error {
6464
func StargzSupported(root string) error {
6565
return errors.Wrapf(util3.ErrUnsupportedPlatform, "stargz is not supported")
6666
}
67+
68+
func NixSupported(root string) error {
69+
return errors.Wrapf(util3.ErrUnsupportedPlatform, "nix is not supported")
70+
}

pkg/agent/templates/templates_linux.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ version = 2
3535
{{- if .NodeConfig.AgentConfig.Snapshotter }}
3636
[plugins."io.containerd.grpc.v1.cri".containerd]
3737
snapshotter = "{{ .NodeConfig.AgentConfig.Snapshotter }}"
38-
disable_snapshot_annotations = {{ if eq .NodeConfig.AgentConfig.Snapshotter "stargz" }}false{{else}}true{{end}}
38+
disable_snapshot_annotations = {{ if or (eq .NodeConfig.AgentConfig.Snapshotter "stargz") (eq .NodeConfig.AgentConfig.Snapshotter "nix") }}false{{else}}true{{end}}
3939
{{ if .NodeConfig.DefaultRuntime }}default_runtime_name = "{{ .NodeConfig.DefaultRuntime }}"{{end}}
4040
{{ if eq .NodeConfig.AgentConfig.Snapshotter "stargz" }}
4141
{{ if .NodeConfig.AgentConfig.ImageServiceSocket }}
@@ -75,6 +75,14 @@ enable_keychain = true
7575
{{end}}
7676
{{end}}
7777
{{end}}
78+
{{ if eq .NodeConfig.AgentConfig.Snapshotter "nix" }}
79+
[plugins."io.containerd.snapshotter.v1.nix"]
80+
address = "{{ .NodeConfig.AgentConfig.ImageServiceSocket }}"
81+
image_service.enable = true
82+
[[plugins."io.containerd.transfer.v1.local".unpack_config]]
83+
platform = "linux/amd64"
84+
snapshotter = "nix"
85+
{{end}}
7886
{{end}}
7987
8088
{{- if not .NodeConfig.NoFlannel }}

pkg/containerd/builtins_linux.go

+1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ import (
3232
_ "github.com/containerd/fuse-overlayfs-snapshotter/plugin"
3333
_ "github.com/containerd/stargz-snapshotter/service/plugin"
3434
_ "github.com/containerd/zfs/plugin"
35+
_ "github.com/pdtpartners/nix-snapshotter/pkg/plugin"
3536
)

pkg/containerd/utility_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
77
fuseoverlayfs "github.com/containerd/fuse-overlayfs-snapshotter"
88
stargz "github.com/containerd/stargz-snapshotter/service"
9+
"github.com/pdtpartners/nix-snapshotter/pkg/nix"
910
)
1011

1112
func OverlaySupported(root string) error {
@@ -19,3 +20,7 @@ func FuseoverlayfsSupported(root string) error {
1920
func StargzSupported(root string) error {
2021
return stargz.Supported(root)
2122
}
23+
24+
func NixSupported(root string) error {
25+
return nix.Supported(root)
26+
}

pkg/containerd/utility_windows.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ func FuseoverlayfsSupported(root string) error {
1919
func StargzSupported(root string) error {
2020
return errors.Wrapf(util2.ErrUnsupportedPlatform, "stargz is not supported")
2121
}
22+
23+
func NixSupported(root string) error {
24+
return errors.Wrapf(util2.ErrUnsupportedPlatform, "nix is not supported")
25+
}

0 commit comments

Comments
 (0)