Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running with no timeout, ignore/deprecate TIMEOUT task param #2229

Merged
merged 4 commits into from
Jan 7, 2025
Merged
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
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 @@
// 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)
}

Check warning on line 85 in cmd/root/root_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/root/root_cmd.go#L84-L85

Added lines #L84 - L85 were not covered by tests
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 @@ -125,11 +125,13 @@
description: Merge additional Rego variables into the policy data. Use syntax "key=value,key2=value2..."
default: ""

- 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
description: Number of parallel workers to use for policy evaluation.
Expand Down Expand Up @@ -224,7 +226,11 @@
- "$(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
Loading