Skip to content

Commit

Permalink
Merge pull request moby#48862 from thaJeztah/deprecate_pkg_platform
Browse files Browse the repository at this point in the history
deprecate pkg/platform and move internal
  • Loading branch information
thaJeztah authored Nov 13, 2024
2 parents a95a678 + b034dc4 commit d0a4bbc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions daemon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion daemon/stats_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions internal/platform/platform.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !windows

package platform // import "github.com/docker/docker/pkg/platform"
package platform

import (
"golang.org/x/sys/unix"
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package platform // import "github.com/docker/docker/pkg/platform"
package platform

import (
"fmt"
Expand Down
21 changes: 11 additions & 10 deletions pkg/platform/platform.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()
}

0 comments on commit d0a4bbc

Please sign in to comment.