|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | + |
| 20 | +chart: |
| 21 | + version: 1.2.3 |
| 22 | + appVersion: 4.5.6 |
| 23 | + |
| 24 | +release: |
| 25 | + name: polaris-release |
| 26 | + namespace: polaris-ns |
| 27 | + |
| 28 | +templates: |
| 29 | + - poddisruptionbudget.yaml |
| 30 | + |
| 31 | +tests: |
| 32 | + |
| 33 | + # kind |
| 34 | + - it: should not create PDB by default |
| 35 | + asserts: |
| 36 | + - containsDocument: |
| 37 | + kind: PodDisruptionBudget |
| 38 | + apiVersion: policy/v1 |
| 39 | + not: true |
| 40 | + - it: should create PDB when enabled |
| 41 | + set: |
| 42 | + podDisruptionBudget.enabled: true |
| 43 | + asserts: |
| 44 | + - containsDocument: |
| 45 | + kind: PodDisruptionBudget |
| 46 | + apiVersion: policy/v1 |
| 47 | + |
| 48 | + # metadata.name (with PDB enabled) |
| 49 | + - it: should set PDB name |
| 50 | + set: |
| 51 | + podDisruptionBudget.enabled: true |
| 52 | + asserts: |
| 53 | + - equal: |
| 54 | + path: metadata.name |
| 55 | + value: polaris-release |
| 56 | + - it: should set PDB name with override |
| 57 | + set: |
| 58 | + podDisruptionBudget.enabled: true |
| 59 | + nameOverride: polaris-override |
| 60 | + asserts: |
| 61 | + - equal: |
| 62 | + path: metadata.name |
| 63 | + value: polaris-release-polaris-override |
| 64 | + - it: should set PDB name with full override |
| 65 | + set: |
| 66 | + podDisruptionBudget.enabled: true |
| 67 | + fullnameOverride: polaris-override |
| 68 | + asserts: |
| 69 | + - equal: |
| 70 | + path: metadata.name |
| 71 | + value: polaris-override |
| 72 | + |
| 73 | + # metadata.namespace (with PDB enabled) |
| 74 | + - it: should set PDB namespace |
| 75 | + set: |
| 76 | + podDisruptionBudget.enabled: true |
| 77 | + asserts: |
| 78 | + - equal: |
| 79 | + path: metadata.namespace |
| 80 | + value: polaris-ns |
| 81 | + |
| 82 | + # metadata.labels (with PDB enabled) |
| 83 | + - it: should set PDB default labels |
| 84 | + set: |
| 85 | + podDisruptionBudget.enabled: true |
| 86 | + asserts: |
| 87 | + - isSubset: |
| 88 | + path: metadata.labels |
| 89 | + content: |
| 90 | + app.kubernetes.io/name: polaris |
| 91 | + app.kubernetes.io/instance: polaris-release |
| 92 | + app.kubernetes.io/version: 4.5.6 |
| 93 | + app.kubernetes.io/managed-by: Helm |
| 94 | + helm.sh/chart: polaris-1.2.3 |
| 95 | + |
| 96 | + # metadata.annotations (with PDB enabled) |
| 97 | + - it: should not set annotations by default |
| 98 | + set: |
| 99 | + podDisruptionBudget.enabled: true |
| 100 | + asserts: |
| 101 | + - isNull: |
| 102 | + path: metadata.annotations |
| 103 | + - it: should set custom annotations |
| 104 | + set: |
| 105 | + podDisruptionBudget.enabled: true |
| 106 | + podDisruptionBudget.annotations: |
| 107 | + example.com/policy: "critical" |
| 108 | + kubernetes.io/description: "PDB for Polaris" |
| 109 | + asserts: |
| 110 | + - equal: |
| 111 | + path: metadata.annotations |
| 112 | + value: |
| 113 | + example.com/policy: "critical" |
| 114 | + kubernetes.io/description: "PDB for Polaris" |
| 115 | + - it: should template annotations |
| 116 | + set: |
| 117 | + podDisruptionBudget.enabled: true |
| 118 | + podDisruptionBudget.annotations: |
| 119 | + app.example.com/release: "{{ .Release.Name }}" |
| 120 | + asserts: |
| 121 | + - equal: |
| 122 | + path: metadata.annotations |
| 123 | + value: |
| 124 | + app.example.com/release: "polaris-release" |
| 125 | + |
| 126 | + - it: should set custom maxUnavailable |
| 127 | + set: |
| 128 | + podDisruptionBudget.enabled: true |
| 129 | + podDisruptionBudget.maxUnavailable: 2 |
| 130 | + asserts: |
| 131 | + - equal: |
| 132 | + path: spec.maxUnavailable |
| 133 | + value: 2 |
| 134 | + - isNull: |
| 135 | + path: spec.minAvailable |
| 136 | + - it: should set maxUnavailable percentage |
| 137 | + set: |
| 138 | + podDisruptionBudget.enabled: true |
| 139 | + podDisruptionBudget.maxUnavailable: "50%" |
| 140 | + asserts: |
| 141 | + - equal: |
| 142 | + path: spec.maxUnavailable |
| 143 | + value: "50%" |
| 144 | + - isNull: |
| 145 | + path: spec.minAvailable |
| 146 | + |
| 147 | + # spec.minAvailable |
| 148 | + - it: should set minAvailable and unset maxUnavailable |
| 149 | + set: |
| 150 | + podDisruptionBudget.enabled: true |
| 151 | + podDisruptionBudget.minAvailable: 2 |
| 152 | + podDisruptionBudget.maxUnavailable: null |
| 153 | + asserts: |
| 154 | + - equal: |
| 155 | + path: spec.minAvailable |
| 156 | + value: 2 |
| 157 | + - isNull: |
| 158 | + path: spec.maxUnavailable |
| 159 | + - it: should set minAvailable percentage |
| 160 | + set: |
| 161 | + podDisruptionBudget.enabled: true |
| 162 | + podDisruptionBudget.minAvailable: "75%" |
| 163 | + podDisruptionBudget.maxUnavailable: null |
| 164 | + asserts: |
| 165 | + - equal: |
| 166 | + path: spec.minAvailable |
| 167 | + value: "75%" |
| 168 | + - isNull: |
| 169 | + path: spec.maxUnavailable |
| 170 | + |
| 171 | + # spec.selector.matchLabels |
| 172 | + - it: should set selector labels to match deployment |
| 173 | + set: |
| 174 | + podDisruptionBudget.enabled: true |
| 175 | + asserts: |
| 176 | + - equal: |
| 177 | + path: spec.selector.matchLabels |
| 178 | + value: |
| 179 | + app.kubernetes.io/name: polaris |
| 180 | + app.kubernetes.io/instance: polaris-release |
| 181 | + - it: should set selector labels with name override |
| 182 | + set: |
| 183 | + podDisruptionBudget.enabled: true |
| 184 | + nameOverride: polaris-override |
| 185 | + asserts: |
| 186 | + - equal: |
| 187 | + path: spec.selector.matchLabels |
| 188 | + value: |
| 189 | + app.kubernetes.io/name: polaris-override |
| 190 | + app.kubernetes.io/instance: polaris-release |
| 191 | + - it: should set selector labels with full name override |
| 192 | + set: |
| 193 | + podDisruptionBudget.enabled: true |
| 194 | + fullnameOverride: polaris-override |
| 195 | + asserts: |
| 196 | + - equal: |
| 197 | + path: spec.selector.matchLabels |
| 198 | + value: |
| 199 | + app.kubernetes.io/name: polaris |
| 200 | + app.kubernetes.io/instance: polaris-release |
| 201 | + |
| 202 | + # validation tests |
| 203 | + - it: should fail when both minAvailable and maxUnavailable are set |
| 204 | + set: |
| 205 | + podDisruptionBudget.enabled: true |
| 206 | + podDisruptionBudget.minAvailable: 1 |
| 207 | + podDisruptionBudget.maxUnavailable: 1 |
| 208 | + asserts: |
| 209 | + - failedTemplate: |
| 210 | + errorMessage: "podDisruptionBudget.minAvailable and podDisruptionBudget.maxUnavailable cannot be both set." |
0 commit comments