From d2d48f068509ec78900619544405059e427bfa87 Mon Sep 17 00:00:00 2001 From: nadavbuc Date: Mon, 15 Apr 2024 11:14:31 +0300 Subject: [PATCH] cover everything in tests --- charts/karpenter_nodes/README.md | 2 +- .../karpenter_nodes/templates/nodeclass.yaml | 2 ++ .../karpenter_nodes/tests/nodeclass_test.yaml | 20 ++++++++++++++++++- .../tests/nodepool_nodes_default_test.yaml | 2 +- .../tests/nodepool_nodes_workers_test.yaml | 20 +++++++++++++++++-- charts/karpenter_nodes/tests/values.yaml | 17 +++++++++++++++- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/charts/karpenter_nodes/README.md b/charts/karpenter_nodes/README.md index c37eaba..1717e84 100644 --- a/charts/karpenter_nodes/README.md +++ b/charts/karpenter_nodes/README.md @@ -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 ``: `` | `Map` | ✓ | ✓ | -| `additionalNodeTags` | Additional Tags to add to the instances ``: `` | `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 | ✓ | @@ -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 ``: `` | `Map` | ✓ | ✓ | +| `nodegroups.{}.additionalNodeTags` | Additional Tags to add to the instances ``: `` | `Map` | ✓ | ✓ | | `nodegroups.{}.annotations` | Annotations to add to nodes ``: `` | `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 `- `: ``: `` | `List(Map)` | ✓ | ✓ | diff --git a/charts/karpenter_nodes/templates/nodeclass.yaml b/charts/karpenter_nodes/templates/nodeclass.yaml index 6191a28..fd02ddd 100644 --- a/charts/karpenter_nodes/templates/nodeclass.yaml +++ b/charts/karpenter_nodes/templates/nodeclass.yaml @@ -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 @@ -72,3 +73,4 @@ spec: {{- end }} {{- end}} {{- end }} +{{- end }} diff --git a/charts/karpenter_nodes/tests/nodeclass_test.yaml b/charts/karpenter_nodes/tests/nodeclass_test.yaml index 393de8c..3c0a0e9 100644 --- a/charts/karpenter_nodes/tests/nodeclass_test.yaml +++ b/charts/karpenter_nodes/tests/nodeclass_test.yaml @@ -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: @@ -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 @@ -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 diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml index ed10bd7..5431804 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml @@ -151,7 +151,7 @@ tests: path: spec.disruption.consolidateAfter value: 5m - isNull: - path: spec.budgets + path: spec.disruption.budgets - isNull: path: spec.limits - equal: diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml index e72dc00..a10abc0 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml @@ -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 @@ -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 diff --git a/charts/karpenter_nodes/tests/values.yaml b/charts/karpenter_nodes/tests/values.yaml index 601c58d..c59c6f3 100644 --- a/charts/karpenter_nodes/tests/values.yaml +++ b/charts/karpenter_nodes/tests/values.yaml @@ -22,6 +22,12 @@ nodeGroups: - c6a nodes-workers: + additionalNodeTags: + testtag1: tag1 + testtag2: tag2 + annotations: + testannotation1: annotation1 + testannotation2: annotation2 weight: 3 amiFamily: BottleRocket consolidationPolicy: "WhenEmpty" @@ -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"