Skip to content

Support per-step timeout field in Kptfile pipeline - #4814

Open
SurbhiAgarwal1 wants to merge 6 commits into
kptdev:mainfrom
SurbhiAgarwal1:feat/4473-kptfile-step-timeout
Open

SurbhiAgarwal1 wants to merge 6 commits into
kptdev:mainfrom
SurbhiAgarwal1:feat/4473-kptfile-step-timeout

Conversation

@SurbhiAgarwal1

@SurbhiAgarwal1 SurbhiAgarwal1 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Description
This PR adds support for a per-function timeout field on pipeline mutator and validator steps in the Kptfile as requested in issue #4473.

  • Add Timeout field to Function type in api/kptfile/v1/types.go and applyconfigurations
  • Add validation in api/kptfile/v1/validation.go ensuring positive, valid duration syntax (e.g. 30s, 1m, 5m)
  • Propagate function step timeout to ContainerFn and ExecFn runtimes in pkg/fn/runtime/runner.go
  • Integrate precedence: pipeline-level --timeout flag overrides step-level timeout, and step-level timeout overrides the 5-minute default
  • Update Kptfile schema definitions (kptfile.yaml and kptfile.json)
  • Built on top of #4798 (feat/4473-timeout-flag)

Motivation
Currently, both ContainerFn and ExecFn can accept a timeout, but there was no mechanism to configure a timeout per individual function step in the Kptfile pipeline. Adding this allows fast functions to fail quickly and heavy functions to have dedicated time limits in GitOps and CI workflows without relying solely on global CLI flags.

Testing

  • Validation tests in api/kptfile/v1/validation_test.go for valid durations, invalid syntax, zero, and negative values
  • Runtime step timeout execution tests in pkg/fn/runtime/runner_test.go
  • Precedence tests in pkg/fn/runtime/runner_test.go verifying CLI pipeline timeout precedence and step timeout precedence
  • Render executor tests in pkg/lib/kptops/render_executor_test.go
  • All unit tests passing with zero compilation errors

Part of #4473

The container and exec function runtimes accept a timeout, but nothing set it, so every function ran with the default of 5 minutes. Add a --timeout flag to both commands and pass it to the runtimes. A function that times out is now reported with its stderr and a 'Timed out after' line, and kpt no longer waits past the timeout for a child process that keeps the output open.

Part of kptdev#4473

Assisted-by: Claude:claude-opus-5-5

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Nikshay <nikshayyadav90@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Nikshay <nikshayyadav90@gmail.com>
Signed-off-by: Nikshay <nikshayyadav90@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Nikshay <nikshayyadav90@gmail.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Nikshay <nikshayyadav90@gmail.com>
@SurbhiAgarwal1
SurbhiAgarwal1 requested review from a team and a balanced review from Copilot October 17, 2026 16:37
@netlify

netlify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 0d88a10
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6ad63992b08ba52907ed8d42
😎 Deploy Preview https://deploy-preview-4814--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Nikshay1 Nikshay1 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulled this locally and the new tests pass for me. left a few small notes inline. the empty ci: re-trigger live-apply workflow commit could probably go before merge too. thanks for taking the Kptfile part!

opts := runneroptions.RunnerOptions{}
opts.InitDefaults(runneroptions.GHCRImagePrefix)
opts.AllowExec = true
opts.Timeout = 10 * time.Second

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test shows the shorter limit wins, a 100ms step still times out under a 10s flag. the PR description says the flag overrides the step timeout though. I like shorter-wins better, so maybe only the description needs a small change?

Comment on lines +88 to +89
When this flag is not set, there is no limit for the whole pipeline, and each
function is allowed to run for 5 minutes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line came from #4798 and isn't right anymore once a step sets its own timeout. maybe something like

Suggested change
When this flag is not set, there is no limit for the whole pipeline, and each
function is allowed to run for 5 minutes.
When this flag is not set, there is no limit for the whole pipeline, and each
function is allowed to run for 5 minutes, or for its `timeout` from the
Kptfile if it sets one.

the same sentence is also in the flag help in cmdrender.go and in internal/docs/generated/fndocs/docs.go.

Comment thread pkg/fn/runtime/runner_test.go Outdated
require.Len(t, fnResults.Items, 1)
assert.Equal(t, timeoutExitCode, fnResults.Items[0].ExitCode)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gofmt wants this trailing blank line gone.

b.Timeout = &value
return b
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same trailing blank line here, gofmt flags this file too.

Comment thread api/kptfile/v1/types.go Outdated

// Timeout specifies the maximum execution time for this function step
// (e.g. "30s", "1m", "5m"). If omitted, the pipeline timeout or default
// function timeout (5m) is used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small thing, this doesn't apply with --allow-alpha-wasm, since runner.go only passes it to ContainerFn and ExecFn. wasm functions don't get the 5m default on main either, so it's not new. the --timeout docs already say "container and exec based functions only", maybe the same note fits here?

Add support for specifying a timeout field on individual mutator and
validator pipeline steps in the Kptfile (e.g. timeout: 30s).

- Add Timeout field to Function type in api/kptfile/v1/types.go and
  generated applyconfigurations.
- Validate that the timeout field contains a valid, positive duration.
- Parse step timeout and pass to ContainerFn and ExecFn runtimes.
- Maintain precedence: the shorter limit wins (pipeline-level --timeout flag
  limits the whole run, step-level timeout limits the individual function,
  and step-level timeout overrides the default 5-minute timeout).
- Update Kptfile schema definitions (JSON and YAML).
- Add unit tests for validation, step execution timeout, and precedence.

Part of kptdev#4473

Signed-off-by: SurbhiAgarwal <agarwalsurbhi1807@gmail.com>
@SurbhiAgarwal1
SurbhiAgarwal1 force-pushed the feat/4473-kptfile-step-timeout branch from 8b858f1 to 0d88a10 Compare October 19, 2026 15:38
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants