Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavbuc committed Apr 15, 2024
1 parent cf80be4 commit 8dcda1c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ You can then run `helm search repo fiverr_public` to see the charts.

## License

<!-- Keep full URL links to repo files because this README syncs from main to gh-pages. -->
[Apache 2.0 License](https://github.com/fiverr/public_charts/blob/main/LICENSE).
<!-- Keep full URL links to repo files because this README syncs from master to gh-pages. -->
[Apache 2.0 License](https://github.com/fiverr/public_charts/blob/master/LICENSE).

## Helm charts build status

Expand Down
2 changes: 1 addition & 1 deletion charts/karpenter_nodes/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: karpenter_nodes
version: 0.0.2
version: 0.1.0
description: A Helm chart for generating NodeClasses and NodePools for Karpenter
maintainers:
- name: nadavbuc
7 changes: 4 additions & 3 deletions charts/karpenter_nodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ The `UserData` field supports templating and your own values. You can take a loo

### Testing Your Changes
After making changes you will probably want to see the new output. Run `helm template` with the relevant example files: </br>
`helm template . -f values.yaml`
`helm template <some-name> . -f values.yaml`

### Unit Tests
Make sure you have `helm-unittest` plugin installed. [helm-unittest](https://github.com/helm-unittest/helm-unittest)

Unit tests are written in `tests` directory. To run the tests, use the following command: </br>
`helm unittest --helm3 karpenter_nodes -f "tests/$value/*_test.yaml"`
`helm unittest --helm3 karpenter_nodes -f "tests/*_test.yaml"`


## Configuration keys
Expand Down Expand Up @@ -72,6 +72,7 @@ Note - Most of the values can be overridden per nodegroup (If not specified, it
| `consolidateAfter` | Specify how long to wait before consolidating nodes [Documentation](https://karpenter.sh/docs/concepts/nodepools/) | `String` |||
| `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)` |||

### NodeGroup Configuration
| Key Name | Description | Type | Optional? | Optional Per NodeGroup? |
Expand All @@ -96,7 +97,7 @@ The pods will be configured with ultra-low priority, and will be terminated and
| `nodegroups.{}.headRoom` | List of headroom configurations for the nodePool | `List(Map)` |||
| `nodegroups.{}.headRoom.size` | `small`, `medium`, `large`, `xlarge` - see below | `String` |||
| `nodegroups.{}.headRoom.count` | Number of headroom pod replicas to schedule | `Integer` |||
| `nodegroups.{}.headRoom.antiAffinitySpec` | Required - set antiaffinity to match against all running workloads | `LabelSelectorSpec` |||
| `nodegroups.{}.headRoom.antiAffinitySpec` | Optional - set antiaffinity to match against running workloads | `LabelSelectorSpec` |||
| `nodegroups.{}.headRoom.nameSpaces` | Specify list of namespaces to match again (default `all`) | `List(String)` |||

### Headroom Sizing
Expand Down
2 changes: 2 additions & 0 deletions charts/karpenter_nodes/templates/headroom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ spec:
operator: In
values:
- headroom-{{ $k }}-{{ $v.instances.architecture | default $.Values.instances.architecture }}-{{ $nhr.size }}
{{- if hasKey $nhr "antiAffinitySpec" }}
{{- $nhr.antiAffinitySpec | toYaml | nindent 14 }}
{{- end }}
topologyKey: kubernetes.io/hostname
{{- if hasKey $nhr "nameSpaces" }}
namespaces:
Expand Down
8 changes: 3 additions & 5 deletions charts/karpenter_nodes/templates/nodeclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ spec:
{{- end }}
amiFamily: {{ $v.amiFamily | default $.Values.amiFamily }}
amiSelectorTerms:
{{- if hasKey $v "amiSelectorTerms" }}
{{- toYaml $v.amiSelectorTerms | nindent 4 }}
{{- else }}
{{- toYaml $.Values.amiSelectorTerms | nindent 4 }}
{{- if or (hasKey $v "amiSelectorTerms") (hasKey $.Values "amiSelectorTerms") }}
{{- toYaml ($v.amiSelectorTerms | default $.Values.amiSelectorTerms) | nindent 4 }}
{{- end }}
subnetSelectorTerms:
{{- if hasKey $v "subnetSelectorTerms" }}
Expand All @@ -44,7 +42,7 @@ spec:
{{- toYaml ($v.nodeTags | default $.Values.nodeTags) | nindent 4 }}
{{- end }}
{{- if hasKey $v "additionalNodeTags" }}
{{- toYaml $v.tags | nindent 4 }}
{{- toYaml $v.additionalNodeTags | nindent 4 }}
{{- end }}
managed_by: karpenter
blockDeviceMappings:
Expand Down
19 changes: 4 additions & 15 deletions charts/karpenter_nodes/templates/nodepool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,6 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if or (hasKey $.Values "excludeCpuManufacturer") (hasKey $v "excludeCpuManufacturer") }}
- key: "karpenter.k8s.aws/instance-cpu-manufacturer"
operator: NotIn
values:
{{- if hasKey $v "excludeCpuManufacturer" }}
{{- range $v .excludeCpuManufacturer }}
- {{ . }}
{{- end }}
{{- else }}
{{- range $.Values.excludeCpuManufacturer }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- if or (hasKey $.Values "excludeInstanceSize") (hasKey $v "excludeInstanceSize") }}
- key: "karpenter.k8s.aws/instance-size"
operator: NotIn
Expand Down Expand Up @@ -146,6 +132,9 @@ spec:
- {{ . -}}
{{- end }}
{{- end }}
{{- if or (hasKey $.Values "additionalRequirements") (hasKey $v "additionalRequirements") }}
{{- toYaml ($v.additionalRequirements | default $.Values.additionalRequirements) | nindent 8 }}
{{- end }}
kubelet:
{{- if or (hasKey $v "kubeletClusterDNS") (hasKey $.Values "kubeletClusterDNS") }}
clusterDNS:
Expand Down Expand Up @@ -209,7 +198,7 @@ spec:
consolidateAfter: {{ $v.consolidateAfter | default $.Values.consolidateAfter }}
{{- if $v.budgets }}
budgets:
{{- $v.budgets | toYaml | nindent 6 }}
{{- toYaml $v.budgets | nindent 6 }}
{{- end }}
{{- if hasKey $v "limits" }}
limits:
Expand Down
6 changes: 0 additions & 6 deletions charts/karpenter_nodes/tests/headroom_nodes_default_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ tests:
- equal:
path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchExpressions[0].values[0]
value: headroom-nodes-default-amd64-small
- equal:
path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchExpressions[1].key
value: testlabel1
- equal:
path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector.matchExpressions[1].operator
value: Exists
- equal:
path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].namespaces
value: {}
Expand Down
36 changes: 27 additions & 9 deletions charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ tests:
- it: Verify nodes-default requirements
documentIndex: 0
asserts:
# instance-category
- equal:
path: spec.template.spec.requirements[0].key
value: "karpenter.k8s.aws/instance-category"
- notContains:
path: spec.template.spec.requirements[0].values
content: t
Expand All @@ -62,47 +64,63 @@ tests:
- equal:
path: spec.template.spec.requirements[0].values[2]
value: c
# instance-cpu
- equal:
path: spec.template.spec.requirements[1].key
value: "karpenter.k8s.aws/instance-cpu"
- equal:
path: spec.template.spec.requirements[1].values[0]
value: "4"
- equal:
path: spec.template.spec.requirements[1].values[2]
value: "16"
# instance-generation
- equal:
path: spec.template.spec.requirements[2].key
value: "karpenter.k8s.aws/instance-generation"
- equal:
path: spec.template.spec.requirements[2].operator
value: "Gt"
- equal:
path: spec.template.spec.requirements[2].values[0]
value: "6"
# instance-zone
- equal:
path: spec.template.spec.requirements[3].key
value: "topology.kubernetes.io/zone"
- equal:
path: spec.template.spec.requirements[3].values[0]
value: "eu-west-1a"
- equal:
path: spec.template.spec.requirements[3].values[2]
value: "eu-west-1c"
# instance-architecture
- equal:
path: spec.template.spec.requirements[4].key
value: "kubernetes.io/arch"
- equal:
path: spec.template.spec.requirements[4].values[0]
value: "amd64"
# instance-capacity-type
- equal:
path: spec.template.spec.requirements[5].key
value: "karpenter.sh/capacity-type"
- equal:
path: spec.template.spec.requirements[5].values[0]
value: "spot"
- equal:
path: spec.template.spec.requirements[5].values[1]
value: "on-demand"
# instance-OS
- equal:
path: spec.template.spec.requirements[6].key
value: "kubernetes.io/os"
- equal:
path: spec.template.spec.requirements[6].values[0]
value: "linux"
# instance-family Exclusions
- equal:
path: spec.template.spec.requirements[7].key
value: "karpenter.k8s.aws/instance-family"
- equal:
path: spec.template.spec.requirements[7].values[0]
value: "c6a"
# instance-size Exclusiong
- equal:
path: spec.template.spec.requirements[8].key
value: "karpenter.k8s.aws/instance-size"
- equal:
path: spec.template.spec.requirements[8].operator
value: NotIn
Expand Down
65 changes: 56 additions & 9 deletions charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ tests:
- it: Verify nodes-workers requirements
documentIndex: 1
asserts:
# instance-category
- equal:
path: spec.template.spec.requirements[0].key
value: "karpenter.k8s.aws/instance-category"
- notContains:
path: spec.template.spec.requirements[0].values
content: m
Expand All @@ -57,47 +59,92 @@ tests:
- equal:
path: spec.template.spec.requirements[0].values[1]
value: x
# instance-cpu
- equal:
path: spec.template.spec.requirements[1].key
value: "karpenter.k8s.aws/instance-cpu"
- equal:
path: spec.template.spec.requirements[1].values[0]
value: "2"
- equal:
path: spec.template.spec.requirements[1].values[1]
value: "6"
# instance-generation
- equal:
path: spec.template.spec.requirements[2].key
value: "karpenter.k8s.aws/instance-generation"
- equal:
path: spec.template.spec.requirements[2].operator
value: "Gt"
- equal:
path: spec.template.spec.requirements[2].values[0]
value: "4"
# instance-zone
- equal:
path: spec.template.spec.requirements[3].key
value: "topology.kubernetes.io/zone"
- equal:
path: spec.template.spec.requirements[3].values[0]
value: "eu-west-1g"
# instance-architecture
- equal:
path: spec.template.spec.requirements[4].key
value: "kubernetes.io/arch"
- equal:
path: spec.template.spec.requirements[4].values[0]
value: "arm64"
# instance-capacity-type
- equal:
path: spec.template.spec.requirements[5].key
value: "karpenter.sh/capacity-type"
- equal:
path: spec.template.spec.requirements[5].values[0]
value: "on-demand"
# instance-OS
- equal:
path: spec.template.spec.requirements[6].key
value: "kubernetes.io/os"
- equal:
path: spec.template.spec.requirements[6].values[0]
value: "linux"
# instance-family Exclusions
- equal:
path: spec.template.spec.requirements[7].key
value: "karpenter.k8s.aws/instance-family"
- equal:
path: spec.template.spec.requirements[7].operator
value: "NotIn"
- equal:
path: spec.template.spec.requirements[7].values[0]
value: "m6a"
# instance-size Exclusiong
- equal:
path: spec.template.spec.requirements[8].key
value: "karpenter.k8s.aws/instance-size"
- equal:
path: spec.template.spec.requirements[8].operator
value: NotIn
- equal:
path: spec.template.spec.requirements[8].values[0]
value: metal
- equal:
path: spec.template.spec.requirements[9].key
value: "capacity-spread"
- equal:
path: spec.template.spec.requirements[9].values[0]
value: "1"
- equal:
path: spec.template.spec.requirements[9].values[4]
value: "5"
# additional requirements
- equal:
path: spec.template.spec.requirements[10].key
value: "karpenter.k8s.aws/instance-local-nvme"
- equal:
path: spec.template.spec.requirements[10].operator
value: "Exists"
- equal:
path: spec.template.spec.requirements[11].key
value: "karpenter.k8s.aws/other"
- equal:
path: spec.template.spec.requirements[11].operator
value: "In"
- equal:
path: spec.template.spec.requirements[11].values[1]
value: "value2"


- it: Verify nodes-workers kubelet
documentIndex: 1
Expand Down
12 changes: 9 additions & 3 deletions charts/karpenter_nodes/tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ nodeGroups:
headRoom:
- size: small
count: 2
antiAffinitySpec:
- key: testlabel1
operator: Exists
labels:
testlabel1: label1
testlabel2: label2
Expand Down Expand Up @@ -55,6 +52,15 @@ nodeGroups:
nameSpaces:
- default
- kube-system
additionalRequirements:
- key: "karpenter.k8s.aws/instance-local-nvme"
operator: "Exists"
- key: "karpenter.k8s.aws/other"
operator: "In"
values:
- "value1"
- "value2"


instances:
architecture: "arm64"
Expand Down
4 changes: 4 additions & 0 deletions charts/karpenter_nodes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ headRoom: true

# PlaceHolder fo NodeGroups
nodeGroups: {}

#additionalRequirements:

Check failure on line 139 in charts/karpenter_nodes/values.yaml

View workflow job for this annotation

GitHub Actions / lint-and-version-check-then-tests

139:2 [comments] missing starting space in comment
# - key: "karpenter.k8s.aws/instance-local-nvme"
# operator: "Exists"

0 comments on commit 8dcda1c

Please sign in to comment.