From 8f2be32ac8e8040e84802b30f33f43d740be434d Mon Sep 17 00:00:00 2001 From: Abhishek Dubey Date: Mon, 30 Dec 2024 23:40:36 +0530 Subject: [PATCH] Added functionality to loop over different node pools Signed-off-by: Abhishek Dubey --- charts/karpenter/templates/node-pool.yaml | 68 ++++++++++++ charts/karpenter/templates/nodePool.yaml | 72 ------------ charts/karpenter/values.yaml | 129 +++++++++++----------- 3 files changed, 132 insertions(+), 137 deletions(-) create mode 100644 charts/karpenter/templates/node-pool.yaml delete mode 100644 charts/karpenter/templates/nodePool.yaml diff --git a/charts/karpenter/templates/node-pool.yaml b/charts/karpenter/templates/node-pool.yaml new file mode 100644 index 0000000..ce4ac63 --- /dev/null +++ b/charts/karpenter/templates/node-pool.yaml @@ -0,0 +1,68 @@ +{{- range .Values.nodePools }} +apiVersion: karpenter.sh/v1 +kind: NodePool +metadata: + name: {{ .name }} +spec: + template: + metadata: + labels: +{{- if .labels }} +{{- range $key, $value := .labels }} + {{ $key }}: {{ $value }} +{{- end }} +{{- else }} + {} # Empty labels object if no labels are defined +{{- end }} + annotations: +{{- if .annotations }} +{{- range $key, $value := .annotations }} + {{ $key }}: {{ $value }} +{{- end }} +{{- else }} + {} # Empty annotations object if no annotations are defined +{{- end }} + spec: + requirements: +{{- if .requirements | len }} +{{- range .requirements }} + - key: {{ .key }} + operator: {{ .operator }} + values: +{{ toYaml .values | indent 12 }} +{{- if .minValues }} + minValues: {{ .minValues }} +{{- end }} +{{- end }} +{{- else }} + [] # In case requirements is empty, an empty array will be passed +{{- end }} + + taints: +{{- if .taints }} +{{- range .taints }} + - key: {{ .key }} + {{- if .value }} + value: {{ .value }} + {{- end }} + effect: {{ .effect }} +{{- end }} +{{- else }} + [] # Empty taints array if no taints are defined +{{- end }} + nodeClassRef: + group: {{ .nodeClass.group | default "karpenter.k8s.aws" }} + kind: {{ .nodeClass.kind | default "EC2NodeClass" }} + name: {{ .nodeClass.name }} + expireAfter: {{ .expireAfter | default "720h" }} + limits: +{{- if .limits.cpu }} + cpu: {{ .limits.cpu }} +{{- end }} +{{- if .limits.memory }} + memory: {{ .limits.memory }} +{{- end }} + disruption: + consolidationPolicy: {{ .disruption.consolidationPolicy | default "WhenEmptyOrUnderutilized" }} + consolidateAfter: {{ .disruption.consolidateAfter | default "1m" }} +{{- end }} diff --git a/charts/karpenter/templates/nodePool.yaml b/charts/karpenter/templates/nodePool.yaml deleted file mode 100644 index 65ff4dd..0000000 --- a/charts/karpenter/templates/nodePool.yaml +++ /dev/null @@ -1,72 +0,0 @@ -apiVersion: karpenter.sh/v1 -kind: NodePool -metadata: - name: {{ .Values.nodePools.name }} -spec: - template: - metadata: - # Labels - This will loop over and add all labels specified in values.yaml - labels: -{{- if .Values.nodePools.labels }} -{{- range $key, $value := .Values.nodePools.labels }} - {{ $key }}: {{ $value }} -{{- end }} -{{- else }} - {} # Empty labels object if no labels are defined -{{- end }} - # Annotations - This will loop over and add all annotations specified in values.yaml - annotations: -{{- if .Values.nodePools.annotations }} -{{- range $key, $value := .Values.nodePools.annotations }} - {{ $key }}: {{ $value }} -{{- end }} -{{- else }} - {} # Empty annotations object if no annotations are defined -{{- end }} - - spec: - requirements: -{{- if .Values.nodePools.requirements | len }} -{{- range .Values.nodePools.requirements }} - - key: {{ .key }} - operator: {{ .operator }} - values: -{{ toYaml .values | indent 12 }} -{{- if .minValues }} - minValues: {{ .minValues }} -{{- end }} -{{- end }} -{{- else }} - [] # In case requirements is empty, an empty array will be passed -{{- end }} - - taints: -{{- if .Values.nodePools.taints }} -{{- range .Values.nodePools.taints }} - - key: {{ .key }} - {{- if .value }} - value: {{ .value }} - {{- end }} - effect: {{ .effect }} -{{- end }} -{{- else }} - [] # Empty taints array if no taints are defined -{{- end }} - - nodeClassRef: - group: {{ .Values.nodePools.nodeClass.group | default "karpenter.k8s.aws" }} - kind: {{ .Values.nodePools.nodeClass.kind | default "EC2NodeClass" }} - name: {{ .Values.nodePools.nodeClass.name }} - expireAfter: {{ .Values.nodePools.expireAfter | default "720h" }} - - limits: -{{- if .Values.nodePools.limits.cpu }} - cpu: {{ .Values.nodePools.limits.cpu }} -{{- end }} -{{- if .Values.nodePools.limits.memory }} - memory: {{ .Values.nodePools.limits.memory }} -{{- end }} - - disruption: - consolidationPolicy: {{ .Values.nodePools.disruption.consolidationPolicy | default "WhenEmptyOrUnderutilized" }} - consolidateAfter: {{ .Values.nodePools.disruption.consolidateAfter | default "1m" }} diff --git a/charts/karpenter/values.yaml b/charts/karpenter/values.yaml index 39eedb8..ec26f0d 100644 --- a/charts/karpenter/values.yaml +++ b/charts/karpenter/values.yaml @@ -23,68 +23,67 @@ karpenter: # Node Pool Configuration nodePools: - name: default - requirements: - - key: kubernetes.io/arch - operator: In - values: - - "amd64" - - key: kubernetes.io/os - operator: In - values: - - "linux" - - key: karpenter.sh/capacity-type - operator: In - values: - - "on-demand" - - key: karpenter.k8s.aws/instance-category - operator: In - values: - - "t" - - "m" - - "r" - minValues: 2 - - key: karpenter.k8s.aws/instance-family - operator: Exists - minValues: 5 - - key: karpenter.k8s.aws/instance-family - operator: In - values: - - "m5" - - "m5d" - - "c5" - - "c5d" - - "c4" - - "r4" - minValues: 3 - - key: node.kubernetes.io/instance-type - operator: Exists - minValues: 10 - - key: karpenter.k8s.aws/instance-generation - operator: Gt - values: - - "2" - - nodeClass: - group: karpenter.k8s.aws - kind: EC2NodeClass - name: default - expireAfter: 720h - limits: - cpu: "1000" - memory: "1000Gi" - disruption: - consolidationPolicy: WhenEmptyOrUnderutilized - consolidateAfter: 1m - taints: - - key: "example.com/special-taint" - value: "my-value" - effect: "NoSchedule" - - key: "example.com/another-taint" - effect: "NoExecute" - labels: - billing-team: my-team - environment: production - annotations: - example.com/owner: "my-team" - example.com/maintainer: "admin@company.com" + - name: default + expireAfter: 720h + labels: + billing-team: my-team + environment: production + annotations: + example.com/owner: "my-team" + example.com/maintainer: "admin@company.com" + limits: + cpu: "1000" + memory: "1000Gi" + disruption: + consolidationPolicy: WhenEmptyOrUnderutilized + consolidateAfter: 1m + nodeClass: + group: karpenter.k8s.aws + kind: EC2NodeClass + name: default + taints: + - key: "example.com/special-taint" + value: "my-value" + effect: "NoSchedule" + - key: "example.com/another-taint" + effect: "NoExecute" + requirements: + - key: kubernetes.io/arch + operator: In + values: + - "amd64" + - key: kubernetes.io/os + operator: In + values: + - "linux" + - key: karpenter.sh/capacity-type + operator: In + values: + - "on-demand" + - key: karpenter.k8s.aws/instance-category + operator: In + values: + - "t" + - "m" + - "r" + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: karpenter.k8s.aws/instance-family + operator: In + values: + - "m5" + - "m5d" + - "c5" + - "c5d" + - "c4" + - "r4" + minValues: 3 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: + - "2"