From 4fbb7f9a24c5712e16bc7a4b0b4ffa433979f66d Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 25 Mar 2024 02:43:06 +0200 Subject: [PATCH] fix(resources): do not render zero-ed extra resources --- library/common-test/tests/container/resources_test.yaml | 3 +-- library/common/Chart.yaml | 2 +- library/common/templates/lib/container/_resources.tpl | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/common-test/tests/container/resources_test.yaml b/library/common-test/tests/container/resources_test.yaml index 404684ab..8c237c36 100644 --- a/library/common-test/tests/container/resources_test.yaml +++ b/library/common-test/tests/container/resources_test.yaml @@ -70,6 +70,7 @@ tests: nvidia.com/gpu: 1 some-resource: 1 some-other-resource: 0 + some-string-resource: "0" asserts: - documentIndex: &deploymentDoc 0 isKind: @@ -87,7 +88,6 @@ tests: memory: 4Gi nvidia.com/gpu: 1 some-resource: 1 - some-other-resource: 0 requests: cpu: 10m memory: 50Mi @@ -132,7 +132,6 @@ tests: limits: cpu: 2000m memory: 4Gi - some-resource: 0 some-other-resource: 2 requests: cpu: 10m diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index dd0b6c5f..249d20ea 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 20.2.4 +version: 20.2.5 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/lib/container/_resources.tpl b/library/common/templates/lib/container/_resources.tpl index b442ef16..7f802062 100644 --- a/library/common/templates/lib/container/_resources.tpl +++ b/library/common/templates/lib/container/_resources.tpl @@ -37,6 +37,9 @@ limits: {{- end -}} {{- if not $objectData.resources.excludeExtra -}} {{- range $k, $v := (omit $resources.limits "cpu" "memory") }} {{/* Omit cpu and memory, as they are handled above */}} + {{- if or (not $v) (eq (toString $v) "0") -}} + {{ continue }} + {{- end }} {{ $k }}: {{ $v }} {{- end -}} {{- end -}}