Browse code

pkg/system: remove EnableContainerdRuntime, ContainerdRuntimeSupported

These functions were used internally to keep track of whether containerd
was enabled as runtime on Windows; move it to libcontainerd.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/07/13 02:16:30
Showing 4 changed files
... ...
@@ -9,7 +9,7 @@ import (
9 9
 
10 10
 	"github.com/containerd/log"
11 11
 	"github.com/docker/docker/daemon/config"
12
-	"github.com/docker/docker/pkg/system"
12
+	"github.com/docker/docker/daemon/internal/libcontainerd"
13 13
 	"golang.org/x/sys/windows"
14 14
 )
15 15
 
... ...
@@ -101,7 +101,11 @@ func newCgroupParent(*config.Config) string {
101 101
 }
102 102
 
103 103
 func (cli *daemonCLI) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
104
-	defer func() { system.EnableContainerdRuntime(cli.Config.ContainerdAddr) }()
104
+	defer func() {
105
+		if cli.Config.ContainerdAddr != "" {
106
+			libcontainerd.ContainerdRuntimeEnabled = true
107
+		}
108
+	}()
105 109
 
106 110
 	if cli.Config.ContainerdAddr != "" {
107 111
 		return nil, nil
... ...
@@ -7,12 +7,16 @@ import (
7 7
 	"github.com/docker/docker/daemon/internal/libcontainerd/local"
8 8
 	"github.com/docker/docker/daemon/internal/libcontainerd/remote"
9 9
 	libcontainerdtypes "github.com/docker/docker/daemon/internal/libcontainerd/types"
10
-	"github.com/docker/docker/pkg/system"
11 10
 )
12 11
 
12
+// ContainerdRuntimeEnabled determines whether to use containerd for runtime on Windows.
13
+//
14
+// TODO(thaJeztah): this value is equivalent to checking whether "cli.Config.ContainerdAddr != """ - do we really need it?
15
+var ContainerdRuntimeEnabled = false
16
+
13 17
 // NewClient creates a new libcontainerd client from a containerd client
14 18
 func NewClient(ctx context.Context, cli *containerd.Client, stateDir, ns string, b libcontainerdtypes.Backend) (libcontainerdtypes.Client, error) {
15
-	if !system.ContainerdRuntimeSupported() {
19
+	if !ContainerdRuntimeEnabled {
16 20
 		return local.NewClient(ctx, b)
17 21
 	}
18 22
 	return remote.NewClient(ctx, cli, stateDir, ns, b)
... ...
@@ -4,11 +4,11 @@ import (
4 4
 	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
5 5
 	"github.com/docker/docker/daemon/config"
6 6
 	"github.com/docker/docker/daemon/container"
7
-	"github.com/docker/docker/pkg/system"
7
+	"github.com/docker/docker/daemon/internal/libcontainerd"
8 8
 )
9 9
 
10 10
 func (daemon *Daemon) getLibcontainerdCreateOptions(*configStore, *container.Container) (string, interface{}, error) {
11
-	if system.ContainerdRuntimeSupported() {
11
+	if libcontainerd.ContainerdRuntimeEnabled {
12 12
 		opts := &options.Options{}
13 13
 		return config.WindowsV2RuntimeName, opts, nil
14 14
 	}
15 15
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-package system
2
-
3
-// containerdRuntimeSupported determines if containerd should be the runtime.
4
-var containerdRuntimeSupported = false
5
-
6
-// EnableContainerdRuntime sets whether to use containerd for runtime on Windows.
7
-func EnableContainerdRuntime(cdPath string) {
8
-	if len(cdPath) > 0 {
9
-		containerdRuntimeSupported = true
10
-	}
11
-}
12
-
13
-// ContainerdRuntimeSupported returns true if the use of containerd runtime is supported.
14
-func ContainerdRuntimeSupported() bool {
15
-	return containerdRuntimeSupported
16
-}