Skip to content

Commit

Permalink
feat(controller): unix timestamp support on creationTimestamp var (#4763
Browse files Browse the repository at this point in the history
)

Signed-off-by: RossyWhite <daikishiroi@gmail.com>
  • Loading branch information
RossyWhite authored Dec 18, 2020
1 parent 9f67b28 commit 442d367
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ func (woc *wfOperationCtx) setGlobalParameters(executionParameters wfv1.Argument
cTimeVar := fmt.Sprintf("%s.%s", common.GlobalVarWorkflowCreationTimestamp, string(char))
woc.globalParams[cTimeVar] = strftime.Format("%"+string(char), woc.wf.ObjectMeta.CreationTimestamp.Time)
}
woc.globalParams[common.GlobalVarWorkflowCreationTimestamp+".s"] = strconv.FormatInt(woc.wf.ObjectMeta.CreationTimestamp.Time.Unix(), 10)

if workflowParameters, err := json.Marshal(woc.execWf.Spec.Arguments.Parameters); err == nil {
woc.globalParams[common.GlobalVarWorkflowParameters] = string(workflowParameters)
Expand Down
7 changes: 7 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/argoproj/pkg/strftime"

"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -240,6 +242,11 @@ func TestGlobalParams(t *testing.T) {
if assert.Contains(t, woc.globalParams, "workflow.creationTimestamp") {
assert.NotContains(t, woc.globalParams["workflow.creationTimestamp"], "UTC")
}
for char := range strftime.FormatChars {
assert.Contains(t, woc.globalParams, fmt.Sprintf("%s.%s", "workflow.creationTimestamp", string(char)))
}
assert.Contains(t, woc.globalParams, "workflow.creationTimestamp.s")

assert.Contains(t, woc.globalParams, "workflow.duration")
assert.Contains(t, woc.globalParams, "workflow.name")
assert.Contains(t, woc.globalParams, "workflow.namespace")
Expand Down

0 comments on commit 442d367

Please sign in to comment.