Skip to content

Commit

Permalink
Merge pull request #2229 from simonbaird/support-no-timeout
Browse files Browse the repository at this point in the history
Support running with no timeout, ignore/deprecate TIMEOUT task param
  • Loading branch information
simonbaird authored Jan 7, 2025
2 parents 3996d38 + 73f183e commit 1f2699f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
13 changes: 10 additions & 3 deletions cmd/root/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ func NewRootCmd() *cobra.Command {
// set a custom message for context.DeadlineExceeded error
context.DeadlineExceeded = customDeadlineExceededError{}

// Create a new context now that flags have been parsed so a custom timeout can be used.
ctx, cancel := context.WithTimeout(cmd.Context(), globalTimeout)
// Create a new context now that flags have been parsed so a
// custom timeout can be used and traces can be added
ctx := cmd.Context()
var cancel context.CancelFunc
if globalTimeout > 0 {
ctx, cancel = context.WithTimeout(ctx, globalTimeout)
log.Debugf("globalTimeout is %s", time.Duration(globalTimeout))
} else {
log.Debugf("globalTimeout is %d, no timeout used", globalTimeout)
}
ctx = tracing.WithTrace(ctx, enabledTraces)
cmd.SetContext(ctx)
log.Debugf("globalTimeout is %d", globalTimeout)

var cpuprofile *os.File
var tracefile *os.File
Expand Down
5 changes: 2 additions & 3 deletions docs/modules/ROOT/pages/verify-enterprise-contract.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ paths can be provided by using the `:` separator.
+
*Default*: `now`
*EXTRA_RULE_DATA* (`string`):: Merge additional Rego variables into the policy data. Use syntax "key=value,key2=value2..."
*TIMEOUT* (`string`):: Timeout setting for `ec validate`.
+
*Default*: `5m0s`
*TIMEOUT* (`string`):: This param is deprecated and will be removed in future. Its value is ignored. EC will be run without a timeout. (If you do want to apply a timeout use the Tekton task timeout.)

*WORKERS* (`string`):: Number of parallel workers to use for policy evaluation.
+
*Default*: `1`
Expand Down
6 changes: 4 additions & 2 deletions features/task_validate_image.feature
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ Feature: Verify Enterprise Contract Tekton Tasks
Then the task should succeed
And the task logs for step "debug-log" should contain "Using provided effective time 2020-01-01T00:00:00Z"

Scenario: Timeout is honored
# Previously we did allow a custom timeout to be set via the TIMEOUT param, but now it's ignored.
# (This test could be removed in the future, but let's keep it for now I guess.)
Scenario: Deprecated timeout param is ignored
Given a working namespace
And a key pair named "known"
And an image named "acceptance/timeout"
Expand All @@ -314,7 +316,7 @@ Feature: Verify Enterprise Contract Tekton Tasks
| IGNORE_REKOR | true |
| TIMEOUT | 666s |
Then the task should succeed
And the task logs for step "debug-log" should contain "globalTimeout is 666000000000"
And the task logs for step "debug-log" should contain "globalTimeout is 100h0m0s"

Scenario: SSL_CERT_DIR environment variable is customized
Given a working namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ spec:

- name: TIMEOUT
type: string
description: Timeout setting for `ec validate`.
default: "5m0s"
description: >
This param is deprecated and will be removed in future. Its value is ignored. EC will
be run without a timeout. (If you do want to apply a timeout use the Tekton task timeout.)
default: ""

Check failure on line 134 in tasks/verify-enterprise-contract/0.1/verify-enterprise-contract.yaml

View workflow job for this annotation

GitHub Actions / Lint

Task 'verify-enterprise-contract' defines parameter 'TIMEOUT', but it's not used anywhere in the spec
- name: WORKERS
type: string
Expand Down Expand Up @@ -224,7 +226,11 @@ spec:
- "$(params.WORKERS)"
# NOTE: The syntax below is required to negate boolean parameters
- "--info=$(params.INFO)"
- "--timeout=$(params.TIMEOUT)"
# Fresh versions of ec support "--timeout=0" to indicate no timeout, but this would break
# the task if it's used with an older version of ec. In an abundance of caution, let's set
# an arbitrary high value instead of using 0 here. In future we can change it to 0.
# (The reason to not use an explicit timeout for ec is so Tekton can handle the timeouts).
- "--timeout=100h"
- "--strict=false"
- "--show-successes"
- "--effective-time=$(params.EFFECTIVE_TIME)"
Expand Down

0 comments on commit 1f2699f

Please sign in to comment.