Skip to content

Commit

Permalink
Merge pull request #8106 from cpuguy83/1.6_loosen_windows_platform_ma…
Browse files Browse the repository at this point in the history
…tching

[1.6] Add fallback for windows platforms without osversion
  • Loading branch information
kzys committed Feb 15, 2023
2 parents 47f1aad + b327af6 commit 9cec7a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 8 additions & 4 deletions platforms/defaults_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ type matchComparer struct {

// Match matches platform with the same windows major, minor
// and build version.
func (m matchComparer) Match(p imagespec.Platform) bool {
if m.defaults.Match(p) {
// TODO(windows): Figure out whether OSVersion is deprecated.
return strings.HasPrefix(p.OSVersion, m.osVersionPrefix)
func (m matchComparer) Match(p specs.Platform) bool {
match := m.defaults.Match(p)

if match && p.OS == "windows" {
if strings.HasPrefix(p.OSVersion, m.osVersionPrefix) {
return true
}
return p.OSVersion == ""
}
return false
}
Expand Down
4 changes: 2 additions & 2 deletions platforms/defaults_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestMatchComparerMatch(t *testing.T) {
Architecture: "amd64",
OS: "windows",
},
match: false,
match: true,
},
} {
assert.Equal(t, test.match, m.Match(test.platform))
Expand Down Expand Up @@ -159,11 +159,11 @@ func TestMatchComparerLess(t *testing.T) {
{
Architecture: "amd64",
OS: "windows",
OSVersion: "10.0.17764.1",
},
{
Architecture: "amd64",
OS: "windows",
OSVersion: "10.0.17764.1",
},
{
Architecture: "amd64",
Expand Down
14 changes: 14 additions & 0 deletions platforms/platforms_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ package platforms
import (
"testing"

specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/require"
)

func TestNormalize(t *testing.T) {
require.Equal(t, DefaultSpec(), Normalize(DefaultSpec()))
}

func TestFallbackOnOSVersion(t *testing.T) {
p := specs.Platform{
OS: "windows",
Architecture: "amd64",
OSVersion: "99.99.99.99",
}

other := specs.Platform{OS: p.OS, Architecture: p.Architecture}

m := NewMatcher(p)
require.True(t, m.Match(other))
}

0 comments on commit 9cec7a8

Please sign in to comment.