-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore variant when looking up command for platform in entrypoint
This change changes our runtime platform selection logic to allow matching platforms that don't match the CPU variant, since some indexes only provide the variant-less platform, and should be chosen in that case rather than failing. If the platform's command is found including the CPU variant, it will be used. If not, we'll also check if there's a variant-less platform that matches, and if so, we'll use that command.
- Loading branch information
1 parent
ed4200b
commit 6cb0f4c
Showing
6 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestSelectCommandForPlatform(t *testing.T) { | ||
for _, c := range []struct { | ||
desc string | ||
m map[string][]string | ||
plat string | ||
want []string | ||
wantErr bool | ||
}{{ | ||
desc: "platform exists", | ||
m: map[string][]string{ | ||
"linux/amd64": {"my", "command"}, | ||
"linux/s390x": {"other", "one"}, | ||
}, | ||
plat: "linux/amd64", | ||
want: []string{"my", "command"}, | ||
}, { | ||
desc: "platform not found", | ||
m: map[string][]string{ | ||
"linux/amd64": {"my", "command"}, | ||
"linux/s390x": {"other", "one"}, | ||
}, | ||
plat: "linux/ppc64le", | ||
wantErr: true, | ||
}, { | ||
desc: "platform fallback", | ||
m: map[string][]string{ | ||
"linux/amd64": {"my", "command"}, | ||
"linux/s390x": {"other", "one"}, | ||
}, | ||
plat: "linux/amd64/v8", | ||
want: []string{"my", "command"}, | ||
}, { | ||
desc: "platform fallback not needed", | ||
m: map[string][]string{ | ||
"linux/amd64": {"other", "one"}, | ||
"linux/amd64/v8": {"my", "command"}, | ||
}, | ||
plat: "linux/amd64/v8", | ||
want: []string{"my", "command"}, | ||
}} { | ||
t.Run(c.desc, func(t *testing.T) { | ||
got, err := selectCommandForPlatform(c.m, c.plat) | ||
if err != nil { | ||
if c.wantErr { | ||
return | ||
} | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
if d := cmp.Diff(c.want, got); d != "" { | ||
t.Fatalf("Diff(-want,+got):\n%s", d) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
/* | ||
|