diff --git a/go.mod b/go.mod index b973b2476b16..dab0bcc98287 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/containerd/go-runc v1.1.0 github.com/containerd/log v0.1.0 github.com/containerd/nydus-snapshotter v0.15.13 - github.com/containerd/platforms v1.0.0-rc.3 + github.com/containerd/platforms v1.0.0-rc.2 github.com/containerd/stargz-snapshotter v0.18.2 github.com/containerd/stargz-snapshotter/estargz v0.18.2 github.com/containerd/typeurl/v2 v2.2.3 diff --git a/go.sum b/go.sum index 166e2f15faf7..ca412796392e 100644 --- a/go.sum +++ b/go.sum @@ -159,8 +159,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containerd/nydus-snapshotter v0.15.13 h1:z9yCiTPMxVBIZlHxOPinZXhly2MdcIqxk9VXPlHIOJY= github.com/containerd/nydus-snapshotter v0.15.13/go.mod h1:t95dwCb4I0RE4n1iOk0sJCWosNoACA8daOXmU5A2VHI= -github.com/containerd/platforms v1.0.0-rc.3 h1:YdvwaHtrN6wHcGJ2mYRYP3Nso8OcysuqFe9Hxm1X/tI= -github.com/containerd/platforms v1.0.0-rc.3/go.mod h1:gw0R+alP3nFQPh1L4K9bv13fRWeeyokLGLu2fKuqI10= +github.com/containerd/platforms v1.0.0-rc.2 h1:0SPgaNZPVWGEi4grZdV8VRYQn78y+nm6acgLGv/QzE4= +github.com/containerd/platforms v1.0.0-rc.2/go.mod h1:J71L7B+aiM5SdIEqmd9wp6THLVRzJGXfNuWCZCllLA4= github.com/containerd/plugin v1.0.0 h1:c8Kf1TNl6+e2TtMHZt+39yAPDbouRH9WAToRjex483Y= github.com/containerd/plugin v1.0.0/go.mod h1:hQfJe5nmWfImiqT1q8Si3jLv3ynMUIBB47bQ+KexvO8= github.com/containerd/stargz-snapshotter v0.18.2 h1:Ev/sxfQUjwzJQ9eqy3XzttcQ3osMIqkQgMYlcET+10M= diff --git a/vendor/github.com/containerd/platforms/.golangci.yml b/vendor/github.com/containerd/platforms/.golangci.yml index 9320503c7ba3..d574fe11d79f 100644 --- a/vendor/github.com/containerd/platforms/.golangci.yml +++ b/vendor/github.com/containerd/platforms/.golangci.yml @@ -1,25 +1,32 @@ -version: "2" linters: enable: - copyloopvar - - dupword + - gofmt + - goimports - gosec + - ineffassign - misspell - nolintlint - revive + - staticcheck + - tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17 - unconvert + - unused + - govet + - dupword # Checks for duplicate words in the source code disable: - errcheck - exclusions: - generated: lax - presets: - - comments - - common-false-positives - - legacy - - std-error-handling -formatters: - enable: - - gofmt - - goimports - exclusions: - generated: lax + +run: + timeout: 5m + +issues: + exclude-dirs: + - api + - cluster + - design + - docs + - docs/man + - releases + - reports + - test # e2e scripts diff --git a/vendor/github.com/containerd/platforms/compare.go b/vendor/github.com/containerd/platforms/compare.go index 802b860452d0..24403f3b3d45 100644 --- a/vendor/github.com/containerd/platforms/compare.go +++ b/vendor/github.com/containerd/platforms/compare.go @@ -213,20 +213,9 @@ func (c orderedPlatformComparer) Less(p1 specs.Platform, p2 specs.Platform) bool return true } if p1m || p2m { - if p1m && p2m { - // Prefer one with most matching features - if len(p1.OSFeatures) != len(p2.OSFeatures) { - return len(p1.OSFeatures) > len(p2.OSFeatures) - } - } return false } } - if len(p1.OSFeatures) > 0 || len(p2.OSFeatures) > 0 { - p1.OSFeatures = nil - p2.OSFeatures = nil - return c.Less(p1, p2) - } return false } @@ -253,20 +242,9 @@ func (c anyPlatformComparer) Less(p1, p2 specs.Platform) bool { p2m = true } if p1m && p2m { - if len(p1.OSFeatures) != len(p2.OSFeatures) { - return len(p1.OSFeatures) > len(p2.OSFeatures) - } - break + return false } } - - // If neither match and has features, strip features and compare - if !p1m && !p2m && (len(p1.OSFeatures) > 0 || len(p2.OSFeatures) > 0) { - p1.OSFeatures = nil - p2.OSFeatures = nil - return c.Less(p1, p2) - } - // If one matches, and the other does, sort match first return p1m && !p2m } diff --git a/vendor/github.com/containerd/platforms/cpuinfo_other.go b/vendor/github.com/containerd/platforms/cpuinfo_other.go index 5bbfef70425e..97a1fe8a3e55 100644 --- a/vendor/github.com/containerd/platforms/cpuinfo_other.go +++ b/vendor/github.com/containerd/platforms/cpuinfo_other.go @@ -27,8 +27,7 @@ func getCPUVariant() (string, error) { var variant string - switch runtime.GOOS { - case "windows", "darwin": + if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { // Windows/Darwin only supports v7 for ARM32 and v8 for ARM64 and so we can use // runtime.GOARCH to determine the variants switch runtime.GOARCH { @@ -39,7 +38,7 @@ func getCPUVariant() (string, error) { default: variant = "unknown" } - case "freebsd": + } else if runtime.GOOS == "freebsd" { // FreeBSD supports ARMv6 and ARMv7 as well as ARMv4 and ARMv5 (though deprecated) // detecting those variants is currently unimplemented switch runtime.GOARCH { @@ -48,7 +47,7 @@ func getCPUVariant() (string, error) { default: variant = "unknown" } - default: + } else { return "", fmt.Errorf("getCPUVariant for OS %s: %v", runtime.GOOS, errNotImplemented) } diff --git a/vendor/github.com/containerd/platforms/platforms.go b/vendor/github.com/containerd/platforms/platforms.go index 2d9b3c204c30..14d65abd4f86 100644 --- a/vendor/github.com/containerd/platforms/platforms.go +++ b/vendor/github.com/containerd/platforms/platforms.go @@ -111,11 +111,9 @@ package platforms import ( "fmt" - "net/url" "path" "regexp" "runtime" - "slices" "strconv" "strings" @@ -123,10 +121,12 @@ import ( ) var ( - specifierRe = regexp.MustCompile(`^[A-Za-z0-9_.-]+$`) - osRe = regexp.MustCompile(`^([A-Za-z0-9_-]+)(?:\(([A-Za-z0-9_.%-]*)((?:\+[A-Za-z0-9_.%-]+)*)\))?$`) + specifierRe = regexp.MustCompile(`^[A-Za-z0-9_.-]+$`) + osAndVersionRe = regexp.MustCompile(`^([A-Za-z0-9_-]+)(?:\(([A-Za-z0-9_.-]*)\))?$`) ) +const osAndVersionFormat = "%s(%s)" + // Platform is a type alias for convenience, so there is no need to import image-spec package everywhere. type Platform = specs.Platform @@ -143,10 +143,6 @@ type Matcher interface { // functionality. // // Applications should opt to use `Match` over directly parsing specifiers. -// -// For OSFeatures, this matcher will match if the platform to match has -// OSFeatures which are a subset of the OSFeatures of the platform -// provided to NewMatcher. func NewMatcher(platform specs.Platform) Matcher { m := &matcher{ Platform: Normalize(platform), @@ -182,39 +178,10 @@ type matcher struct { func (m *matcher) Match(platform specs.Platform) bool { normalized := Normalize(platform) - if m.OS == normalized.OS && + return m.OS == normalized.OS && m.Architecture == normalized.Architecture && m.Variant == normalized.Variant && - m.matchOSVersion(platform) { - if len(normalized.OSFeatures) == 0 { - return true - } - if len(m.OSFeatures) >= len(normalized.OSFeatures) { - // Ensure that normalized.OSFeatures is a subset of - // m.OSFeatures - j := 0 - for _, feature := range normalized.OSFeatures { - found := false - for ; j < len(m.OSFeatures); j++ { - if feature == m.OSFeatures[j] { - found = true - j++ - break - } - // Since both lists are ordered, if the feature is less - // than what is seen, it is not in the list - if feature < m.OSFeatures[j] { - return false - } - } - if !found { - return false - } - } - return true - } - } - return false + m.matchOSVersion(platform) } func (m *matcher) matchOSVersion(platform specs.Platform) bool { @@ -243,14 +210,11 @@ func ParseAll(specifiers []string) ([]specs.Platform, error) { // Parse parses the platform specifier syntax into a platform declaration. // -// Platform specifiers are in the format `[()]||[()]/[/]`. +// Platform specifiers are in the format `[()]||[()]/[/]`. // The minimum required information for a platform specifier is the operating -// system or architecture. The "os options" may be OSVersion which can be part of the OS -// like `windows(10.0.17763)`. When an OSVersion is specified, then specs.Platform.OSVersion is -// populated with that value, and an empty string otherwise. The "os options" may also include an -// array of OSFeatures, each feature prefixed with '+', without any other separator, and provided -// after the OSVersion when the OSVersion is specified. An "os options" with version and features -// is like `windows(10.0.17763+win32k)`. +// system or architecture. The OSVersion can be part of the OS like `windows(10.0.17763)` +// When an OSVersion is specified, then specs.Platform.OSVersion is populated with that value, +// and an empty string otherwise. // If there is only a single string (no slashes), the // value will be matched against the known set of operating systems, then fall // back to the known set of architectures. The missing component will be @@ -267,28 +231,14 @@ func Parse(specifier string) (specs.Platform, error) { var p specs.Platform for i, part := range parts { if i == 0 { - // First element is [([+]*)] - osOptions := osRe.FindStringSubmatch(part) - if osOptions == nil { - return specs.Platform{}, fmt.Errorf("%q is an invalid OS component of %q: OSAndVersion specifier component must match %q: %w", part, specifier, osRe.String(), errInvalidArgument) + // First element is [()] + osVer := osAndVersionRe.FindStringSubmatch(part) + if osVer == nil { + return specs.Platform{}, fmt.Errorf("%q is an invalid OS component of %q: OSAndVersion specifier component must match %q: %w", part, specifier, osAndVersionRe.String(), errInvalidArgument) } - p.OS = normalizeOS(osOptions[1]) - osVersion, err := decodeOSOption(osOptions[2]) - if err != nil { - return specs.Platform{}, fmt.Errorf("%q has an invalid OS version %q: %w", specifier, osOptions[2], err) - } - p.OSVersion = osVersion - if osOptions[3] != "" { - rawFeatures := strings.Split(osOptions[3][1:], "+") - p.OSFeatures = make([]string, len(rawFeatures)) - for i, f := range rawFeatures { - p.OSFeatures[i], err = decodeOSOption(f) - if err != nil { - return specs.Platform{}, fmt.Errorf("%q has an invalid OS feature %q: %w", specifier, f, err) - } - } - } + p.OS = normalizeOS(osVer[1]) + p.OSVersion = osVer[2] } else { if !specifierRe.MatchString(part) { return specs.Platform{}, fmt.Errorf("%q is an invalid component of %q: platform specifier component must match %q: %w", part, specifier, specifierRe.String(), errInvalidArgument) @@ -372,44 +322,13 @@ func FormatAll(platform specs.Platform) string { return "unknown" } - osOptions := encodeOSOption(platform.OSVersion) - features := platform.OSFeatures - if !slices.IsSorted(features) { - features = slices.Clone(features) - slices.Sort(features) - } - for _, f := range features { - osOptions += "+" + encodeOSOption(f) - } - if osOptions != "" { - OSAndVersion := fmt.Sprintf("%s(%s)", platform.OS, osOptions) + if platform.OSVersion != "" { + OSAndVersion := fmt.Sprintf(osAndVersionFormat, platform.OS, platform.OSVersion) return path.Join(OSAndVersion, platform.Architecture, platform.Variant) } return path.Join(platform.OS, platform.Architecture, platform.Variant) } -// osOptionReplacer encodes characters in OS option values (version and -// features) that are ambiguous with the format syntax. The percent sign -// must be replaced first to avoid double-encoding. -var osOptionReplacer = strings.NewReplacer( - "%", "%25", - "+", "%2B", - "(", "%28", - ")", "%29", - "/", "%2F", -) - -func encodeOSOption(v string) string { - return osOptionReplacer.Replace(v) -} - -func decodeOSOption(v string) (string, error) { - if strings.Contains(v, "%") { - return url.PathUnescape(v) - } - return v, nil -} - // Normalize validates and translate the platform to the canonical value. // // For example, if "Aarch64" is encountered, we change it to "arm64" or if @@ -417,11 +336,6 @@ func decodeOSOption(v string) (string, error) { func Normalize(platform specs.Platform) specs.Platform { platform.OS = normalizeOS(platform.OS) platform.Architecture, platform.Variant = normalizeArch(platform.Architecture, platform.Variant) - if len(platform.OSFeatures) > 0 { - platform.OSFeatures = slices.Clone(platform.OSFeatures) - slices.Sort(platform.OSFeatures) - platform.OSFeatures = slices.Compact(platform.OSFeatures) - } return platform } diff --git a/vendor/modules.txt b/vendor/modules.txt index cc2baeae973e..801e4466b8b8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -472,8 +472,8 @@ github.com/containerd/log github.com/containerd/nydus-snapshotter/pkg/converter github.com/containerd/nydus-snapshotter/pkg/converter/tool github.com/containerd/nydus-snapshotter/pkg/label -# github.com/containerd/platforms v1.0.0-rc.3 -## explicit; go 1.21 +# github.com/containerd/platforms v1.0.0-rc.2 +## explicit; go 1.20 github.com/containerd/platforms # github.com/containerd/plugin v1.0.0 ## explicit; go 1.20