Skip to content

Commit bf134c3

Browse files
authored
Merge pull request #865 from mtrmac/variant-on-overidden-arch
Only auto-detect platform variant if we are also auto-detecting the architecture
2 parents d9b1d8e + d85425d commit bf134c3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/pkg/platform/platform_matcher.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,26 @@ var compatibility = map[string][]string{
125125
// If some option (arch, os, variant) is not present, a value from current platform is detected.
126126
func WantedPlatforms(ctx *types.SystemContext) ([]imgspecv1.Platform, error) {
127127
wantedArch := runtime.GOARCH
128+
wantedVariant := ""
128129
if ctx != nil && ctx.ArchitectureChoice != "" {
129130
wantedArch = ctx.ArchitectureChoice
131+
} else {
132+
// Only auto-detect the variant if we are using the default architecture.
133+
// If the user has specified the ArchitectureChoice, don't autodetect, even if
134+
// ctx.ArchitectureChoice == runtime.GOARCH, because we have no idea whether the runtime.GOARCH
135+
// value is relevant to the use case, and if we do autodetect a variant,
136+
// ctx.VariantChoice can't be used to override it back to "".
137+
wantedVariant = getCPUVariant(runtime.GOOS, runtime.GOARCH)
130138
}
139+
if ctx != nil && ctx.VariantChoice != "" {
140+
wantedVariant = ctx.VariantChoice
141+
}
142+
131143
wantedOS := runtime.GOOS
132144
if ctx != nil && ctx.OSChoice != "" {
133145
wantedOS = ctx.OSChoice
134146
}
135147

136-
wantedVariant := getCPUVariant(runtime.GOOS, runtime.GOARCH)
137-
if ctx != nil && ctx.VariantChoice != "" {
138-
wantedVariant = ctx.VariantChoice
139-
}
140-
141148
var wantedPlatforms []imgspecv1.Platform
142149
if wantedVariant != "" && compatibility[wantedArch] != nil {
143150
wantedPlatforms = make([]imgspecv1.Platform, 0, len(compatibility[wantedArch]))

0 commit comments

Comments
 (0)