diff --git a/library/common-test/tests/podDisruptionBudget/spec_test.yaml b/library/common-test/tests/podDisruptionBudget/spec_test.yaml index ac81f013..f8942967 100644 --- a/library/common-test/tests/podDisruptionBudget/spec_test.yaml +++ b/library/common-test/tests/podDisruptionBudget/spec_test.yaml @@ -5,7 +5,7 @@ release: name: test-release-name namespace: test-release-namespace tests: - - it: should pass with zero in keys + - it: should pass with zero in keys (minAvailable) set: podDisruptionBudget: my-pdb1: @@ -13,7 +13,6 @@ tests: customLabels: label1: value1 minAvailable: 0 - maxUnavailable: 0 asserts: - documentIndex: &pdbDoc 0 isKind: @@ -23,12 +22,28 @@ tests: path: spec content: minAvailable: 0 + + - it: should pass with zero in keys (maxUnavailable) + set: + podDisruptionBudget: + my-pdb1: + enabled: true + customLabels: + label1: value1 + maxUnavailable: 0 + asserts: + - documentIndex: &pdbDoc 0 + isKind: + of: PodDisruptionBudget + - documentIndex: *pdbDoc + isSubset: + path: spec + content: maxUnavailable: 0 - - it: should pass keys from tpl + - it: should pass keys from tpl (minAvailable) set: k1: 0 - k2: 0 k3: AlwaysAllow podDisruptionBudget: my-pdb1: @@ -36,7 +51,6 @@ tests: customLabels: label1: value1 minAvailable: "{{ .Values.k1 }}" - maxUnavailable: "{{ .Values.k2 }}" unhealthyPodEvictionPolicy: "{{ .Values.k3 }}" asserts: - documentIndex: *pdbDoc @@ -44,9 +58,24 @@ tests: path: spec content: minAvailable: 0 - maxUnavailable: 0 unhealthyPodEvictionPolicy: AlwaysAllow + - it: should pass keys from tpl (maxUnavailable) + set: + k2: 0 + podDisruptionBudget: + my-pdb1: + enabled: true + customLabels: + label1: value1 + maxUnavailable: "{{ .Values.k2 }}" + asserts: + - documentIndex: *pdbDoc + isSubset: + path: spec + content: + maxUnavailable: 0 + - it: should pass with percentage in keys set: percentage: 50% @@ -55,14 +84,12 @@ tests: enabled: true customLabels: label1: value1 - minAvailable: 50% maxUnavailable: "{{ .Values.percentage }}" asserts: - documentIndex: *pdbDoc isSubset: path: spec content: - minAvailable: 50% maxUnavailable: 50% - it: should pass with minAvailable defined diff --git a/library/common-test/tests/podDisruptionBudget/validation_test.yaml b/library/common-test/tests/podDisruptionBudget/validation_test.yaml index 22278f89..c1c74bdc 100644 --- a/library/common-test/tests/podDisruptionBudget/validation_test.yaml +++ b/library/common-test/tests/podDisruptionBudget/validation_test.yaml @@ -8,8 +8,8 @@ tests: - it: should fail with name longer than 63 characters set: podDisruptionBudget: - my-poddisruptionbudget-super-long-name-that-is-longer-than-63-characters: - enabled: true + ? my-poddisruptionbudget-super-long-name-that-is-longer-than-63-characters + : enabled: true asserts: - failedTemplate: errorMessage: Name [test-release-name-common-test-my-poddisruptionbudget-super-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters. @@ -153,3 +153,15 @@ tests: asserts: - failedTemplate: errorMessage: Pod Disruption Budget - Selected pod [my-pod] is not defined + + - it: should fail with both minAvailable and maxUnavailable + set: + podDisruptionBudget: + my-poddisruptionbudget: + enabled: true + targetSelector: my-pod + minAvailable: 1 + maxUnavailable: 1 + asserts: + - failedTemplate: + errorMessage: Pod Disruption Budget - Expected one of [minAvailable, maxUnavailable] to be defined in [podDisruptionBudget.my-poddisruptionbudget], but got both diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index ad498a21..10943df4 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 24.1.3 +version: 24.1.4 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/lib/podDistruptionBudget/_validation.tpl b/library/common/templates/lib/podDistruptionBudget/_validation.tpl index 8b5e0794..b92fc57e 100644 --- a/library/common/templates/lib/podDistruptionBudget/_validation.tpl +++ b/library/common/templates/lib/podDistruptionBudget/_validation.tpl @@ -41,6 +41,10 @@ objectData: {{- end -}} {{- end -}} + {{- if and ($objectData.minAvailable) ($objectData.maxUnavailable) -}} + {{- fail (printf "Pod Disruption Budget - Expected one of [%s] to be defined in [podDisruptionBudget.%s], but got both" (join ", " $keys) $objectData.shortName) -}} + {{- end -}} + {{- if not $hasKey -}} {{- fail (printf "Pod Disruption Budget - Expected at least one of [%s] to be defined in [podDisruptionBudget.%s]" (join ", " $keys) $objectData.shortName) -}} {{- end -}}