Skip to content

Commit

Permalink
feat(controller): Make MAX_OPERATION_TIME configurable. Close #4239 (#…
Browse files Browse the repository at this point in the history
…4562)

Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Nov 21, 2020
1 parent 66f2306 commit e8ba1ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 21 additions & 0 deletions util/env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package env

import (
"os"
"time"

log "github.com/sirupsen/logrus"
)

func LookupEnvDurationOr(key string, o time.Duration) time.Duration {
v, found := os.LookupEnv(key)
if found {
d, err := time.ParseDuration(v)
if err != nil {
log.WithField(key, v).WithError(err).Panic("failed to parse")
} else {
return d
}
}
return o
}
18 changes: 18 additions & 0 deletions util/env/env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package env

import (
"os"
"testing"
"time"

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

func TestLookupEnvDurationOr(t *testing.T) {
defer func() { _ = os.Unsetenv("FOO") }()
assert.Equal(t, time.Second, LookupEnvDurationOr("", time.Second), "default value")
_ = os.Setenv("FOO", "bar")
assert.Panics(t, func() { LookupEnvDurationOr("FOO", time.Second) }, "bad value")
_ = os.Setenv("FOO", "1h")
assert.Equal(t, time.Hour, LookupEnvDurationOr("FOO", time.Second), "env var value")
}
6 changes: 5 additions & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
"github.com/argoproj/argo/util"
envutil "github.com/argoproj/argo/util/env"
errorsutil "github.com/argoproj/argo/util/errors"
"github.com/argoproj/argo/util/intstr"
"github.com/argoproj/argo/util/resource"
Expand Down Expand Up @@ -108,7 +109,10 @@ var (

// maxOperationTime is the maximum time a workflow operation is allowed to run
// for before requeuing the workflow onto the workqueue.
const maxOperationTime = 10 * time.Second
var (
maxOperationTime = envutil.LookupEnvDurationOr("MAX_OPERATION_TIME", 30*time.Second)
defaultRequeueTime = envutil.LookupEnvDurationOr("DEFAULT_REQUEUE_TIME", maxOperationTime/2)
)

// failedNodeStatus is a subset of NodeStatus that is only used to Marshal certain fields into a JSON of failed nodes
type failedNodeStatus struct {
Expand Down

0 comments on commit e8ba1ed

Please sign in to comment.