From 491d490e18fa6bb173cb4793028d0d5af40cb33e Mon Sep 17 00:00:00 2001 From: nadavbuc Date: Mon, 15 Apr 2024 11:35:29 +0300 Subject: [PATCH] cover all in tests --- .../karpenter_nodes/templates/nodepool.yaml | 2 +- .../tests/nodepool_nodes_default_test.yaml | 1 - .../tests/nodepool_nodes_noclass_test.yaml | 88 +++++++++++++++++++ .../tests/nodepool_nodes_workers_test.yaml | 9 +- charts/karpenter_nodes/tests/values.yaml | 6 +- 5 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 charts/karpenter_nodes/tests/nodepool_nodes_noclass_test.yaml diff --git a/charts/karpenter_nodes/templates/nodepool.yaml b/charts/karpenter_nodes/templates/nodepool.yaml index d982497..4214e89 100644 --- a/charts/karpenter_nodes/templates/nodepool.yaml +++ b/charts/karpenter_nodes/templates/nodepool.yaml @@ -24,7 +24,7 @@ spec: spec: nodeClassRef: {{- if hasKey $v "nodeClassRef" }} - {{ $v.nodeClassRef | toYaml | nindent 8 }} + {{- $v.nodeClassRef | toYaml | nindent 8 }} {{- else }} name: {{ $k }}-{{ $v.instances.architecture | default $.Values.instances.architecture }} {{- end }} diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml index 5431804..bdf270b 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_default_test.yaml @@ -1,7 +1,6 @@ suite: test nodepool - nodes-default templates: - nodepool.yaml - values: - values.yaml diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_noclass_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_noclass_test.yaml new file mode 100644 index 0000000..b432124 --- /dev/null +++ b/charts/karpenter_nodes/tests/nodepool_nodes_noclass_test.yaml @@ -0,0 +1,88 @@ +suite: test nodepool - nodes-noclass +templates: + - nodepool.yaml +values: + - values.yaml + +tests: + - it: Verify nodes-noclass metadata + documentIndex: 1 + asserts: + - isKind: + of: NodePool + - equal: + path: metadata.name + value: nodes-noclass-amd64 + - equal: + path: spec.template.metadata.labels.cluster + value: eks-dev + - equal: + path: spec.template.metadata.labels.nodegroup + value: nodes-noclass + - equal: + path: spec.template.spec.nodeClassRef.name + value: default + + - it: Verify nodes-noclass requirements + documentIndex: 1 + asserts: + - equal: + path: spec.template.spec.requirements[0].key + value: "karpenter.k8s.aws/instance-category" + - notContains: + path: spec.template.spec.requirements[0].values + content: t + - equal: + path: spec.template.spec.requirements[0].values[0] + value: m + - equal: + path: spec.template.spec.requirements[0].values[2] + value: c + - 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" + - 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" + - 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" + - equal: + path: spec.template.spec.requirements[4].key + value: "kubernetes.io/arch" + - equal: + path: spec.template.spec.requirements[4].values[0] + value: "amd64" + - 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" + - equal: + path: spec.template.spec.requirements[6].key + value: "kubernetes.io/os" + - equal: + path: spec.template.spec.requirements[6].values[0] + value: "linux" diff --git a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml index a10abc0..9ae4919 100644 --- a/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml +++ b/charts/karpenter_nodes/tests/nodepool_nodes_workers_test.yaml @@ -1,13 +1,12 @@ suite: test nodepool - nodes-workers templates: - nodepool.yaml - values: - values.yaml tests: - it: Verify nodes-workers metadata - documentIndex: 1 + documentIndex: 2 asserts: - isKind: of: NodePool @@ -51,7 +50,7 @@ tests: value: noSchedule - it: Verify nodes-workers requirements - documentIndex: 1 + documentIndex: 2 asserts: - equal: path: spec.template.spec.requirements[0].key @@ -153,7 +152,7 @@ tests: - it: Verify nodes-workers kubelet - documentIndex: 1 + documentIndex: 2 asserts: - equal: path: spec.template.spec.kubelet.systemReserved.cpu @@ -169,7 +168,7 @@ tests: value: "2.2.2.2" - it: Verify nodes-workers Options - documentIndex: 1 + documentIndex: 2 asserts: - equal: path: spec.disruption.expireAfter diff --git a/charts/karpenter_nodes/tests/values.yaml b/charts/karpenter_nodes/tests/values.yaml index c59c6f3..d1273dc 100644 --- a/charts/karpenter_nodes/tests/values.yaml +++ b/charts/karpenter_nodes/tests/values.yaml @@ -21,6 +21,11 @@ nodeGroups: excludeFamilies: - c6a + nodes-noclass: + instances: {} + nodeClassRef: + name: default + nodes-workers: additionalNodeTags: testtag1: tag1 @@ -76,7 +81,6 @@ nodeGroups: environment: test - name: my-ami - id: ami-123 - instances: architecture: "arm64" minGeneration: 5