Skip to content

Commit b034dc4

Browse files
committed
deprecate pkg/platform and move internal
Functions in this package are only used internally in the daemon for the `/info` endpoint (Architecture), and as part of `stats` (NumProcs). I was not able to find external consumers, but deprecating the package first, so that we can remove / dismantle the package in a follow-up. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a95a678 commit b034dc4

6 files changed

Lines changed: 56 additions & 15 deletions

File tree

daemon/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"github.com/docker/docker/daemon/config"
2121
"github.com/docker/docker/daemon/logger"
2222
"github.com/docker/docker/dockerversion"
23+
"github.com/docker/docker/internal/platform"
2324
"github.com/docker/docker/pkg/fileutils"
2425
"github.com/docker/docker/pkg/meminfo"
2526
"github.com/docker/docker/pkg/parsers/kernel"
2627
"github.com/docker/docker/pkg/parsers/operatingsystem"
27-
"github.com/docker/docker/pkg/platform"
2828
"github.com/docker/docker/pkg/sysinfo"
2929
"github.com/docker/docker/registry"
3030
metrics "github.com/docker/go-metrics"
@@ -63,7 +63,7 @@ func (daemon *Daemon) SystemInfo(ctx context.Context) (*system.Info, error) {
6363
OSVersion: osVersion(ctx),
6464
IndexServerAddress: registry.IndexServer,
6565
OSType: runtime.GOOS,
66-
Architecture: platform.Architecture,
66+
Architecture: platform.Architecture(),
6767
RegistryConfig: doWithTrace(ctx, "registry.ServiceConfig", daemon.registryService.ServiceConfig),
6868
NCPU: doWithTrace(ctx, "sysinfo.NumCPU", sysinfo.NumCPU),
6969
MemTotal: memInfo(ctx).MemTotal,

daemon/stats_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
containertypes "github.com/docker/docker/api/types/container"
77
"github.com/docker/docker/container"
88
"github.com/docker/docker/errdefs"
9-
"github.com/docker/docker/pkg/platform"
9+
"github.com/docker/docker/internal/platform"
1010
)
1111

1212
func (daemon *Daemon) stats(c *container.Container) (*containertypes.StatsResponse, error) {

internal/platform/platform.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package platform
2+
3+
import (
4+
"context"
5+
"sync"
6+
7+
"github.com/containerd/log"
8+
)
9+
10+
var (
11+
arch string
12+
onceArch sync.Once
13+
)
14+
15+
// Architecture returns the runtime architecture of the process.
16+
//
17+
// Unlike [runtime.GOARCH] (which refers to the compiler platform),
18+
// Architecture refers to the running platform.
19+
//
20+
// For example, Architecture reports "x86_64" as architecture, even
21+
// when running a "linux/386" compiled binary on "linux/amd64" hardware.
22+
func Architecture() string {
23+
onceArch.Do(func() {
24+
var err error
25+
arch, err = runtimeArchitecture()
26+
if err != nil {
27+
log.G(context.TODO()).WithError(err).Error("Could not read system architecture info")
28+
}
29+
})
30+
return arch
31+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !windows
22

3-
package platform // import "github.com/docker/docker/pkg/platform"
3+
package platform
44

55
import (
66
"golang.org/x/sys/unix"
@@ -14,3 +14,12 @@ func runtimeArchitecture() (string, error) {
1414
}
1515
return unix.ByteSliceToString(utsname.Machine[:]), nil
1616
}
17+
18+
// NumProcs returns the number of processors on the system
19+
//
20+
// Deprecated: temporary stub for non-Windows to provide an alias for the deprecated github.com/docker/docker/pkg/platform package.
21+
//
22+
// FIXME(thaJeztah): remove once we remove github.com/docker/docker/pkg/platform
23+
func NumProcs() uint32 {
24+
return 0
25+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package platform // import "github.com/docker/docker/pkg/platform"
1+
package platform
22

33
import (
44
"fmt"

pkg/platform/platform.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Package platform provides helper function to get the runtime architecture
22
// for different platforms.
3+
//
4+
// Deprecated: this package is only used internally, and will be removed in the next release.
35
package platform // import "github.com/docker/docker/pkg/platform"
46

57
import (
6-
"context"
7-
8-
"github.com/containerd/log"
8+
"github.com/docker/docker/internal/platform"
99
)
1010

1111
// Architecture holds the runtime architecture of the process.
@@ -15,12 +15,13 @@ import (
1515
//
1616
// For example, Architecture reports "x86_64" as architecture, even
1717
// when running a "linux/386" compiled binary on "linux/amd64" hardware.
18-
var Architecture string
18+
//
19+
// Deprecated: this package is only used internally, and will be removed in the next release.
20+
var Architecture = platform.Architecture()
1921

20-
func init() {
21-
var err error
22-
Architecture, err = runtimeArchitecture()
23-
if err != nil {
24-
log.G(context.TODO()).WithError(err).Error("Could not read system architecture info")
25-
}
22+
// NumProcs returns the number of processors on the system
23+
//
24+
// Deprecated: this package is only used internally, and will be removed in the next release.
25+
func NumProcs() uint32 {
26+
return platform.NumProcs()
2627
}

0 commit comments

Comments
 (0)