-
Notifications
You must be signed in to change notification settings - Fork 310
[Feature] Add Karpenter Do Not Disrupt policy for Karpenter 1.x migration #1209
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
Indrranil
wants to merge
7
commits into
kyverno:main
Choose a base branch
from
Indrranil:add-karpenter-do-not-disrupt-policy
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a579db
[Feature] Add Karpenter Do Not Disrupt policy for Karpenter 1.x migra…
Indrranil 884c3a4
[Feature] Add tests for Karpenter Do Not Disrupt policy
Indrranil 59cd794
adjust preconditions to properly skip unlabeled pods
Indrranil 5976070
Merge branch 'main' into add-karpenter-do-not-disrupt-policy
JimBugwadia eed1a81
Merge branch 'main' into add-karpenter-do-not-disrupt-policy
fjogeleit a02dccc
Merge branch 'main' into add-karpenter-do-not-disrupt-policy
JimBugwadia 1da220a
Merge branch 'main' into add-karpenter-do-not-disrupt-policy
JimBugwadia 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
28 changes: 28 additions & 0 deletions
28
karpenter/add-karpenter-donot-disrupt/.chainsaw-test/chainsaw-test.yaml
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,28 @@ | ||
| apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
| kind: Test | ||
| metadata: | ||
| name: add-karpenter-donot-disrupt | ||
| spec: | ||
| steps: | ||
| - name: step-01 | ||
| try: | ||
| - apply: | ||
| file: ../add-karpenter-donot-disrupt.yaml | ||
| - assert: | ||
| file: policy-ready.yaml | ||
| - name: step-02 | ||
| try: | ||
| - apply: | ||
| file: ../.kyverno-test/resource.yaml | ||
| - apply: | ||
| file: resource-others.yaml | ||
| - name: step-03 | ||
| try: | ||
| - assert: | ||
| file: ../.kyverno-test/patched01.yaml | ||
| - assert: | ||
| file: ../.kyverno-test/patched02.yaml | ||
| - assert: | ||
| file: patched03.yaml | ||
| - assert: | ||
| file: patched04.yaml |
11 changes: 11 additions & 0 deletions
11
karpenter/add-karpenter-donot-disrupt/.chainsaw-test/patched03.yaml
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,11 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-1 | ||
| labels: | ||
| karpenter.sh/do-not-evict: "true" | ||
| karpenter.sh/do-not-disrupt: "true" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
10 changes: 10 additions & 0 deletions
10
karpenter/add-karpenter-donot-disrupt/.chainsaw-test/patched04.yaml
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,10 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-2 | ||
| labels: | ||
| karpenter.sh/do-not-evict: "false" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
9 changes: 9 additions & 0 deletions
9
karpenter/add-karpenter-donot-disrupt/.chainsaw-test/policy-ready.yaml
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,9 @@ | ||
| apiVersion: kyverno.io/v1 | ||
| kind: ClusterPolicy | ||
| metadata: | ||
| name: add-karpenter-donot-disrupt | ||
| status: | ||
| conditions: | ||
| - reason: Succeeded | ||
| status: "True" | ||
| type: Ready |
21 changes: 21 additions & 0 deletions
21
karpenter/add-karpenter-donot-disrupt/.chainsaw-test/resource-others.yaml
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,21 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-1 | ||
| labels: | ||
| karpenter.sh/do-not-evict: "true" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-2 | ||
| labels: | ||
| karpenter.sh/do-not-evict: "false" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
23 changes: 23 additions & 0 deletions
23
karpenter/add-karpenter-donot-disrupt/.kyverno-test/kyverno-test.yaml
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,23 @@ | ||
| apiVersion: cli.kyverno.io/v1alpha1 | ||
| kind: Test | ||
| metadata: | ||
| name: add-karpenter-donot-disrupt | ||
| policies: | ||
| - ../add-karpenter-donot-disrupt.yaml | ||
| resources: | ||
| - resource.yaml | ||
| results: | ||
| - kind: Pod | ||
| patchedResource: patched01.yaml | ||
| policy: add-karpenter-donot-disrupt | ||
| resources: | ||
| - test-pod-with-evict | ||
| result: pass | ||
| rule: add-donot-disrupt-label | ||
| - kind: Pod | ||
| patchedResource: patched02.yaml | ||
| policy: add-karpenter-donot-disrupt | ||
| resources: | ||
| - test-pod-without-evict | ||
| result: skip | ||
| rule: add-donot-disrupt-label |
11 changes: 11 additions & 0 deletions
11
karpenter/add-karpenter-donot-disrupt/.kyverno-test/patched01.yaml
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,11 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-with-evict | ||
| labels: | ||
| karpenter.sh/do-not-evict: "true" | ||
| karpenter.sh/do-not-disrupt: "true" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
8 changes: 8 additions & 0 deletions
8
karpenter/add-karpenter-donot-disrupt/.kyverno-test/patched02.yaml
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,8 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-without-evict | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
19 changes: 19 additions & 0 deletions
19
karpenter/add-karpenter-donot-disrupt/.kyverno-test/resource.yaml
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,19 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-with-evict | ||
| labels: | ||
| karpenter.sh/do-not-evict: "true" | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: test-pod-without-evict | ||
| spec: | ||
| containers: | ||
| - name: nginx | ||
| image: nginx:1.14.2 |
34 changes: 34 additions & 0 deletions
34
karpenter/add-karpenter-donot-disrupt/add-karpenter-donot-disrupt.yaml
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,34 @@ | ||
| apiVersion: kyverno.io/v1 | ||
| kind: ClusterPolicy | ||
| metadata: | ||
| name: add-karpenter-donot-disrupt | ||
| annotations: | ||
| policies.kyverno.io/title: Add Karpenter Do Not Disrupt | ||
| policies.kyverno.io/category: Karpenter, EKS Best Practices | ||
| policies.kyverno.io/severity: medium | ||
| policies.kyverno.io/subject: Pod | ||
| kyverno.io/kyverno-version: 1.7.1 | ||
| policies.kyverno.io/minversion: 1.6.0 | ||
| kyverno.io/kubernetes-version: "1.23" | ||
| policies.kyverno.io/description: >- | ||
| This policy assists in migrating from Karpenter 0.x to 1.x by adding the | ||
| karpenter.sh/do-not-disrupt label to pods that have the deprecated | ||
| karpenter.sh/do-not-evict label. This ensures smooth upgrades and | ||
| maintains the intended protection against pod disruption. | ||
| spec: | ||
| rules: | ||
| - name: add-donot-disrupt-label | ||
| match: | ||
| resources: | ||
| kinds: | ||
| - Pod | ||
| preconditions: | ||
| all: | ||
| - key: '{{ request.object.metadata.labels."karpenter.sh/do-not-evict" || '''' }}' | ||
| operator: NotEquals | ||
| value: "" | ||
realshuting marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mutate: | ||
| patchStrategicMerge: | ||
| metadata: | ||
| labels: | ||
| karpenter.sh/do-not-disrupt: "true" | ||
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,33 @@ | ||
| name: add-karpenter-donot-disrupt | ||
| version: 1.0.0 | ||
| displayName: Add Karpenter Do Not Disrupt Label | ||
| createdAt: "2024-12-17T00:00:00Z" | ||
| description: | | ||
| This policy assists in migrating from Karpenter 0.x to 1.x by adding the | ||
| karpenter.sh/do-not-disrupt label to pods that have the deprecated | ||
| karpenter.sh/do-not-evict label. This ensures smooth upgrades and | ||
| maintains the intended protection against pod disruption during Karpenter | ||
| node termination. | ||
| install: | | ||
| ```sh | ||
| kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/karpenter/add-karpenter-donot-disrupt/add-karpenter-donot-disrupt.yaml | ||
| ``` | ||
| keywords: | ||
| - kyverno | ||
| - karpenter | ||
| readme: | | ||
| # Add Karpenter Do Not Disrupt Label | ||
|
|
||
| This policy facilitates the migration from Karpenter 0.x to 1.x by automatically | ||
| adding the new karpenter.sh/do-not-disrupt label to pods that use the deprecated | ||
| karpenter.sh/do-not-evict label. | ||
|
|
||
| When a pod is created with the old karpenter.sh/do-not-evict label, this policy | ||
| automatically adds the new karpenter.sh/do-not-disrupt label to ensure the pod | ||
| remains protected during node termination operations in Karpenter 1.x. | ||
|
|
||
| Reference for this change: https://karpenter.sh/v1.0/upgrading/v1beta1-migration/ | ||
| annotations: | ||
| kyverno.io/category: Pod | ||
| kyverno.io/kubernetes-version: "1.23" | ||
| kyverno.io/subject: "Pod, Migration" |
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.
Uh oh!
There was an error while loading. Please reload this page.