Panic for GCP provider on zone parsing
Overview
Having the following config file
Provider = "gcp"
Executor = "winrm"
OS = "windows"
VMMetadataRegistry = "file"
LogLevel = "debug"
[GCP]
ServiceAccountFile = "xxx"
Project = "xxxxx"
Zone = "europe-west4-c"
MachineType = "n1-standard-2"
Image="windows-server-2019-dc-for-containers-v20190827"
DiskSize=50
When autoscaler create-vm testvm
is run we get the following panic error:
goroutine 1 [running]:
gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/providers/gcp.zoneToRegion(0xc000240200, 0xe, 0xc0002d1690, 0x5)
/Users/steve/Code/gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/providers/gcp/utils.go:48 +0x10a
gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/providers/gcp.(*Provider).Create(0xc00034c000, 0x19d3e60, 0xc0000c8580, 0x19cc7e0, 0xc0000b6870, 0xc00035e000, 0x0, 0x0)
/Users/steve/Code/gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/providers/gcp/provider.go:111 +0x40d
main.createVM(0x19d3e60, 0xc0000c8580, 0x19e2500, 0xc0002320c0, 0x19d2760, 0xc00034e000, 0x19cc820, 0xc00034c000, 0x19cc7e0, 0xc0000b6870, ...)
/Users/steve/Code/gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/cmd/autoscaler/main.go:177 +0xe8
main.main()
/Users/steve/Code/gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/cmd/autoscaler/main.go:73 +0x88b
exit status 2
This is caused by https://gitlab.com/gitlab-org/ci-cd/custom-executors/autoscaler/blob/404c56e73921d606bc45d357373fdea6efb82d5c/providers/gcp/utils.go#L42-46 where there is no match and we try to get from an index that doesn't exist
Proposal
Handle the error correctly, return that we failed to parse the zone instead.
/cc @tmaczukin