From 1ec785c7e939b108186d321c547093e007ac84a7 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:37:38 +0200 Subject: [PATCH] Weakly decode backend options (#4577) --- pipeline/backend/docker/backend_options.go | 2 +- pipeline/backend/kubernetes/backend_options.go | 2 +- .../backend/kubernetes/backend_options_test.go | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pipeline/backend/docker/backend_options.go b/pipeline/backend/docker/backend_options.go index 14aece0f3..d368309ab 100644 --- a/pipeline/backend/docker/backend_options.go +++ b/pipeline/backend/docker/backend_options.go @@ -16,6 +16,6 @@ func parseBackendOptions(step *backend.Step) (BackendOptions, error) { if step == nil || step.BackendOptions == nil { return result, nil } - err := mapstructure.Decode(step.BackendOptions[EngineName], &result) + err := mapstructure.WeakDecode(step.BackendOptions[EngineName], &result) return result, err } diff --git a/pipeline/backend/kubernetes/backend_options.go b/pipeline/backend/kubernetes/backend_options.go index ee2310be8..c43d23b32 100644 --- a/pipeline/backend/kubernetes/backend_options.go +++ b/pipeline/backend/kubernetes/backend_options.go @@ -89,6 +89,6 @@ func parseBackendOptions(step *backend.Step) (BackendOptions, error) { if step == nil || step.BackendOptions == nil { return result, nil } - err := mapstructure.Decode(step.BackendOptions[EngineName], &result) + err := mapstructure.WeakDecode(step.BackendOptions[EngineName], &result) return result, err } diff --git a/pipeline/backend/kubernetes/backend_options_test.go b/pipeline/backend/kubernetes/backend_options_test.go index f1a42aa19..cbf043faf 100644 --- a/pipeline/backend/kubernetes/backend_options_test.go +++ b/pipeline/backend/kubernetes/backend_options_test.go @@ -114,6 +114,23 @@ func Test_parseBackendOptions(t *testing.T) { }, }, }, + { + name: "number options", + step: &backend.Step{BackendOptions: map[string]any{ + "kubernetes": map[string]any{ + "resources": map[string]any{ + "requests": map[string]int{"memory": 128, "cpu": 1000}, + "limits": map[string]int{"memory": 256, "cpu": 2}, + }, + }, + }}, + want: BackendOptions{ + Resources: Resources{ + Requests: map[string]string{"memory": "128", "cpu": "1000"}, + Limits: map[string]string{"memory": "256", "cpu": "2"}, + }, + }, + }, } for _, tt := range tests {