Skip to content

Add support for Kubernetes 1.34 LifecycleHandler.sleep field#2057

Merged
naomi-robusta merged 2 commits intomasterfrom
claude/update-prestop-sleep-LQ6Rf
Apr 30, 2026
Merged

Add support for Kubernetes 1.34 LifecycleHandler.sleep field#2057
naomi-robusta merged 2 commits intomasterfrom
claude/update-prestop-sleep-LQ6Rf

Conversation

@naomi-robusta
Copy link
Copy Markdown
Contributor

Summary

This PR adds support for the sleep field in Kubernetes 1.34's LifecycleHandler, which is not present in Hikaru's bundled v1.26 model. The patch ensures that preStop/postStart sleep handlers are correctly parsed and diffed.

Key Changes

  • New SleepAction dataclass: Created a dataclass to represent the sleep action with a seconds field, matching the Kubernetes 1.34 API specification
  • New patch_lifecycle_handler_sleep() function: Dynamically patches the LifecycleHandler class to add the missing sleep field by:
    • Adding the field to the class annotations
    • Creating and registering a proper dataclass field with correct metadata
    • Clearing cached arguments and type hints to ensure proper serialization
    • Registering SleepAction in the v1 package namespace
  • Integration: The patch is automatically applied during monkey patch initialization

Implementation Details

  • The patch uses dataclass field manipulation to inject the sleep field into the existing LifecycleHandler class
  • Field metadata (_field_type, name, type) is properly configured to integrate seamlessly with Hikaru's dataclass infrastructure
  • The implementation includes a guard check to prevent re-patching if the field already exists
  • Cached class attributes are cleared to ensure Hikaru's serialization logic picks up the new field

https://claude.ai/code/session_013fifvjn134B8JQUK1EE9tG

Hikaru's bundled v1 model (rel_1_26) predates the lifecycle.preStop.sleep
field that became GA in Kubernetes 1.34. Without a matching field on
LifecycleHandler, hikaru silently drops the value when parsing, so a
migration from preStop.exec to preStop.sleep was reported as the exec
field changing to None with no corresponding new value.

Patch LifecycleHandler in place to add an Optional[SleepAction] field so
the new value is parsed, round-tripped, and surfaced in change diffs.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f8220b0-5786-49d6-ba50-c7567512d5e1

📥 Commits

Reviewing files that changed from the base of the PR and between a487815 and cac26bf.

📒 Files selected for processing (1)
  • src/robusta/patch/patch.py

Walkthrough

Adds a new SleepAction Hikaru dataclass and a monkey-patch that augments hikaru.model.rel_1_26.v1.LifecycleHandler with an optional sleep field, registers SleepAction into the v1 model namespaces, initializes the injected field, resets cached dataclass constructor/hint state, and invokes the patch during initialization.

Changes

Cohort / File(s) Summary
Lifecycle Handler Sleep Support
src/robusta/patch/patch.py
Added SleepAction dataclass (seconds: int = 0), implemented patch_lifecycle_handler_sleep() to register SleepAction into v1_pkg/v1_pkg.v1, inject an optional sleep field into LifecycleHandler, initialize the field, clear cached constructor/hint state, and updated create_monkey_patches() to call the new patch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for Kubernetes 1.34 LifecycleHandler.sleep field, which is the primary objective of the PR.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the new SleepAction dataclass, the patch function, and how the sleep field is integrated into LifecycleHandler.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/update-prestop-sleep-LQ6Rf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

Docker image ready for 82eed64 (built in 1m 31s)

⚠️ Warning: does not support ARM (ARM images are built on release only - not on every PR)

Use this tag to pull the image for testing.

📋 Copy commands

⚠️ Temporary images are deleted after 30 days. Copy to a permanent registry before using them:

gcloud auth configure-docker us-central1-docker.pkg.dev
docker pull us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:82eed64
docker tag us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:82eed64 me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:82eed64
docker push me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:82eed64

Patch Helm values in one line:

helm upgrade --install robusta robusta/robusta \
  --reuse-values \
  --set runner.image=me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:82eed64

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/robusta/patch/patch.py`:
- Line 2: The import currently pulls the private symbol `_FIELD`; remove
`_FIELD` from the import and instead create any needed template Field by calling
the public factory `field()` (from the existing import) and modifying its
attributes as required; update any code that referenced `_FIELD` to use that
`field()`-derived template (e.g., replace usages of `_FIELD` with a `template =
field()` or `template = field(default=...)` and then adjust
template.metadata/default_factory/etc.), keeping the rest of the dataclasses
usage (InitVar, dataclass, is_dataclass) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7841576f-3c4c-41a5-9120-86cd121d967a

📥 Commits

Reviewing files that changed from the base of the PR and between 3be09d7 and a487815.

📒 Files selected for processing (1)
  • src/robusta/patch/patch.py

Comment thread src/robusta/patch/patch.py Outdated
dataclasses.fields() filters by `f._field_type is _FIELD`, so the patched
field needs the same sentinel. Borrow it from an existing field on the
class instead of importing the private symbol from the stdlib.
@naomi-robusta naomi-robusta merged commit b147fb8 into master Apr 30, 2026
5 checks passed
@naomi-robusta naomi-robusta deleted the claude/update-prestop-sleep-LQ6Rf branch April 30, 2026 07:05
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