config: check Runtime.Arch
This commit is contained in:
parent
22f0865aa3
commit
f3e583bb40
@ -22,3 +22,23 @@ const (
|
||||
ArchARM Arch = "arm"
|
||||
ArchARM64 Arch = "arm64"
|
||||
)
|
||||
|
||||
var ValidArchs = []Arch{Arch386, ArchAMD64, ArchARM, ArchARM64}
|
||||
|
||||
func IsValidArch(arch Arch) bool {
|
||||
for _, va := range ValidArchs {
|
||||
if arch == va {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ArchFromString(arch string) Arch {
|
||||
for _, va := range ValidArchs {
|
||||
if arch == string(va) {
|
||||
return va
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -681,6 +681,11 @@ func checkConfig(config *Config) error {
|
||||
if len(r.Containers) == 0 {
|
||||
return errors.Errorf("task %q runtime: at least one container must be defined", task.Name)
|
||||
}
|
||||
if r.Arch != "" {
|
||||
if !common.IsValidArch(r.Arch) {
|
||||
return errors.Errorf("task %q runtime: invalid arch %q", task.Name, r.Arch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,34 @@ func TestParseConfig(t *testing.T) {
|
||||
`,
|
||||
err: fmt.Errorf(`run "run01": task at index 0 is empty`),
|
||||
},
|
||||
{
|
||||
name: "test empty runtime arch",
|
||||
in: `
|
||||
runs:
|
||||
- name: run01
|
||||
tasks:
|
||||
- name: task01
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "test invalid runtime arch",
|
||||
in: `
|
||||
runs:
|
||||
- name: run01
|
||||
tasks:
|
||||
- name: task01
|
||||
runtime:
|
||||
type: pod
|
||||
arch: invalidarch
|
||||
containers:
|
||||
- image: busybox
|
||||
`,
|
||||
err: fmt.Errorf(`task "task01" runtime: invalid arch "invalidarch"`),
|
||||
},
|
||||
{
|
||||
name: "test missing task dependency",
|
||||
in: `
|
||||
|
Loading…
Reference in New Issue
Block a user