From 2c63507a0bba852912fb4b26388dc444ea85d7da 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 --- jobspec/parse_task.go | 12 ++++++++++-- jobspec/parse_test.go | 4 ++++ jobspec/test-fixtures/csi-plugin.hcl | 7 ++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/jobspec/parse_task.go b/jobspec/parse_task.go index ff81b6ba66a8..4bc77c310f27 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/parse_test.go b/jobspec/parse_test.go index 45d624aa22f1..815923aa3504 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -1,6 +1,7 @@ package jobspec import ( + "fmt" "path/filepath" "strings" "testing" @@ -1831,6 +1832,9 @@ func TestParse(t *testing.T) { if tc.Err { require.Error(t, err) } else { + if actual != nil && actual.TaskGroups != nil && len(actual.TaskGroups) > 0 && actual.TaskGroups[0].Tasks != nil && len(actual.TaskGroups[0].Tasks) > 0 && actual.TaskGroups[0].Tasks[0].CSIPluginConfig != nil { + fmt.Println("***actual", actual.TaskGroups[0].Tasks[0].CSIPluginConfig.HealthTimeout) + } require.NoError(t, err) require.Equal(t, tc.Result, actual) } diff --git a/jobspec/test-fixtures/csi-plugin.hcl b/jobspec/test-fixtures/csi-plugin.hcl index b879da184347..3e4106719d5e 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" } } }