Skip to content

Commit 2d5656d

Browse files
committed
feat: Refactor Helm chart
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent 8cca5e9 commit 2d5656d

27 files changed

+783
-644
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ WITH_GOFLAGS = GOFLAGS=$(GOFLAGS)
99
## Extra helm options
1010
CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev)
1111
CLUSTER_ENDPOINT ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].cluster.server}')
12-
HELM_OPTS ?= --set controller.clusterName=${CLUSTER_NAME} \
13-
--set controller.clusterEndpoint=${CLUSTER_ENDPOINT} \
14-
--set aws.defaultInstanceProfile=KarpenterNodeInstanceProfile-${CLUSTER_NAME}
12+
HELM_OPTS ?= --set serviceAccount.annotations.eks\.amazonaws\.com/role-arn=${KARPENTER_IAM_ROLE_ARN} \
13+
--set clusterName=${CLUSTER_NAME} \
14+
--set clusterEndpoint=${CLUSTER_ENDPOINT} \
15+
--set aws.defaultInstanceProfile=KarpenterNodeInstanceProfile-${CLUSTER_NAME}
1516

1617
help: ## Display help
1718
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@@ -49,7 +50,7 @@ licenses: ## Verifies dependency licenses and requires GITHUB_TOKEN to be set
4950
golicense hack/license-config.hcl karpenter
5051

5152
apply: ## Deploy the controller into your ~/.kube/config cluster
52-
helm template --include-crds karpenter charts/karpenter --namespace karpenter \
53+
helm template --include-crds karpenter charts/karpenter --namespace karpenter \
5354
$(HELM_OPTS) \
5455
--set controller.image=ko://github.com/aws/karpenter/cmd/controller \
5556
--set webhook.image=ko://github.com/aws/karpenter/cmd/webhook \
@@ -58,7 +59,6 @@ apply: ## Deploy the controller into your ~/.kube/config cluster
5859
delete: ## Delete the controller from your ~/.kube/config cluster
5960
helm template karpenter charts/karpenter --namespace karpenter \
6061
$(HELM_OPTS) \
61-
--set serviceAccount.create=false \
6262
| kubectl delete -f -
6363

6464
codegen: ## Generate code. Must be run if changes are made to ./pkg/apis/...

charts/karpenter/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/karpenter/Chart.yaml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
apiVersion: v2
2-
appVersion: "0.6.1"
32
name: karpenter
4-
description: A Helm chart for https://github.com/aws/karpenter/.
3+
description: A Helm chart for Karpenter, an open-source node provisioning project built for Kubernetes.
54
type: application
6-
version: "0.6.1"
5+
version: 0.6.1
6+
appVersion: 0.6.1
7+
keywords:
8+
- cluster
9+
- node
10+
- scheduler
11+
- autoscaling
12+
- lifecycle
13+
home: https://karpenter.sh/
14+
icon: https://repository-images.githubusercontent.com/278480393/dab059c8-caa1-4b55-aaa7-3d30e47a5616
15+
sources:
16+
- https://github.com/aws/karpenter/

charts/karpenter/README.md

+60-39
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,77 @@
11
# karpenter
22

3-
A Helm chart for https://github.com/aws/karpenter/.
3+
A Helm chart for Karpenter, an open-source node provisioning project built for Kubernetes.
44

55
![Version: 0.6.1](https://img.shields.io/badge/Version-0.6.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.1](https://img.shields.io/badge/AppVersion-0.6.1-informational?style=flat-square)
66

7+
## Documentation
8+
9+
For full Karpenter documentation please checkout [https://karpenter.sh](https://karpenter.sh/v0.6.1/).
10+
711
## Installing the Chart
812

9-
To install the chart with the release name `karpenter`:
13+
Before the chart can be installed the repo needs to be added to Helm, run the following commands to add the repo.
1014

11-
```console
12-
$ helm repo add karpenter https://charts.karpenter.sh
13-
$ helm repo update
14-
$ helm upgrade --install karpenter karpenter/karpenter --namespace karpenter \
15-
--create-namespace --set serviceAccount.create=false --version 0.6.1 \
16-
--set controller.clusterName=${CLUSTER_NAME} \
17-
--set controller.clusterEndpoint=$(aws eks describe-cluster --name ${CLUSTER_NAME} --query "cluster.endpoint" --output json) \
18-
--wait # for the defaulting webhook to install before creating a Provisioner
15+
```bash
16+
helm repo add karpenter https://charts.karpenter.sh/
17+
helm repo update
1918
```
2019

21-
You can follow the detailed installation instruction [here](https://karpenter.sh/docs/getting-started/#install).
20+
You can follow the detailed installation instruction in the [documentation](https://karpenter.sh/v0.6.1/getting-started/#install) which covers the Karpenter prerequisites and installation options. The outcome of these instructions should result in something like the following command.
21+
22+
```bash
23+
helm upgrade --install --namespace karpenter --create-namespace \
24+
karpenter karpenter/karpenter \
25+
--version 0.6.1 \
26+
--set serviceAccount.annotations.eks\.amazonaws\.com/role-arn=${KARPENTER_IAM_ROLE_ARN}
27+
--set clusterName=${CLUSTER_NAME} \
28+
--set clusterEndpoint=${CLUSTER_ENDPOINT} \
29+
--set aws.defaultInstanceProfile=KarpenterNodeInstanceProfile-${CLUSTER_NAME} \
30+
--wait # for the defaulting webhook to install before creating a Provisioner
31+
```
2232

2333
## Values
2434

2535
| Key | Type | Default | Description |
2636
|-----|------|---------|-------------|
27-
| additionalLabels | object | `{}` | Additional labels to add into metadata |
37+
| additionalAnnotations | object | `{}` | Additional annotations to add into metadata. |
38+
| additionalLabels | object | `{}` | Additional labels to add into metadata. |
39+
| affinity | object | `{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"key":"karpenter.sh/provisioner-name","operator":"DoesNotExist"}]}}}` | Affinity rules for scheduling the pod. |
2840
| aws.defaultInstanceProfile | string | `""` | The default instance profile to use when launching nodes on AWS |
29-
| controller.affinity | object | `{}` | Affinity rules for scheduling |
30-
| controller.clusterEndpoint | string | `""` | Cluster endpoint |
31-
| controller.clusterName | string | `""` | Cluster name |
32-
| controller.env | list | `[]` | Additional environment variables to run with |
33-
| controller.image | string | `"public.ecr.aws/karpenter/controller:v0.6.1@sha256:5a0bd78e2f7ada324677e2eb82e53b648593e9de1acf0a8fc84138a1a6be753c"` | Image to use for the Karpenter controller |
34-
| controller.nodeSelector | object | `{}` | Node selectors to schedule to nodes with labels. |
35-
| controller.replicas | int | `1` | |
36-
| controller.resources.limits.cpu | int | `1` | |
37-
| controller.resources.limits.memory | string | `"1Gi"` | |
38-
| controller.resources.requests.cpu | int | `1` | |
39-
| controller.resources.requests.memory | string | `"1Gi"` | |
40-
| controller.tolerations | list | `[]` | Tolerations to schedule to nodes with taints. |
41-
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account (like the ARN of the IRSA role) |
42-
| serviceAccount.create | bool | `true` | Create a service account for the application controller |
43-
| serviceAccount.name | string | `"karpenter"` | Service account name |
44-
| webhook.affinity | object | `{}` | Affinity rules for scheduling |
45-
| webhook.env | list | `[]` | List of environment items to add to the webhook |
46-
| webhook.hostNetwork | bool | `false` | Set to true if using custom CNI on EKS |
47-
| webhook.image | string | `"public.ecr.aws/karpenter/webhook:v0.6.1@sha256:7d75747caeb1ca63da1d68925b961c7a61f40faa76aa678320b2d3e090d1713f"` | Image to use for the webhook |
48-
| webhook.nodeSelector | object | `{}` | Node selectors to schedule to nodes with labels. |
49-
| webhook.port | int | `8443` | |
50-
| webhook.replicas | int | `1` | |
51-
| webhook.resources.limits.cpu | string | `"100m"` | |
52-
| webhook.resources.limits.memory | string | `"50Mi"` | |
53-
| webhook.resources.requests.cpu | string | `"100m"` | |
54-
| webhook.resources.requests.memory | string | `"50Mi"` | |
55-
| webhook.tolerations | list | `[]` | Tolerations to schedule to nodes with taints. |
41+
| clusterEndpoint | string | `""` | Cluster endpoint. |
42+
| clusterName | string | `""` | Cluster name. |
43+
| controller.env | list | `[]` | Additional environment variables for the controller pod. |
44+
| controller.image | string | `"public.ecr.aws/karpenter/controller:v0.6.1@sha256:5a0bd78e2f7ada324677e2eb82e53b648593e9de1acf0a8fc84138a1a6be753c"` | Controller image. |
45+
| controller.logLevel | string | `""` | Controller log level, defaults to the global log level |
46+
| controller.resources | object | `{"limits":{"cpu":1,"memory":"1Gi"},"requests":{"cpu":1,"memory":"1Gi"}}` | Resources for the controller pod. |
47+
| controller.securityContext | object | `{}` | SecurityContext for the controller container. |
48+
| fullnameOverride | string | `""` | Overrides the chart's computed fullname. |
49+
| hostNetwork | bool | `false` | Bind the pod to the host network. This is required when using a custom CNI. |
50+
| imagePullPolicy | string | `"IfNotPresent"` | Image pull policy for Docker images. |
51+
| imagePullSecrets | list | `[]` | Image pull secrets for Docker images. |
52+
| logLevel | string | `"info"` | Global log level |
53+
| nameOverride | string | `""` | Overrides the chart's name. |
54+
| nodeSelector | object | `{"kubernetes.io/os":"linux"}` | Node selectors to schedule the pod to nodes with labels. |
55+
| podAnnotations | object | `{}` | Additional annotations for the pod. |
56+
| podLabels | object | `{}` | Additional labels for the pod. |
57+
| podSecurityContext | object | `{"fsGroup":1000}` | SecurityContext for the pod. |
58+
| priorityClassName | string | `"system-cluster-critical"` | PriorityClass name for the pod. |
59+
| replicas | int | `1` | Number of replicas. |
60+
| serviceAccount.annotations | object | `{}` | Additional annotations for the ServiceAccount. |
61+
| serviceAccount.create | bool | `true` | Specifies if a ServiceAccount should be created. |
62+
| serviceAccount.name | string | `""` | The name of the ServiceAccount to use. If not set and create is true, a name is generated using the fullname template. |
63+
| serviceMonitor.additionalLabels | object | `{}` | Additional labels for the ServiceMonitor. |
64+
| serviceMonitor.enabled | bool | `false` | Specifies whether a ServiceMonitor should be created. |
65+
| serviceMonitor.endpointConfig | object | `{}` | Endpoint configuration for the ServiceMonitor. |
66+
| strategy | object | `{"type":"Recreate"}` | Strategy for updating the pod. |
67+
| terminationGracePeriodSeconds | string | `nil` | Override the default termination grace period for the pod. |
68+
| tolerations | list | `[]` | Tolerations to allow the pod to be scheduled to nodes with taints. |
69+
| webhook.env | list | `[]` | Additional environment variables for the webhook pod. |
70+
| webhook.image | string | `"public.ecr.aws/karpenter/webhook:v0.6.1@sha256:7d75747caeb1ca63da1d68925b961c7a61f40faa76aa678320b2d3e090d1713f"` | Webhook image. |
71+
| webhook.logLevel | string | `""` | Webhook log level, defaults to the global log level |
72+
| webhook.port | int | `8443` | The container port to use for the webhook. |
73+
| webhook.resources | object | `{"limits":{"cpu":"100m","memory":"50Mi"},"requests":{"cpu":"100m","memory":"50Mi"}}` | Resources for the webhook pod. |
74+
| webhook.securityContext | object | `{}` | SecurityContext for the webhook container. |
5675

76+
----------------------------------------------
77+
Autogenerated from chart metadata using [helm-docs v1.7.0](https://github.com/norwoodj/helm-docs/releases/v1.7.0)

charts/karpenter/README.md.gotmpl

+21-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,34 @@
33

44
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
55

6+
## Documentation
7+
8+
For full Karpenter documentation please checkout [https://karpenter.sh](https://karpenter.sh/v{{ template "chart.version" . }}/).
9+
610
## Installing the Chart
711

8-
To install the chart with the release name `karpenter`:
12+
Before the chart can be installed the repo needs to be added to Helm, run the following commands to add the repo.
913

10-
```console
11-
$ helm repo add karpenter https://charts.karpenter.sh
12-
$ helm repo update
13-
$ helm upgrade --install karpenter karpenter/{{ template "chart.name" . }} --namespace karpenter \
14-
--create-namespace --set serviceAccount.create=false --version {{ template "chart.version" . }} \
15-
--set controller.clusterName=${CLUSTER_NAME} \
16-
--set controller.clusterEndpoint=$(aws eks describe-cluster --name ${CLUSTER_NAME} --query "cluster.endpoint" --output json) \
17-
--wait # for the defaulting webhook to install before creating a Provisioner
14+
```bash
15+
helm repo add karpenter https://charts.karpenter.sh/
16+
helm repo update
1817
```
1918

20-
You can follow the detailed installation instruction [here](https://karpenter.sh/docs/getting-started/#install).
19+
You can follow the detailed installation instruction in the [documentation](https://karpenter.sh/v{{ template "chart.version" . }}/getting-started/#install) which covers the Karpenter prerequisites and installation options. The outcome of these instructions should result in something like the following command.
20+
21+
```bash
22+
helm upgrade --install --namespace karpenter --create-namespace \
23+
karpenter karpenter/{{ template "chart.name" . }} \
24+
--version {{ template "chart.version" . }} \
25+
--set serviceAccount.annotations.eks\.amazonaws\.com/role-arn=${KARPENTER_IAM_ROLE_ARN}
26+
--set clusterName=${CLUSTER_NAME} \
27+
--set clusterEndpoint=${CLUSTER_ENDPOINT} \
28+
--set aws.defaultInstanceProfile=KarpenterNodeInstanceProfile-${CLUSTER_NAME} \
29+
--wait # for the defaulting webhook to install before creating a Provisioner
30+
```
2131

2232
{{ template "chart.requirementsSection" . }}
2333

2434
{{ template "chart.valuesSection" . }}
2535

26-
{{ template "helm-docs.versionFooter" . }}
36+
{{ template "helm-docs.versionFooter" . }}

charts/karpenter/templates/_helpers.tpl

+30-32
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,53 @@
22
Expand the name of the chart.
33
*/}}
44
{{- define "karpenter.name" -}}
5-
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
6-
{{- end -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
77

88
{{/*
99
Create a default fully qualified app name.
1010
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1111
If release name contains chart name it will be used as a full name.
1212
*/}}
1313
{{- define "karpenter.fullname" -}}
14-
{{- if .Values.fullnameOverride -}}
15-
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
16-
{{- else -}}
17-
{{- $name := default .Chart.Name .Values.nameOverride -}}
18-
{{- if contains $name .Release.Name -}}
19-
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
20-
{{- else -}}
21-
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
22-
{{- end -}}
23-
{{- end -}}
24-
{{- end -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
2525

2626
{{/*
2727
Create chart name and version as used by the chart label.
2828
*/}}
2929
{{- define "karpenter.chart" -}}
30-
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
31-
{{- end -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
3232

3333
{{/*
34-
Generate basic labels
34+
Common labels
3535
*/}}
36-
{{- define "karpenter.labels" }}
36+
{{- define "karpenter.labels" -}}
3737
helm.sh/chart: {{ include "karpenter.chart" . }}
38-
app.kubernetes.io/managed-by: {{ .Release.Service }}
39-
app.kubernetes.io/component: karpenter
40-
app.kubernetes.io/part-of: {{ template "karpenter.name" . }}
41-
{{- include "karpenter.selectorLabels" . }}
42-
{{- if .Chart.Version }}
43-
app.kubernetes.io/version: {{ .Chart.Version | quote }}
38+
{{ include "karpenter.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4441
{{- end }}
45-
{{- if .Values.additionalLabels }}
46-
{{ toYaml .Values.additionalLabels }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- with .Values.additionalLabels }}
44+
{{ toYaml . }}
4745
{{- end }}
4846
{{- end }}
4947

5048
{{/*
5149
Selector labels
5250
*/}}
53-
{{- define "karpenter.selectorLabels" }}
51+
{{- define "karpenter.selectorLabels" -}}
5452
app.kubernetes.io/name: {{ include "karpenter.name" . }}
5553
app.kubernetes.io/instance: {{ .Release.Name }}
5654
{{- end }}
@@ -59,9 +57,9 @@ app.kubernetes.io/instance: {{ .Release.Name }}
5957
Create the name of the service account to use
6058
*/}}
6159
{{- define "karpenter.serviceAccountName" -}}
62-
{{- if .Values.serviceAccount.enabled -}}
63-
{{ default (include "karpenter.fullname" .) .Values.serviceAccount.name }}
64-
{{- else -}}
65-
{{ default "default" .Values.serviceAccount.name }}
66-
{{- end -}}
67-
{{- end -}}
60+
{{- if .Values.serviceAccount.create }}
61+
{{- default (include "karpenter.fullname" .) .Values.serviceAccount.name }}
62+
{{- else }}
63+
{{- default "default" .Values.serviceAccount.name }}
64+
{{- end }}
65+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: {{ include "karpenter.fullname" . }}
5+
labels:
6+
{{- include "karpenter.labels" . | nindent 4 }}
7+
{{- with .Values.additionalAnnotations }}
8+
annotations:
9+
{{- toYaml . | nindent 4 }}
10+
{{- }}
11+
rules:
12+
- apiGroups: ["karpenter.sh"]
13+
resources: ["provisioners"]
14+
verbs: ["get", "list", "watch"]
15+
- apiGroups: ["karpenter.sh"]
16+
resources: ["provisioners/status"]
17+
verbs: ["create", "delete", "patch", "get", "list", "watch"]
18+
- apiGroups: [""]
19+
resources: ["persistentvolumes", "persistentvolumeclaims"]
20+
verbs: ["get", "list", "watch", "update"]
21+
- apiGroups: ["storage.k8s.io"]
22+
resources: ["storageclasses"]
23+
verbs: ["get", "list", "watch"]
24+
- apiGroups: [""]
25+
resources: ["nodes", "pods"]
26+
verbs: ["get", "list", "watch", "patch", "delete"]
27+
- apiGroups: [""]
28+
resources: ["configmaps"]
29+
verbs: ["get", "list", "watch"]
30+
- apiGroups: [""]
31+
resources: ["nodes"]
32+
verbs: ["create"]
33+
- apiGroups: [""]
34+
resources: ["pods/binding", "pods/eviction"]
35+
verbs: ["create"]
36+
- apiGroups: ["apps"]
37+
resources: ["daemonsets"]
38+
verbs: ["list", "watch"]
39+
- apiGroups: ["admissionregistration.k8s.io"]
40+
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
41+
verbs: ["get", "watch", "list", "update"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: {{ include "karpenter.fullname" . }}
5+
labels:
6+
{{- include "karpenter.labels" . | nindent 4 }}
7+
{{- with .Values.additionalAnnotations }}
8+
annotations:
9+
{{- toYaml . | nindent 4 }}
10+
{{- }}
11+
roleRef:
12+
apiGroup: rbac.authorization.k8s.io
13+
kind: ClusterRole
14+
name: {{ include "karpenter.fullname" . }}
15+
subjects:
16+
- kind: ServiceAccount
17+
name: {{ template "karpenter.serviceAccountName" . }}
18+
namespace: {{ .Release.Namespace }}

0 commit comments

Comments
 (0)