From a496915fb859bd7f4fad65447705496fb263f37f Mon Sep 17 00:00:00 2001 From: Grant Griffiths Date: Fri, 10 Jun 2022 21:36:53 +0000 Subject: [PATCH] fix parse_task.go and associated test Signed-off-by: Grant Griffiths --- api/tasks.go | 4 ++++ jobspec/parse_task.go | 12 ++++++++++-- jobspec/test-fixtures/csi-plugin.hcl | 7 ++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api/tasks.go b/api/tasks.go index 8433f222c29..6cdb44da3a3 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -1049,4 +1049,8 @@ func (t *TaskCSIPluginConfig) Canonicalize() { if t.MountDir == "" { t.MountDir = "/csi" } + + if t.HealthTimeout == 0 { + t.HealthTimeout = 30 * time.Second + } } diff --git a/jobspec/parse_task.go b/jobspec/parse_task.go index ff81b6ba66a..4bc77c310f2 100644 --- a/jobspec/parse_task.go +++ b/jobspec/parse_task.go @@ -158,12 +158,20 @@ func parseTask(item *ast.ObjectItem, keys []string) (*api.Task, error) { i := o.Elem().Items[0] var m map[string]interface{} + var cfg api.TaskCSIPluginConfig if err := hcl.DecodeObject(&m, i.Val); err != nil { return nil, err } - var cfg api.TaskCSIPluginConfig - if err := mapstructure.WeakDecode(m, &cfg); err != nil { + dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ + DecodeHook: mapstructure.StringToTimeDurationHookFunc(), + WeaklyTypedInput: true, + Result: &cfg, + }) + if err != nil { + return nil, err + } + if err := dec.Decode(m); err != nil { return nil, err } diff --git a/jobspec/test-fixtures/csi-plugin.hcl b/jobspec/test-fixtures/csi-plugin.hcl index b879da18434..3e4106719d5 100644 --- a/jobspec/test-fixtures/csi-plugin.hcl +++ b/jobspec/test-fixtures/csi-plugin.hcl @@ -4,9 +4,10 @@ job "binstore-storagelocker" { driver = "docker" csi_plugin { - id = "org.hashicorp.csi" - type = "monolith" - mount_dir = "/csi/test" + id = "org.hashicorp.csi" + type = "monolith" + mount_dir = "/csi/test" + health_timeout = "1m" } } }