diff --git a/internal/common/arch.go b/internal/common/arch.go index 5d2dd90..590b829 100644 --- a/internal/common/arch.go +++ b/internal/common/arch.go @@ -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 "" +} diff --git a/internal/config/config.go b/internal/config/config.go index 9742aea..ccd846b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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) + } + } } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 968b8be..3cea1a5 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -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: `