From 50cbdfcbadd322b6a63068d97150c7fa2bc5181a Mon Sep 17 00:00:00 2001 From: Kohei Tokunaga Date: Fri, 25 Mar 2022 18:38:37 +0900 Subject: [PATCH] Add check of snapshotter when sharing images Signed-off-by: Kohei Tokunaga --- cmd/nerdctl/build.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/nerdctl/build.go b/cmd/nerdctl/build.go index a8baccd6fcb..11b4c2ea2bd 100644 --- a/cmd/nerdctl/build.go +++ b/cmd/nerdctl/build.go @@ -93,7 +93,7 @@ func getBuildkitHost(cmd *cobra.Command) (string, error) { return buildkitutil.GetBuildkitHost(ns) } -func isImageSharable(buildkitHost string, namespace, uuid string) (bool, error) { +func isImageSharable(buildkitHost string, namespace, uuid, snapshotter string) (bool, error) { labels, err := buildkitutil.GetWorkerLabels(buildkitHost) if err != nil { return false, err @@ -111,7 +111,11 @@ func isImageSharable(buildkitHost string, namespace, uuid string) (bool, error) if !ok { return false, nil } - return executor == "containerd" && containerdUUID == uuid && containerdNamespace == namespace, nil + workerSnapshotter, ok := labels["org.mobyproject.buildkit.worker.snapshotter"] + if !ok { + return false, nil + } + return executor == "containerd" && containerdUUID == uuid && containerdNamespace == namespace && workerSnapshotter == snapshotter, nil } func buildAction(cmd *cobra.Command, args []string) error { @@ -235,7 +239,11 @@ func generateBuildctlArgs(cmd *cobra.Command, buildkitHost string, platform, arg if err != nil { return "", nil, false, "", nil, err } - sharable, err := isImageSharable(buildkitHost, ns, info.UUID) + snapshotter, err := cmd.Flags().GetString("snapshotter") + if err != nil { + return "", nil, false, "", nil, err + } + sharable, err := isImageSharable(buildkitHost, ns, info.UUID, snapshotter) if err != nil { return "", nil, false, "", nil, err }