Skip to content

feat(k8s): Add lifecycle feat in task schedule#420

Open
Spground wants to merge 1 commit intoalibaba:mainfrom
Spground:feature/public-k8s-task-lifecycle
Open

feat(k8s): Add lifecycle feat in task schedule#420
Spground wants to merge 1 commit intoalibaba:mainfrom
Spground:feature/public-k8s-task-lifecycle

Conversation

@Spground
Copy link
Collaborator

@Spground Spground commented Mar 11, 2026

Summary

  • What is changing and why?

Add task lifecycle in k8s runtime, commen use cases: use preStart to prepare some resources e.g dir, data and etc, and clean up those resources via postStop after task terminated.

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@Spground Spground added feature New feature or request component/k8s For kubernetes runtime labels Mar 11, 2026
@Spground Spground force-pushed the feature/public-k8s-task-lifecycle branch from e2414f9 to 3835fbf Compare March 11, 2026 07:45
@jwx0925
Copy link
Collaborator

jwx0925 commented Mar 12, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3835fbfdc7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +327 to +329
if task.Process != nil && task.Process.Lifecycle != nil && task.Process.Lifecycle.PostStop != nil {
klog.InfoS("Executing postStop lifecycle hook", "task", task.Name)
if err := e.execLifecycleHook(ctx, task, task.Process.Lifecycle.PostStop); err != nil {

Choose a reason for hiding this comment

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

P2 Badge Trigger postStop for tasks that already reached terminal state

postStop is only executed inside Executor.Stop, but the reconcile loop finalizes deletion of terminal tasks without calling Stop (see reconcileTasks), so any task that exits naturally (or is deleted after it already succeeded/failed) skips the hook entirely. This breaks the advertised lifecycle contract (PostStop is executed after the main process stops) and will miss cleanup for common short-lived tasks that finish before deletion.

Useful? React with 👍 / 👎.

env:
- name: TASK_NAME
value: lifecycle-task
lifecycle:

Choose a reason for hiding this comment

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

P3 Badge Place lifecycle sample under process spec

In this sample manifest, lifecycle is defined at taskTemplate.spec.lifecycle instead of taskTemplate.spec.process.lifecycle, so the hooks are ignored by the controller conversion path that only reads process.lifecycle. Users applying this example won’t actually run preStart/postStop, which makes the feature appear broken and gives incorrect guidance.

Useful? React with 👍 / 👎.

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

Labels

component/k8s For kubernetes runtime feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants