Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .features/fix-http-timeoutseconds-templating.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
issue: 15024
component: workflow
kind: bugfix

tldr: Add support for templated string values for http.timeoutSeconds.

previousBehavior: |
The `timeoutSeconds` field only accepted numeric JSON values.
When templated parameters resolved to strings (e.g. `"1800"` instead of `1800`),
unmarshalling failed with:
`json: cannot unmarshal string into Go struct field HTTP.timeoutSeconds of type int64`.

newBehavior: |
The `HTTP` type now accepts both numeric and string representations for `timeoutSeconds`.
A custom JSON unmarshaller converts string integer values into `int64`,
making templated parameters fully supported while keeping the public API unchanged.

backwardsCompatible: true
3 changes: 2 additions & 1 deletion pkg/apis/workflow/v1alpha1/http_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

type HTTPHeaderSource struct {
Expand Down Expand Up @@ -43,7 +44,7 @@ type HTTP struct {
// Headers are an optional list of headers to send with HTTP requests
Headers HTTPHeaders `json:"headers,omitempty" protobuf:"bytes,3,rep,name=headers"`
// TimeoutSeconds is request timeout for HTTP Request. Default is 30 seconds
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty" protobuf:"bytes,4,opt,name=timeoutSeconds"`
TimeoutSeconds *intstr.IntOrString `json:"timeoutSeconds,omitempty" protobuf:"bytes,4,opt,name=timeoutSeconds"`
// SuccessCondition is an expression if evaluated to true is considered successful
SuccessCondition string `json:"successCondition,omitempty" protobuf:"bytes,6,opt,name=successCondition"`
// Body is content of the HTTP Request
Expand Down
41 changes: 41 additions & 0 deletions pkg/apis/workflow/v1alpha1/http_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v1alpha1

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestHTTPUnmarshalJSON_TimeoutSeconds_Number(t *testing.T) {
jsonData := []byte(`{"timeoutSeconds": 10}`)

var httpTemplate HTTP
err := json.Unmarshal(jsonData, &httpTemplate)
require.NoError(t, err)

if assert.NotNil(t, httpTemplate.TimeoutSeconds) {
assert.Equal(t, int64(10), *httpTemplate.TimeoutSeconds)
}
}

func TestHTTPUnmarshalJSON_TimeoutSeconds_StringNumeric(t *testing.T) {
jsonData := []byte(`{"timeoutSeconds": "15"}`)

var httpTemplate HTTP
err := json.Unmarshal(jsonData, &httpTemplate)
require.NoError(t, err)

if assert.NotNil(t, httpTemplate.TimeoutSeconds) {
assert.Equal(t, int64(15), *httpTemplate.TimeoutSeconds)
}
}

func TestHTTPUnmarshalJSON_TimeoutSeconds_InvalidString(t *testing.T) {
jsonData := []byte(`{"timeoutSeconds": "not-a-number"}`)

var httpTemplate HTTP
err := json.Unmarshal(jsonData, &httpTemplate)
require.Error(t, err)
}
Loading