config: check Runtime.Arch

This commit is contained in:
Simone Gotti 2019-04-17 15:24:37 +02:00
parent 22f0865aa3
commit f3e583bb40
3 changed files with 53 additions and 0 deletions

View File

@ -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 ""
}

View File

@ -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)
}
}
}
}

View File

@ -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: `