mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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 <github@gone.nl>
This commit is contained in:
@@ -20,11 +20,11 @@ import (
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/internal/platform"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
"github.com/docker/docker/pkg/meminfo"
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
"github.com/docker/docker/pkg/parsers/operatingsystem"
|
||||
"github.com/docker/docker/pkg/platform"
|
||||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"github.com/docker/docker/registry"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
@@ -63,7 +63,7 @@ func (daemon *Daemon) SystemInfo(ctx context.Context) (*system.Info, error) {
|
||||
OSVersion: osVersion(ctx),
|
||||
IndexServerAddress: registry.IndexServer,
|
||||
OSType: runtime.GOOS,
|
||||
Architecture: platform.Architecture,
|
||||
Architecture: platform.Architecture(),
|
||||
RegistryConfig: doWithTrace(ctx, "registry.ServiceConfig", daemon.registryService.ServiceConfig),
|
||||
NCPU: doWithTrace(ctx, "sysinfo.NumCPU", sysinfo.NumCPU),
|
||||
MemTotal: memInfo(ctx).MemTotal,
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/platform"
|
||||
"github.com/docker/docker/internal/platform"
|
||||
)
|
||||
|
||||
func (daemon *Daemon) stats(c *container.Container) (*containertypes.StatsResponse, error) {
|
||||
|
||||
31
internal/platform/platform.go
Normal file
31
internal/platform/platform.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/log"
|
||||
)
|
||||
|
||||
var (
|
||||
arch string
|
||||
onceArch sync.Once
|
||||
)
|
||||
|
||||
// Architecture returns the runtime architecture of the process.
|
||||
//
|
||||
// Unlike [runtime.GOARCH] (which refers to the compiler platform),
|
||||
// Architecture refers to the running platform.
|
||||
//
|
||||
// For example, Architecture reports "x86_64" as architecture, even
|
||||
// when running a "linux/386" compiled binary on "linux/amd64" hardware.
|
||||
func Architecture() string {
|
||||
onceArch.Do(func() {
|
||||
var err error
|
||||
arch, err = runtimeArchitecture()
|
||||
if err != nil {
|
||||
log.G(context.TODO()).WithError(err).Error("Could not read system architecture info")
|
||||
}
|
||||
})
|
||||
return arch
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !windows
|
||||
|
||||
package platform // import "github.com/docker/docker/pkg/platform"
|
||||
package platform
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -14,3 +14,12 @@ func runtimeArchitecture() (string, error) {
|
||||
}
|
||||
return unix.ByteSliceToString(utsname.Machine[:]), nil
|
||||
}
|
||||
|
||||
// NumProcs returns the number of processors on the system
|
||||
//
|
||||
// Deprecated: temporary stub for non-Windows to provide an alias for the deprecated github.com/docker/docker/pkg/platform package.
|
||||
//
|
||||
// FIXME(thaJeztah): remove once we remove github.com/docker/docker/pkg/platform
|
||||
func NumProcs() uint32 {
|
||||
return 0
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package platform // import "github.com/docker/docker/pkg/platform"
|
||||
package platform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,11 +1,11 @@
|
||||
// Package platform provides helper function to get the runtime architecture
|
||||
// for different platforms.
|
||||
//
|
||||
// Deprecated: this package is only used internally, and will be removed in the next release.
|
||||
package platform // import "github.com/docker/docker/pkg/platform"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/internal/platform"
|
||||
)
|
||||
|
||||
// Architecture holds the runtime architecture of the process.
|
||||
@@ -15,12 +15,13 @@ import (
|
||||
//
|
||||
// For example, Architecture reports "x86_64" as architecture, even
|
||||
// when running a "linux/386" compiled binary on "linux/amd64" hardware.
|
||||
var Architecture string
|
||||
//
|
||||
// Deprecated: this package is only used internally, and will be removed in the next release.
|
||||
var Architecture = platform.Architecture()
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
Architecture, err = runtimeArchitecture()
|
||||
if err != nil {
|
||||
log.G(context.TODO()).WithError(err).Error("Could not read system architecture info")
|
||||
}
|
||||
// NumProcs returns the number of processors on the system
|
||||
//
|
||||
// Deprecated: this package is only used internally, and will be removed in the next release.
|
||||
func NumProcs() uint32 {
|
||||
return platform.NumProcs()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user