Skip to content

Conversation

@impact-maker
Copy link

@impact-maker impact-maker commented Oct 14, 2024

Description

This PR introduces automated, testable documentation for Kubernetes Pod Lifecycle Behaviors, with a focus on PreStop hook behaviors. It leverages a Python script to dynamically populate placeholders in Markdown files with test-backed autogenerated documentation, covering the following:

Behavior Steps: Provides a clear understanding of the flow of lifecycle behaviors.
Behavior Logs: Displays expected logs to help end users validate complex behaviors.
Behavior Pod Specifications: Includes YAML configurations relevant to the behaviors being documented.

The script ensures consistent formatting and accuracy by using placeholders. Two Markdown files—area.md and area-postinsertion.md are included to validate the content before and after running the script.

Issue

Closes: kubernetes/kubernetes#126369

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Oct 14, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign natalisucks for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 language/en Issues or PRs related to English language size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 14, 2024
@netlify
Copy link

netlify bot commented Oct 14, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit f24aee4
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/674506be6a54c4000815a2f1
😎 Deploy Preview https://deploy-preview-48342--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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


The following are essential concepts related to Pod lifecycle management:

- [Lifecycle Hooks](./lifecycle_hooks/index.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

This link needs update its not correct.

Suggested change
- [Lifecycle Hooks](./lifecycle_hooks/index.md)
- [Lifecycle Hooks](/docs/reference/pod-lifecycle/lifecycle_hooks/)

- [Lifecycle Hooks](./lifecycle_hooks/index.md)
- Lifecycle hooks like PreStop and PostStart allow you to execute commands or run HTTP requests at critical moments in a container’s lifecycle. These hooks provide flexibility during container startup or shutdown, ensuring proper initialization or graceful termination.

- [Probes](./probes/readiness-probes.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no file named "readiness-probes.md". Where is this link leading to?

- [PreStop Hook](./PreStop.md)
- This hook runs a command or sends an HTTP request right before the container is terminated, allowing you to execute graceful shutdown steps.

- [PostStart Hook](./PostStart.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no file named "PostStart.md". Where is this link leading to?


Kubernetes provides two main types of lifecycle hooks:

- [PreStop Hook](./PreStop.md)
Copy link
Contributor

Choose a reason for hiding this comment

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

This link needs update its not correct.

Suggested change
- [PreStop Hook](./PreStop.md)
- [PreStop Hook](/docs/reference/pod-lifecycle/PreStop)

@steve-hardman
Copy link
Contributor

@impact-maker I can see we already have few pages that has the related info, is the objective of pull request to add more data or increase the scope. Could you add a some description of the PR and also, looks like there is some content that is still waiting to be added, maybe make this WIP or draft PR.

List of pages of similar info

@impact-maker
Copy link
Author

@steve-hardman We are restructuring the pod lifecycle events and I am performing a demo to generate documentation from the lifecycle event test cases along with @SergeyKanzhelev @tallclair. Will add some description and make this
a draft pull request.

@impact-maker impact-maker marked this pull request as draft October 15, 2024 13:46
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 15, 2024
@sftim
Copy link
Contributor

sftim commented Oct 15, 2024

/sig node

@k8s-ci-robot k8s-ci-robot added the sig/node Categorizes an issue or PR as relevant to SIG Node. label Oct 15, 2024
@sftim
Copy link
Contributor

sftim commented Oct 15, 2024

BTW if this is documenting something for v1.32, please set the base branch to dev-1.32

@sftim
Copy link
Contributor

sftim commented Oct 19, 2024

You'll find https://kubernetes.io/docs/contribute/style/style-guide/ helpful @impact-maker - please check against that before marking this ready for review.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 29, 2024
Copy link
Member

@Arhell Arhell left a comment

Choose a reason for hiding this comment

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

/easycla

@sftim
Copy link
Contributor

sftim commented Nov 11, 2024

@impact-maker you need to sign a copyright agreement before we can formally review this - see https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/18706487/51478266/48342/#/?version=2

An approver may close this PR if we don't see that covered.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 11, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 25, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 25, 2024
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

Maybe it's better to put the testable docs inside k/k?

I don't see how this page helps end users understand Kubernetes. It might help someone test Kubernetes, but: end users assume we've done that already.


<!-- overview -->

**lifecycle hooks** provide a way to trigger specific actions at crucial stages of a container's lifecycle. These hooks are useful for handling tasks such as performing tasks before the container shuts down or initiating tasks immediately after it starts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**lifecycle hooks** provide a way to trigger specific actions at crucial stages of a container's lifecycle. These hooks are useful for handling tasks such as performing tasks before the container shuts down or initiating tasks immediately after it starts.
Pod _lifecycle hooks_ provide a way to trigger specific actions at crucial stages of a container's lifecycle.
These hooks are useful for handling tasks such as performing tasks before the container shuts down or initiating tasks immediately after it starts.


The following behaviors describes the functionality of the `PreStop` hook. Each behavior ensures that the `PreStop` hook behaves as expected under different scenarios.

---
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
---

- A specified command is executed during the graceful termination of a container.
- The command completes its execution within the defined termination grace period before the container shuts down.

<!-- prestop_basic_execution_test_starts -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how this is a test.

We could put a Pod manifest in the examples directory (for the English localization)

  • including a special annotation?
  • with a separate hard coded list of examples that are used in testing

and then we could refer to those examples using code_example

If we do that, the manifests are easier to access (just a plain YAML file) and they can still appear on the site.
We can also put comments in the manifests where helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we have examples available, another tool can download them and try them in an e2e cluster. Or maybe just the GA APIs out of our set of all examples?

Comment on lines +60 to +64
The following log output confirms the successful execution of the PreStop hook:

```
PreStop Hook Executed
```
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get what readers learn from this (if we're not helping readers learn: why are we including it in the docs?)

Copy link
Author

Choose a reason for hiding this comment

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

End users often seek clarity on edge cases of lifecycle events, such as how the PreStop behavior operates in scenarios with multiple containers. However, the available documentation on these cases is quite limited. To address this, we are creating documentation directly backed by tests. The approach involves writing test cases for Pod lifecycle behaviors using a specially annotated framework.

These annotations enable a script to automatically generate documentation for the corresponding behavior. This ensures that as developers add tests for lifecycle behaviors, the associated documentation is consistently and accurately updated. To illustrate this process, I’ve shared two markdown files: one showing placeholders before the script runs and another demonstrating how the script populates those placeholders with test-derived content.

- The command completes its execution within the defined termination grace period before the container shuts down.

<!-- prestop_basic_execution_test_starts -->
<!-- Auto-generated test details, pod specifications, steps, and logs for the PreStop Basic Behavior will be inserted here. -->
Copy link
Contributor

Choose a reason for hiding this comment

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

In the preview, I don't see anything.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Netlify automatically generates a preview for how the site will look with these commits included.

I'm looking at https://deploy-preview-48342--kubernetes-io-main-staging.netlify.app/docs/reference/lifecycle-events/hooks/prestop-postinsertion/ (“the preview”)

- shows failure affects the overall container shutdown process.

<!-- prestop_basic_failure_test_starts -->
<!-- Auto-generated test details, pod specifications, steps, and logs for PreStop Failure Handling will be inserted here. -->
Copy link
Contributor

Choose a reason for hiding this comment

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

In the preview, I don't see anything.

Copy link
Author

Choose a reason for hiding this comment

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

Yes @sftim Yes currently it might not look merge ready, but I working on the PR aggressively and getting it merge ready after a few feedbacks and corrections.

@sftim
Copy link
Contributor

sftim commented Nov 26, 2024

I looked at https://deploy-preview-48342--kubernetes-io-main-staging.netlify.app/docs/reference/lifecycle-events/hooks/prestop/ - the preview for these changes

I think if a reader saw that page, as it appears right now, they might well file a bug report.

Here's a screenshot of what they'd see:
Screenshot

@sftim
Copy link
Contributor

sftim commented Nov 26, 2024

So, is this a work-in-progress? It doesn't look like a change we could merge as is.

Copy link
Contributor

@sftim sftim Nov 26, 2024

Choose a reason for hiding this comment

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

This documentation, if we add it, would belong inside https://k8s.io/docs/reference/node/ or a new section https://k8s.io/docs/reference/pod/

Copy link
Author

Choose a reason for hiding this comment

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

@sftim This documentation would ideally belong to a new section https://k8s.io/docs/reference/lifecycle-events which have all possible areas and behaviors documentation for pod lifecycle events. Correct if I am wrong or there is a better way to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sftim
Copy link
Contributor

sftim commented Nov 26, 2024

/retitle [WIP] Add reference docs for pod PreStop hooks

per #48342 (comment)

@k8s-ci-robot k8s-ci-robot changed the title PreStop Hook Documentation added [WIP] Add reference docs for pod PreStop hooks Nov 26, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 26, 2024
@impact-maker impact-maker requested a review from sftim November 27, 2024 13:13
@impact-maker
Copy link
Author

impact-maker commented Nov 27, 2024

@sftim I am looking to get the work approved and ideally merge ready, I have created a slack thread for all the follow up questions. Aslo I have already got an approval from sig-docs on this work in the community biweekly meeting and looking to get a wholesome review on this so that I can iterate over this and close it.

@sftim
Copy link
Contributor

sftim commented Jan 14, 2025

When this is ready for review, please update the PR title to show that it's no longer a work-in-progress.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 14, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 14, 2025
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

Details

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@github-project-automation github-project-automation bot moved this from Work in progress to Done in SIG Node: code and documentation PRs Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. language/en Issues or PRs related to English language lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

Enhance pod lifecycle transitions testing and documentation

7 participants