Skip to content

Commit

Permalink
cover everything in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavbuc committed Apr 15, 2024
1 parent 29794da commit d2d48f0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion charts/karpenter_nodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Note - Most of the values can be overridden per nodegroup (If not specified, it
| `securityGroupSelectorTerms` | Selector for Security Groups [Documentation](https://karpenter.sh/docs/concepts/nodeclasses/#specsecuritygroupselectorterms) | `List(Map)` | x ||
| `nodeGroupLabelName` | The Name of the label for each nodegroup (default is `nodegroup`) | `String` | x ||
| `nodeTags` | Tags to add to the instances `<tag_name>`: `<tag_value>` | `Map` |||
| `additionalNodeTags` | Additional Tags to add to the instances `<tag_name>`: `<tag_value>` | `Map` |||
| `nodegroups.{}` | each will be used to setup a provisioner and template based on the nodegrup name key | `List[Maps]` | x ||
| `blockDeviceMappings` | Block Device Mappings [Documentation](https://karpenter.sh/docs/concepts/nodeclasses/#specblockdevicemappings) | `List(Map)` | x ||
| `detailedMonitoring` | Detailed Monitoring [Documentation](https://karpenter.sh/docs/concepts/nodeclasses/#specdetailedmonitoring) | `Boolean` | x ||
Expand Down Expand Up @@ -78,6 +77,7 @@ Note - Most of the values can be overridden per nodegroup (If not specified, it
| Key Name | Description | Type | Optional? | Optional Per NodeGroup? |
| ------------------------------ | ----------- | ---- | --------- | ----------------------- |
| `nodegroups.{}.labels` | Labels to add to nodes `<label_name>`: `<label_value>` | `Map` |||
| `nodegroups.{}.additionalNodeTags` | Additional Tags to add to the instances `<tag_name>`: `<tag_value>` | `Map` |||
| `nodegroups.{}.annotations` | Annotations to add to nodes `<annotation_name>`: `<annotation_value>` | `Map` |||
| `nodegroups.{}.nodeClassRef` | If you wish to use your own nodeClass, specify it [Documentation](https://karpenter.sh/docs/concepts/nodeclasses/) | `Map` |||
| `nodegroups.{}.taints` | Taints to add to nodes `- <taint_key>`: `<taint_value>`: `<taint_effect>` | `List(Map)` |||
Expand Down
2 changes: 2 additions & 0 deletions charts/karpenter_nodes/templates/nodeclass.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- range $k, $v := $.Values.nodeGroups }}
{{- $_ := set $ "key" $k }}
{{- $_ := set $ "value" $v }}
{{- if not (hasKey $v "nodeClassRef") }}
---
apiVersion: karpenter.k8s.aws/{{ $.Values.ApiVersion }}
kind: EC2NodeClass
Expand Down Expand Up @@ -72,3 +73,4 @@ spec:
{{- end }}
{{- end}}
{{- end }}
{{- end }}
20 changes: 19 additions & 1 deletion charts/karpenter_nodes/tests/nodeclass_test.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
suite: test nodeclasses
templates:
- nodeclass.yaml

values:
- values.yaml
tests:
- it: should only render 2 nodeclasses
asserts:
- hasDocuments:
count: 2
- it: Verify nodes-default
documentIndex: 0
asserts:
Expand Down Expand Up @@ -80,6 +83,15 @@ tests:
- equal:
path: spec.amiFamily
value: BottleRocket
- equal:
path: spec.amiSelectorTerms[0].tags.environment
value: test
- equal:
path: spec.amiSelectorTerms[1].name
value: my-ami
- equal:
path: spec.amiSelectorTerms[2].id
value: ami-123
- equal:
path: spec.subnetSelectorTerms[0].tags.Name
value: eks-subnet-workers-1
Expand All @@ -95,6 +107,12 @@ tests:
- equal:
path: spec.tags.cluster
value: eks-dev
- equal:
path: spec.tags.testtag1
value: tag1
- equal:
path: spec.tags.testtag2
value: tag2
- equal:
path: spec.blockDeviceMappings[0].deviceName
value: /dev/xvda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ tests:
path: spec.disruption.consolidateAfter
value: 5m
- isNull:
path: spec.budgets
path: spec.disruption.budgets
- isNull:
path: spec.limits
- equal:
Expand Down
20 changes: 18 additions & 2 deletions charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ tests:
value: nodes-workers
- isNull:
path: spec.template.metadata.labels.testlabel1
- equal:
path: spec.template.metadata.annotations.testannotation1
value: annotation1
- equal:
path: spec.template.metadata.annotations.testannotation2
value: annotation2
- equal:
path: spec.template.spec.nodeClassRef.name
value: nodes-workers-arm64
Expand Down Expand Up @@ -174,8 +180,18 @@ tests:
- equal:
path: spec.disruption.consolidateAfter
value: 10m
- isNull:
path: spec.budgets
- equal:
path: spec.disruption.budgets[0].nodes
value: "5"
- equal:
path: spec.disruption.budgets[1].nodes
value: "0"
- equal:
path: spec.disruption.budgets[1].schedule
value: "@daily"
- equal:
path: spec.disruption.budgets[1].duration
value: "10m"
- equal:
path: spec.limits.cpu
value: 100
Expand Down
17 changes: 16 additions & 1 deletion charts/karpenter_nodes/tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ nodeGroups:
- c6a

nodes-workers:
additionalNodeTags:
testtag1: tag1
testtag2: tag2
annotations:
testannotation1: annotation1
testannotation2: annotation2
weight: 3
amiFamily: BottleRocket
consolidationPolicy: "WhenEmpty"
Expand Down Expand Up @@ -60,7 +66,16 @@ nodeGroups:
values:
- "value1"
- "value2"

budgets:
- nodes: "5"
- nodes: "0"
schedule: "@daily"
duration: 10m
amiSelectorTerms:
- tags:
environment: test
- name: my-ami
- id: ami-123

instances:
architecture: "arm64"
Expand Down

0 comments on commit d2d48f0

Please sign in to comment.