From 4ba8f44e8573d134a102a1c64216f08817c00efe Mon Sep 17 00:00:00 2001 From: nadavbuc Date: Mon, 15 Apr 2024 17:45:16 +0300 Subject: [PATCH] add autotaint --- charts/karpenter_nodes/README.md | 1 + charts/karpenter_nodes/examples/nodegroups.yaml | 10 ++-------- charts/karpenter_nodes/examples/output/output.yaml | 4 ++-- charts/karpenter_nodes/templates/nodepool.yaml | 9 ++++++++- .../tests/nodepool_nodes_default_test.yaml | 4 ++-- .../tests/nodepool_nodes_workers_test.yaml | 14 ++++++++++++-- charts/karpenter_nodes/tests/values.yaml | 9 +++++---- charts/karpenter_nodes/values.yaml | 1 + 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/charts/karpenter_nodes/README.md b/charts/karpenter_nodes/README.md index 1717e84..60909a9 100644 --- a/charts/karpenter_nodes/README.md +++ b/charts/karpenter_nodes/README.md @@ -72,6 +72,7 @@ Note - Most of the values can be overridden per nodegroup (If not specified, it | `excludeInstanceSize` | Exclude specific instance sizes | `List` | ✓ | ✓ | | `headRoom` | Generate Ultra Low Priority Class for Headroom (see below) | `String` | ✓ | x | | `additionalRequirements` | add NodePool requirements which are not covered by this chart | `List(map)` | ✓ | ✓ | +| `autoTaint` | add NodePool taint with `dedicated` as key and `nodepool` (`-` replaced with `_`) | `Boolean` | ✓ | ✓ | ### NodeGroup Configuration | Key Name | Description | Type | Optional? | Optional Per NodeGroup? | diff --git a/charts/karpenter_nodes/examples/nodegroups.yaml b/charts/karpenter_nodes/examples/nodegroups.yaml index 034fb7c..270b867 100644 --- a/charts/karpenter_nodes/examples/nodegroups.yaml +++ b/charts/karpenter_nodes/examples/nodegroups.yaml @@ -31,10 +31,7 @@ nodeGroups: capacitySpread: start: 1 end: 5 - taints: - - key: "dedicated" - value: "workers" - effect: "NoSchedule" + autoTaint: true nodes-workers-c: nodeGroupLabel: nodes-workers capacitySpread: @@ -43,10 +40,7 @@ nodeGroups: instances: categories: - c - taints: - - key: "dedicated" - value: "workers" - effect: "NoSchedule" + autoTaint: true nodeClassRef: name: nodes-workers-amd64 nodes-canary: diff --git a/charts/karpenter_nodes/examples/output/output.yaml b/charts/karpenter_nodes/examples/output/output.yaml index 175a5c9..34f9c06 100644 --- a/charts/karpenter_nodes/examples/output/output.yaml +++ b/charts/karpenter_nodes/examples/output/output.yaml @@ -1526,8 +1526,8 @@ spec: name: nodes-workers-amd64 taints: - key: dedicated - value: workers effect: NoSchedule + value: nodes_workers requirements: - key: "karpenter.k8s.aws/instance-category" operator: In @@ -1641,8 +1641,8 @@ spec: name: nodes-workers-amd64 taints: - key: dedicated - value: workers effect: NoSchedule + value: nodes_workers requirements: - key: "karpenter.k8s.aws/instance-category" operator: In diff --git a/charts/karpenter_nodes/templates/nodepool.yaml b/charts/karpenter_nodes/templates/nodepool.yaml index 427c43a..ab45797 100644 --- a/charts/karpenter_nodes/templates/nodepool.yaml +++ b/charts/karpenter_nodes/templates/nodepool.yaml @@ -28,13 +28,20 @@ spec: {{- else }} name: {{ $k }}-{{ $v.instances.architecture | default $.Values.instances.architecture }} {{- end }} - {{- if hasKey $v "taints" }} + {{- if or (hasKey $v "taints") ($v.autoTaint | default $.Values.autoTaint) }} taints: + {{- if $v.autoTaint | default $.Values.autoTaint }} + - key: dedicated + effect: NoSchedule + value: {{ ($v.nodeGroupLabel | default $k) | replace "-" "_" }} + {{- end }} + {{- if hasKey $v "taints" }} {{- range $v.taints }} - key: {{ .key }} value: {{ .value }} effect: {{ .effect }} {{- end }} + {{- end }} {{- end }} {{- if hasKey $v "startupTaints" }} startupTaints: diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml index 6b9aa48..473ef5f 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml @@ -36,7 +36,7 @@ tests: value: taint1 - equal: path: spec.template.spec.taints[0].effect - value: noSchedule + value: NoSchedule - equal: path: spec.template.spec.taints[1].key value: testtaint2 @@ -45,7 +45,7 @@ tests: value: taint2 - equal: path: spec.template.spec.taints[1].effect - value: noSchedule + value: NoSchedule - it: Verify nodes-default requirements diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml index 9ae4919..b75f104 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml @@ -38,7 +38,7 @@ tests: value: taint1 - equal: path: spec.template.spec.startupTaints[0].effect - value: noSchedule + value: NoSchedule - equal: path: spec.template.spec.startupTaints[1].key value: testtaint2 @@ -47,7 +47,17 @@ tests: value: taint2 - equal: path: spec.template.spec.startupTaints[1].effect - value: noSchedule + value: NoSchedule + - equal: + path: spec.template.spec.taints[0].key + value: dedicated + - equal: + path: spec.template.spec.taints[0].value + value: nodes_workers + - equal: + path: spec.template.spec.taints[0].effect + value: NoSchedule + - it: Verify nodes-workers requirements documentIndex: 2 diff --git a/charts/karpenter_nodes/tests/values.yaml b/charts/karpenter_nodes/tests/values.yaml index d1273dc..878d36a 100644 --- a/charts/karpenter_nodes/tests/values.yaml +++ b/charts/karpenter_nodes/tests/values.yaml @@ -13,10 +13,10 @@ nodeGroups: testlabel2: label2 taints: - key: testtaint1 - effect: noSchedule + effect: NoSchedule value: taint1 - key: testtaint2 - effect: noSchedule + effect: NoSchedule value: taint2 excludeFamilies: - c6a @@ -123,11 +123,12 @@ nodeGroups: memory: "384Gi" startupTaints: - key: testtaint1 - effect: noSchedule + effect: NoSchedule value: taint1 - key: testtaint2 - effect: noSchedule + effect: NoSchedule value: taint2 + autoTaint: true #Default cluster Settings clusterName: "eks-dev" diff --git a/charts/karpenter_nodes/values.yaml b/charts/karpenter_nodes/values.yaml index 526c7c1..f82fce5 100644 --- a/charts/karpenter_nodes/values.yaml +++ b/charts/karpenter_nodes/values.yaml @@ -81,6 +81,7 @@ instances: operatingSystems: - linux +autoTaint: false ## Exclude weak types of AMD instances # excludeFamilies: # - c6a