Repository navigation
MCO-2599: makes bootc-operator aware of karpenter #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cheesesashimi
wants to merge
1
commit into
bootc-dev:main
Choose a base branch
from
cheesesashimi:zzlotnik/karpenter-annotations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+473
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Karpenter integration | ||
|
|
||
| bootc-operator is aware of [Karpenter](https://karpenter.sh/) and coordinates | ||
| with it during node updates to prevent unnecessary node replacement or | ||
| voluntary disruption. | ||
|
|
||
| ## Why this matters | ||
|
|
||
| Karpenter monitors nodes for health and may decide to replace or disrupt a | ||
| node that appears unhealthy or underutilized — for example, one that is | ||
| cordoned, being drained, or not yet Ready after a reboot. All of those | ||
| conditions arise naturally during a bootc-operator update window, so without | ||
| coordination Karpenter could race with the operator and terminate a node that | ||
| is in the middle of a legitimate OS update. | ||
|
|
||
| Karpenter respects two node-level annotations: | ||
|
|
||
| - `karpenter.sh/do-not-repair: "true"` — prevents Node Auto Repair from | ||
| replacing a node that has unhealthy conditions. | ||
| - `karpenter.sh/do-not-disrupt: "true"` — prevents voluntary disruption | ||
| actions (consolidation, drift) from selecting this node. | ||
|
|
||
| > **Note:** `karpenter.sh/do-not-repair` was introduced in | ||
| > [kubernetes-sigs/karpenter#3311](https://github.com/kubernetes-sigs/karpenter/pull/3311) | ||
| > and has not yet appeared in a Karpenter release. This doc will be updated | ||
| > with a minimum required version once one is available. | ||
|
|
||
| bootc-operator sets both annotations automatically on Karpenter-managed nodes | ||
| for the duration of the reboot slot. | ||
|
|
||
| ## How it works | ||
|
|
||
| When the controller assigns a reboot slot to a node it checks whether the K8s | ||
| Node object has an owner reference pointing to a Karpenter `NodeClaim` | ||
| (`apiVersion: karpenter.sh/v1`, `kind: NodeClaim`). If it does, the | ||
| controller takes the following steps: | ||
|
|
||
| 1. For each annotation (`do-not-repair`, `do-not-disrupt`): if the annotation | ||
| is **not** already present on the Node, the controller adds it (value | ||
| `"true"`) and records ownership by setting the corresponding tracking | ||
| annotation on the `BootcNode` object: | ||
| - `bootc.dev/owns-karpenter-do-not-repair: "true"` | ||
| - `bootc.dev/owns-karpenter-do-not-disrupt: "true"` | ||
| 2. The node proceeds through the normal update flow: drain, reboot, image | ||
| verification. | ||
| 3. When the slot is freed (node is Ready and running the new image), the | ||
| controller checks the tracking annotations on the `BootcNode`. For each | ||
| annotation it owns, it removes the corresponding annotation from the Node | ||
| and clears the tracking annotation from the `BootcNode`. Both removals are | ||
| issued as a single Node patch. | ||
|
|
||
| ## Pre-existing annotations | ||
|
|
||
| If either Karpenter annotation is already on the Node before slot assignment — | ||
| set by an external actor, another controller, or a manual operation — | ||
| bootc-operator leaves it completely alone: | ||
|
|
||
| - It does **not** overwrite or change the annotation on assignment. | ||
| - It does **not** set the corresponding tracking annotation on the `BootcNode`. | ||
| - It does **not** remove the annotation when the slot is freed. | ||
|
|
||
| The two annotations are tracked independently. If only one is pre-existing, the | ||
| operator owns (and later removes) only the other. | ||
|
|
||
| This ensures bootc-operator never removes an annotation it did not add. | ||
|
|
||
| ## Limitations | ||
|
|
||
| `karpenter.sh/do-not-disrupt` only blocks voluntary disruption methods | ||
| (consolidation and drift). It does not protect a node against forceful | ||
| termination triggered by expiration (`expireAfter`), interruption (spot | ||
| instance reclaim), Node Auto Repair, or manual deletion. If any of those | ||
| events occur while a node is in a bootc-operator reboot slot, Karpenter may | ||
| still terminate it. | ||
|
|
||
| `karpenter.sh/do-not-repair` similarly has no effect on voluntary disruption | ||
| or expiration — it only suppresses Node Auto Repair. | ||
|
|
||
| If a node is terminated by expiration, interruption, or any other forceful | ||
| method while a bootc-operator update is in progress, the termination is caused | ||
| by Karpenter acting on its own policy — not by the bootc-operator update. The | ||
| update simply happened to be in flight at the time. | ||
|
|
||
| Refer to the [Karpenter disruption documentation](https://karpenter.sh/docs/concepts/disruption/) | ||
| for a full breakdown of which controls apply to which disruption methods. | ||
|
|
||
| ## Non-Karpenter nodes | ||
|
|
||
| Nodes without a `NodeClaim` owner reference are unaffected. The feature | ||
| activates only when the owner reference check matches. | ||
|
|
||
| ## Annotation reference | ||
|
|
||
| | Annotation | Object | Managed by | Purpose | | ||
| |---|---|---|---| | ||
| | `karpenter.sh/do-not-repair` | K8s Node | bootc-operator (or external) | Prevents Karpenter Node Auto Repair from replacing this node during an update | | ||
| | `karpenter.sh/do-not-disrupt` | K8s Node | bootc-operator (or external) | Prevents Karpenter voluntary disruption (consolidation, drift) during an update | | ||
| | `bootc.dev/owns-karpenter-do-not-repair` | BootcNode | bootc-operator | Tracks that the operator added `do-not-repair`; cleared when the annotation is removed on slot free | | ||
| | `bootc.dev/owns-karpenter-do-not-disrupt` | BootcNode | bootc-operator | Tracks that the operator added `do-not-disrupt`; cleared when the annotation is removed on slot free | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this if if then we are evaluating each conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a early return and avoid the nested if, like: