|
| 1 | +# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +suite: "Postgres deployment" |
| 5 | +templates: |
| 6 | + - postgres.yaml |
| 7 | +release: |
| 8 | + # Set for testing labels |
| 9 | + name: test-postgres |
| 10 | + namespace: test-namespace |
| 11 | +chart: |
| 12 | + # Override for testing labels |
| 13 | + version: 0.1.1 |
| 14 | + appVersion: 0.1.0 |
| 15 | +set: |
| 16 | + persistence: |
| 17 | + secretName: postgres-secrets |
| 18 | + db: |
| 19 | + volumeSize: 100Gi |
| 20 | + volumeStorageClass: standard-rwo |
| 21 | + pvcTemplateName: pg-data |
| 22 | + maxConnections: 300 |
| 23 | + maxWalSize: 2GB |
| 24 | +tests: |
| 25 | + - it: "deploys a ConfigMap with correct environment variables" |
| 26 | + documentIndex: 0 |
| 27 | + documentSelector: |
| 28 | + path: kind |
| 29 | + value: ConfigMap |
| 30 | + asserts: |
| 31 | + - equal: |
| 32 | + path: metadata.name |
| 33 | + value: test-postgres-configuration |
| 34 | + - equal: |
| 35 | + path: metadata.namespace |
| 36 | + value: test-namespace |
| 37 | + - equal: |
| 38 | + path: data.PGDATA |
| 39 | + value: "/var/lib/postgresql/data/pgdata" |
| 40 | + - equal: |
| 41 | + path: data.POSTGRES_DB |
| 42 | + value: "cantonnet" |
| 43 | + - equal: |
| 44 | + path: data.POSTGRES_USER |
| 45 | + value: "cnadmin" |
| 46 | + |
| 47 | + - it: "deploys a StatefulSet with correct configuration" |
| 48 | + documentIndex: 1 |
| 49 | + documentSelector: |
| 50 | + path: kind |
| 51 | + value: StatefulSet |
| 52 | + asserts: |
| 53 | + - equal: |
| 54 | + path: metadata.name |
| 55 | + value: test-postgres |
| 56 | + - equal: |
| 57 | + path: metadata.namespace |
| 58 | + value: test-namespace |
| 59 | + - equal: |
| 60 | + path: spec.serviceName |
| 61 | + value: test-postgres |
| 62 | + - equal: |
| 63 | + path: spec.replicas |
| 64 | + value: 1 |
| 65 | + - equal: |
| 66 | + path: spec.selector.matchLabels.app |
| 67 | + value: test-postgres |
| 68 | + |
| 69 | + - it: "sets labels as expected" |
| 70 | + set: |
| 71 | + pod: |
| 72 | + labels: |
| 73 | + custom: label |
| 74 | + annotations: |
| 75 | + custom: annotation |
| 76 | + documentIndex: 1 |
| 77 | + documentSelector: |
| 78 | + path: kind |
| 79 | + value: StatefulSet |
| 80 | + asserts: |
| 81 | + - isSubset: |
| 82 | + path: metadata.labels |
| 83 | + content: |
| 84 | + app: test-postgres |
| 85 | + app.kubernetes.io/instance: test-postgres |
| 86 | + app.kubernetes.io/managed-by: Helm |
| 87 | + app.kubernetes.io/name: test-postgres |
| 88 | + app.kubernetes.io/version: "0.1.0" |
| 89 | + helm.sh/chart: splice-postgres-0.1.1 |
| 90 | + - isSubset: |
| 91 | + path: spec.template.metadata.labels |
| 92 | + content: |
| 93 | + app: test-postgres |
| 94 | + namespace: test-namespace |
| 95 | + custom: label |
| 96 | + - equal: |
| 97 | + path: spec.template.metadata.annotations.custom |
| 98 | + value: annotation |
| 99 | + |
| 100 | + - it: "configures container with default args" |
| 101 | + documentIndex: 1 |
| 102 | + documentSelector: |
| 103 | + path: kind |
| 104 | + value: StatefulSet |
| 105 | + asserts: |
| 106 | + - equal: |
| 107 | + path: spec.template.spec.containers[0].name |
| 108 | + value: test-postgres |
| 109 | + - equal: |
| 110 | + path: spec.template.spec.containers[0].image |
| 111 | + value: postgres:14 |
| 112 | + - equal: |
| 113 | + path: spec.template.spec.containers[0].imagePullPolicy |
| 114 | + value: IfNotPresent |
| 115 | + - contains: |
| 116 | + path: spec.template.spec.containers[0].args |
| 117 | + content: "-c" |
| 118 | + - contains: |
| 119 | + path: spec.template.spec.containers[0].args |
| 120 | + content: "max_connections=300" |
| 121 | + - contains: |
| 122 | + path: spec.template.spec.containers[0].args |
| 123 | + content: "max_wal_size=2GB" |
| 124 | + |
| 125 | + - it: "configures container with extraArgs" |
| 126 | + set: |
| 127 | + extraArgs: |
| 128 | + - "-c" |
| 129 | + - "shared_buffers=256MB" |
| 130 | + - "-c" |
| 131 | + - "work_mem=16MB" |
| 132 | + documentIndex: 1 |
| 133 | + documentSelector: |
| 134 | + path: kind |
| 135 | + value: StatefulSet |
| 136 | + asserts: |
| 137 | + - contains: |
| 138 | + path: spec.template.spec.containers[0].args |
| 139 | + content: "-c" |
| 140 | + - contains: |
| 141 | + path: spec.template.spec.containers[0].args |
| 142 | + content: "max_connections=300" |
| 143 | + - contains: |
| 144 | + path: spec.template.spec.containers[0].args |
| 145 | + content: "shared_buffers=256MB" |
| 146 | + - contains: |
| 147 | + path: spec.template.spec.containers[0].args |
| 148 | + content: "work_mem=16MB" |
| 149 | + |
| 150 | + - it: "configures environment variables correctly" |
| 151 | + documentIndex: 1 |
| 152 | + documentSelector: |
| 153 | + path: kind |
| 154 | + value: StatefulSet |
| 155 | + asserts: |
| 156 | + - equal: |
| 157 | + path: spec.template.spec.containers[0].env[0].name |
| 158 | + value: POSTGRES_PASSWORD |
| 159 | + - equal: |
| 160 | + path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name |
| 161 | + value: postgres-secrets |
| 162 | + - equal: |
| 163 | + path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.key |
| 164 | + value: postgresPassword |
| 165 | + - equal: |
| 166 | + path: spec.template.spec.containers[0].envFrom[0].configMapRef.name |
| 167 | + value: test-postgres-configuration |
| 168 | + |
| 169 | + - it: "configures liveness probe" |
| 170 | + documentIndex: 1 |
| 171 | + documentSelector: |
| 172 | + path: kind |
| 173 | + value: StatefulSet |
| 174 | + asserts: |
| 175 | + - equal: |
| 176 | + path: spec.template.spec.containers[0].livenessProbe.exec.command |
| 177 | + value: |
| 178 | + - psql |
| 179 | + - -U |
| 180 | + - cnadmin |
| 181 | + - -d |
| 182 | + - template1 |
| 183 | + - -c |
| 184 | + - SELECT 1 |
| 185 | + - equal: |
| 186 | + path: spec.template.spec.containers[0].livenessProbe.failureThreshold |
| 187 | + value: 3 |
| 188 | + - equal: |
| 189 | + path: spec.template.spec.containers[0].livenessProbe.periodSeconds |
| 190 | + value: 10 |
| 191 | + |
| 192 | + - it: "configures port correctly" |
| 193 | + documentIndex: 1 |
| 194 | + documentSelector: |
| 195 | + path: kind |
| 196 | + value: StatefulSet |
| 197 | + asserts: |
| 198 | + - equal: |
| 199 | + path: spec.template.spec.containers[0].ports[0].containerPort |
| 200 | + value: 5432 |
| 201 | + - equal: |
| 202 | + path: spec.template.spec.containers[0].ports[0].name |
| 203 | + value: postgresdb |
| 204 | + - equal: |
| 205 | + path: spec.template.spec.containers[0].ports[0].protocol |
| 206 | + value: TCP |
| 207 | + |
| 208 | + - it: "configures resources when provided" |
| 209 | + set: |
| 210 | + resources: |
| 211 | + limits: |
| 212 | + memory: 12Gi |
| 213 | + requests: |
| 214 | + cpu: "0.5" |
| 215 | + memory: 1Gi |
| 216 | + documentIndex: 1 |
| 217 | + documentSelector: |
| 218 | + path: kind |
| 219 | + value: StatefulSet |
| 220 | + asserts: |
| 221 | + - equal: |
| 222 | + path: spec.template.spec.containers[0].resources.limits.memory |
| 223 | + value: 12Gi |
| 224 | + - equal: |
| 225 | + path: spec.template.spec.containers[0].resources.requests.cpu |
| 226 | + value: "0.5" |
| 227 | + - equal: |
| 228 | + path: spec.template.spec.containers[0].resources.requests.memory |
| 229 | + value: 1Gi |
| 230 | + |
| 231 | + - it: "configures volume mounts" |
| 232 | + documentIndex: 1 |
| 233 | + documentSelector: |
| 234 | + path: kind |
| 235 | + value: StatefulSet |
| 236 | + asserts: |
| 237 | + - equal: |
| 238 | + path: spec.template.spec.containers[0].volumeMounts[0].mountPath |
| 239 | + value: /var/lib/postgresql/data |
| 240 | + - equal: |
| 241 | + path: spec.template.spec.containers[0].volumeMounts[0].name |
| 242 | + value: pg-data |
| 243 | + |
| 244 | + - it: "configures nodeSelector when provided" |
| 245 | + set: |
| 246 | + nodeSelector: |
| 247 | + disktype: ssd |
| 248 | + documentIndex: 1 |
| 249 | + documentSelector: |
| 250 | + path: kind |
| 251 | + value: StatefulSet |
| 252 | + asserts: |
| 253 | + - equal: |
| 254 | + path: spec.template.spec.nodeSelector.disktype |
| 255 | + value: ssd |
| 256 | + |
| 257 | + - it: "configures affinity when provided" |
| 258 | + set: |
| 259 | + affinity: |
| 260 | + nodeAffinity: |
| 261 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 262 | + nodeSelectorTerms: |
| 263 | + - matchExpressions: |
| 264 | + - key: topology.kubernetes.io/zone |
| 265 | + operator: In |
| 266 | + values: |
| 267 | + - us-west-2a |
| 268 | + documentIndex: 1 |
| 269 | + documentSelector: |
| 270 | + path: kind |
| 271 | + value: StatefulSet |
| 272 | + asserts: |
| 273 | + - isNotNull: |
| 274 | + path: spec.template.spec.affinity |
| 275 | + - equal: |
| 276 | + path: spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key |
| 277 | + value: topology.kubernetes.io/zone |
| 278 | + |
| 279 | + - it: "configures tolerations when provided" |
| 280 | + set: |
| 281 | + tolerations: |
| 282 | + - key: "dedicated" |
| 283 | + operator: "Equal" |
| 284 | + value: "postgres" |
| 285 | + effect: "NoSchedule" |
| 286 | + documentIndex: 1 |
| 287 | + documentSelector: |
| 288 | + path: kind |
| 289 | + value: StatefulSet |
| 290 | + asserts: |
| 291 | + - equal: |
| 292 | + path: spec.template.spec.tolerations[0].key |
| 293 | + value: dedicated |
| 294 | + - equal: |
| 295 | + path: spec.template.spec.tolerations[0].value |
| 296 | + value: postgres |
| 297 | + |
| 298 | + - it: "configures volumeClaimTemplates correctly" |
| 299 | + documentIndex: 1 |
| 300 | + documentSelector: |
| 301 | + path: kind |
| 302 | + value: StatefulSet |
| 303 | + asserts: |
| 304 | + - equal: |
| 305 | + path: spec.volumeClaimTemplates[0].metadata.name |
| 306 | + value: pg-data |
| 307 | + - equal: |
| 308 | + path: spec.volumeClaimTemplates[0].spec.accessModes[0] |
| 309 | + value: ReadWriteOnce |
| 310 | + - equal: |
| 311 | + path: spec.volumeClaimTemplates[0].spec.resources.requests.storage |
| 312 | + value: 100Gi |
| 313 | + - equal: |
| 314 | + path: spec.volumeClaimTemplates[0].spec.storageClassName |
| 315 | + value: standard-rwo |
| 316 | + - equal: |
| 317 | + path: spec.volumeClaimTemplates[0].spec.volumeMode |
| 318 | + value: Filesystem |
| 319 | + |
| 320 | + - it: "deploys a Service with correct configuration" |
| 321 | + documentIndex: 2 |
| 322 | + documentSelector: |
| 323 | + path: kind |
| 324 | + value: Service |
| 325 | + asserts: |
| 326 | + - equal: |
| 327 | + path: metadata.name |
| 328 | + value: test-postgres |
| 329 | + - equal: |
| 330 | + path: metadata.namespace |
| 331 | + value: test-namespace |
| 332 | + - equal: |
| 333 | + path: spec.ports[0].name |
| 334 | + value: postgresdb |
| 335 | + - equal: |
| 336 | + path: spec.ports[0].port |
| 337 | + value: 5432 |
| 338 | + - equal: |
| 339 | + path: spec.ports[0].protocol |
| 340 | + value: TCP |
| 341 | + - equal: |
| 342 | + path: spec.selector.app |
| 343 | + value: test-postgres |
0 commit comments