Skip to content

Extend PodLifeTime with condition, exit code, owner kind, and transition time filters#1844

Merged
k8s-ci-robot merged 2 commits into
kubernetes-sigs:masterfrom
a7i:extend-podlifetime-transitions
Mar 6, 2026
Merged

Extend PodLifeTime with condition, exit code, owner kind, and transition time filters#1844
k8s-ci-robot merged 2 commits into
kubernetes-sigs:masterfrom
a7i:extend-podlifetime-transitions

Conversation

@a7i
Copy link
Copy Markdown
Contributor

@a7i a7i commented Mar 1, 2026

Description

Extend PodLifeTime with new filtering fields

Adds new fields to PodLifeTimeArgs so it can handle fine-grained, transition-based eviction:

  • conditions: Filter pods by status.conditions entries (type, status, reason) with an optional minTimeSinceLastTransitionSeconds per condition filter
  • exitCodes: Filter by container terminated exit codes
  • ownerKinds: Include or exclude pods by owner reference kind (include/exclude)
  • states enhanced: Now also checks container terminated reasons (previously only checked waiting reasons)

All non-empty filter categories are ANDed together (a pod must satisfy every specified filter). Within each category, entries are ORed. Pods are processed from oldest to newest based on their creation time. Condition filters, including minTimeSinceLastTransitionSeconds, determine which pods are eligible for eviction but do not affect this ordering.

Extract shared container state matching helpers into podutil

Moves the container waiting/terminated state checking logic from PodLifeTime and RemovePodsHavingTooManyRestarts into podutil as separate exported helpers: HasMatchingContainerWaitingState and HasMatchingContainerTerminatedState. Each plugin composes only the helpers it needs — TooManyRestarts uses only the waiting helper, while PodLifeTime uses both.

Checklist

  • Code Readability
  • Naming Conventions
  • Code Duplication
  • Function/Method Size
  • Comments & Documentation
  • Error Handling
  • Testing
  • Performance
  • Dependencies
  • Logging & Monitoring
  • Backward Compatibility
  • Resource Management
  • PR Description
  • Documentation & Changelog

Copilot AI review requested due to automatic review settings March 1, 2026 22:44
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 1, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the PodLifeTime descheduler plugin to support transition-based eviction via new filter fields (conditions, exit codes, owner kinds) and then refactors RemoveFailedPods to delegate its eviction behavior to PodLifeTime (via the new NewAs constructor) to reduce duplicated logic.

Changes:

  • Extend PodLifeTimeArgs with conditions, exitCodes, and ownerKinds, plus enhanced states matching (now includes terminated reasons).
  • Add delegation support (NewAs) so other plugins (notably RemoveFailedPods) can reuse PodLifeTime logic with additional injected filters.
  • Add/extend unit tests, e2e tests, and documentation/examples to cover transition-based eviction scenarios.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/e2e/e2e_podlifetime_test.go Adds e2e coverage for PodLifeTime eviction behavior on failed/succeeded pods with new filters.
pkg/framework/plugins/removefailedpods/failedpods.go Refactors RemoveFailedPods to delegate to PodLifeTime via NewAs and maps args.
pkg/framework/plugins/podlifetime/pod_lifetime.go Implements new filters, delegation constructor, and new eviction ordering logic.
pkg/framework/plugins/podlifetime/types.go Adds new config types/fields: OwnerKinds, PodConditionFilter, ExitCodes.
pkg/framework/plugins/podlifetime/validation.go Updates validation rules to account for new filter criteria and ownerKinds.
pkg/framework/plugins/podlifetime/validation_test.go Updates validation test expectations for new validation semantics.
pkg/framework/plugins/podlifetime/pod_lifetime_test.go Adds unit tests for new filtering and ordering behavior.
pkg/framework/plugins/podlifetime/zz_generated.deepcopy.go Updates generated deep-copies for new args/types.
pkg/framework/plugins/podlifetime/README.md Documents the new filters, AND/OR semantics, ordering, and migration notes.
examples/pod-life-time-transition.yml Adds example policy for transition-based eviction.
README.md Updates top-level plugin documentation and examples for PodLifeTime.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go Outdated
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go Outdated
Comment thread pkg/framework/plugins/podlifetime/validation.go
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime_test.go
Comment thread pkg/framework/plugins/removefailedpods/failedpods.go
Comment thread pkg/framework/plugins/removefailedpods/failedpods.go Outdated
Comment thread test/e2e/e2e_podlifetime_test.go Outdated
Comment thread test/e2e/e2e_podlifetime_test.go Outdated
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 2a26912 to e7a230d Compare March 2, 2026 00:28
@a7i
Copy link
Copy Markdown
Contributor Author

a7i commented Mar 2, 2026

/retest-required

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime_test.go Outdated
Comment thread test/e2e/e2e_podlifetime_test.go Outdated
@a7i
Copy link
Copy Markdown
Contributor Author

a7i commented Mar 2, 2026

/retest-required

@a7i a7i force-pushed the extend-podlifetime-transitions branch from e7a230d to dff7cb8 Compare March 3, 2026 01:22
Copilot AI review requested due to automatic review settings March 5, 2026 01:24
@a7i a7i force-pushed the extend-podlifetime-transitions branch from dff7cb8 to d613ffd Compare March 5, 2026 01:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go
Comment thread pkg/framework/plugins/podlifetime/README.md Outdated
Comment thread README.md Outdated
Comment thread pkg/framework/plugins/removefailedpods/failedpods.go Outdated
@a7i a7i force-pushed the extend-podlifetime-transitions branch from d613ffd to 77d06d2 Compare March 5, 2026 01:32
Copilot AI review requested due to automatic review settings March 5, 2026 01:42
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 77d06d2 to 9f3c55a Compare March 5, 2026 01:42
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 9f3c55a to c4f0ac0 Compare March 5, 2026 01:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread README.md
Comment thread examples/pod-life-time-transition.yml
@a7i
Copy link
Copy Markdown
Contributor Author

a7i commented Mar 5, 2026

/cc @jklaw90 @ingvagabund

🙏🏼

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@a7i a7i requested a review from ingvagabund March 6, 2026 13:40
if podLifeTimeArgs.MaxPodLifeTimeSeconds != nil {
podFilter = podutil.WrapFilterFuncs(podFilter, func(pod *v1.Pod) bool {
podAge := metav1.Now().Sub(pod.GetCreationTimestamp().Local())
if podAge < 0 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is odd, but copilot requested a change for code that I did not touch

@a7i a7i changed the title Extend PodLifeTime with transition-based eviction and delegate RemoveFailedPods Extend PodLifeTime with condition, exit code, owner kind, and transition time filters Mar 6, 2026
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go Outdated
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 7ef5b0d to 93fc0c5 Compare March 6, 2026 14:36
Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go Outdated
if filter.Reason != "" && cond.Reason != filter.Reason {
return false
}
return true
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.

The case where all fields are unset is validated. So in case someone invokes this without the validation a condition with all fields unset matches every pod? Maybe revert the logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Technically only one need to be set so this condition check is still needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

validation:

args.MaxPodLifeTimeSeconds != nil ||
		len(args.States) > 0 ||
		len(args.Conditions) > 0 ||
		len(args.ExitCodes) > 0

p.Status.Phase = v1.PodFailed
}),
},
expectedEvictedPodCount: 1,
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 should not evict a pod if a job is excluded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isn't p2 a non-Job pod? hence why it's expecting p2 pod to be evicted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a separate test to focus on a Job not getting evicted, but this test-case is valid and the assertion is correct

Comment thread README.md
Copilot AI review requested due to automatic review settings March 6, 2026 16:31
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 93fc0c5 to 7114d0e Compare March 6, 2026 16:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/framework/plugins/podlifetime/pod_lifetime.go Outdated
a7i added 2 commits March 6, 2026 12:17
Move container waiting/terminated state checking from PodLifeTime and
RemovePodsHavingTooManyRestarts into podutil as separate exported helpers:
HasMatchingContainerWaitingState and HasMatchingContainerTerminatedState.
Each plugin composes only the helpers it needs.
@a7i a7i force-pushed the extend-podlifetime-transitions branch from 7114d0e to a4391ea Compare March 6, 2026 17:18
@ingvagabund
Copy link
Copy Markdown
Contributor

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 6, 2026
@ingvagabund
Copy link
Copy Markdown
Contributor

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ingvagabund

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 6, 2026
@k8s-ci-robot k8s-ci-robot merged commit 0fafc09 into kubernetes-sigs:master Mar 6, 2026
9 checks passed
@a7i a7i deleted the extend-podlifetime-transitions branch March 6, 2026 19:37
k8s-ci-robot added a commit that referenced this pull request Mar 8, 2026
…#1838-#1842-#1847-#1848-#1844-upstream-release-1.35

Automated cherry pick of #1836: Synchronize helm clusterrole RBAC with base yaml
#1826: Add init containers support to Helm chart
#1838: Change icon URL in Chart.yaml
#1842: fix: resolve detected data races
#1847: fix(ci): upgrade codeql-action to v4 and clean up security
#1848: update go dependencies
#1844: Extend PodLifeTime with condition, exit code, owner kind,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants