|
| 1 | +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json |
| 2 | +apiVersion: chainsaw.kyverno.io/v1alpha1 |
| 3 | +kind: Test |
| 4 | +metadata: |
| 5 | + name: default-autogrow |
| 6 | +spec: |
| 7 | + description: | |
| 8 | + Create a cluster with the default autogrow settings. |
| 9 | + Check that the trigger is hit when expected and |
| 10 | + that volumes are expanded by 50%. |
| 11 | + Since default trigger is 75%, we write 750Mi to each 1Gi volume. |
| 12 | + With GKE storage we expect the PVC request to be increased to 1461Mi |
| 13 | + timeouts: |
| 14 | + assert: 90s |
| 15 | + exec: 15s |
| 16 | + bindings: |
| 17 | + - name: cluster |
| 18 | + value: |
| 19 | + name: default-trigger |
| 20 | + - name: postgres |
| 21 | + value: |
| 22 | + version: ($values.versions.postgres) |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check that volume expansion is enabled on the default storage class |
| 26 | + try: |
| 27 | + - assert: |
| 28 | + resource: |
| 29 | + apiVersion: storage.k8s.io/v1 |
| 30 | + kind: StorageClass |
| 31 | + metadata: |
| 32 | + annotations: |
| 33 | + storageclass.kubernetes.io/is-default-class: "true" |
| 34 | + allowVolumeExpansion: true |
| 35 | + |
| 36 | + - name: Create cluster with default autogrow settings |
| 37 | + try: |
| 38 | + - apply: |
| 39 | + resource: |
| 40 | + apiVersion: postgres-operator.crunchydata.com/v1beta1 |
| 41 | + kind: PostgresCluster |
| 42 | + metadata: |
| 43 | + name: ($cluster.name) |
| 44 | + spec: |
| 45 | + postgresVersion: (to_number($postgres.version)) |
| 46 | + instances: |
| 47 | + - name: instance1 |
| 48 | + dataVolumeClaimSpec: |
| 49 | + accessModes: [ ReadWriteOnce ] |
| 50 | + resources: |
| 51 | + requests: { storage: 1Gi } |
| 52 | + limits: { storage: 5Gi } |
| 53 | + walVolumeClaimSpec: |
| 54 | + accessModes: [ ReadWriteOnce ] |
| 55 | + resources: |
| 56 | + requests: { storage: 1Gi } |
| 57 | + limits: { storage: 5Gi } |
| 58 | + backups: |
| 59 | + pgbackrest: |
| 60 | + repos: |
| 61 | + - name: repo1 |
| 62 | + volume: |
| 63 | + volumeClaimSpec: |
| 64 | + accessModes: [ ReadWriteOnce ] |
| 65 | + resources: |
| 66 | + requests: { storage: 1Gi } |
| 67 | + limits: { storage: 5Gi } |
| 68 | + - name: repo2 |
| 69 | + volume: |
| 70 | + volumeClaimSpec: |
| 71 | + accessModes: [ ReadWriteOnce ] |
| 72 | + resources: |
| 73 | + requests: { storage: 1Gi } |
| 74 | + limits: { storage: 5Gi } |
| 75 | + - assert: |
| 76 | + # Allow more time for cluster to start and initial backup to complete |
| 77 | + timeout: 300s |
| 78 | + resource: |
| 79 | + apiVersion: postgres-operator.crunchydata.com/v1beta1 |
| 80 | + kind: PostgresCluster |
| 81 | + metadata: |
| 82 | + name: ($cluster.name) |
| 83 | + status: |
| 84 | + instances: |
| 85 | + - name: instance1 |
| 86 | + readyReplicas: 1 |
| 87 | + replicas: 1 |
| 88 | + updatedReplicas: 1 |
| 89 | + pgbackrest: |
| 90 | + repoHost: |
| 91 | + apiVersion: apps/v1 |
| 92 | + kind: StatefulSet |
| 93 | + ready: true |
| 94 | + repos: |
| 95 | + - bound: true |
| 96 | + name: repo1 |
| 97 | + replicaCreateBackupComplete: true |
| 98 | + stanzaCreated: true |
| 99 | + - bound: true |
| 100 | + name: repo2 |
| 101 | + stanzaCreated: true |
| 102 | + - assert: |
| 103 | + resource: |
| 104 | + apiVersion: v1 |
| 105 | + kind: PersistentVolumeClaim |
| 106 | + metadata: |
| 107 | + labels: |
| 108 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 109 | + postgres-operator.crunchydata.com/instance-set: instance1 |
| 110 | + postgres-operator.crunchydata.com/role: pgdata |
| 111 | + spec: |
| 112 | + resources: |
| 113 | + requests: { storage: 1Gi } |
| 114 | + status: |
| 115 | + accessModes: [ ReadWriteOnce ] |
| 116 | + capacity: { storage: 1Gi } |
| 117 | + phase: Bound |
| 118 | + - assert: |
| 119 | + resource: |
| 120 | + apiVersion: v1 |
| 121 | + kind: PersistentVolumeClaim |
| 122 | + metadata: |
| 123 | + labels: |
| 124 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 125 | + postgres-operator.crunchydata.com/instance-set: instance1 |
| 126 | + postgres-operator.crunchydata.com/role: pgwal |
| 127 | + spec: |
| 128 | + resources: |
| 129 | + requests: { storage: 1Gi } |
| 130 | + status: |
| 131 | + accessModes: [ ReadWriteOnce ] |
| 132 | + capacity: { storage: 1Gi } |
| 133 | + phase: Bound |
| 134 | + - assert: |
| 135 | + resource: |
| 136 | + apiVersion: v1 |
| 137 | + kind: PersistentVolumeClaim |
| 138 | + metadata: |
| 139 | + labels: |
| 140 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 141 | + postgres-operator.crunchydata.com/data: pgbackrest |
| 142 | + postgres-operator.crunchydata.com/pgbackrest: "" |
| 143 | + postgres-operator.crunchydata.com/pgbackrest-repo: repo1 |
| 144 | + postgres-operator.crunchydata.com/pgbackrest-volume: "" |
| 145 | + spec: |
| 146 | + resources: |
| 147 | + requests: { storage: 1Gi } |
| 148 | + status: |
| 149 | + accessModes: [ ReadWriteOnce ] |
| 150 | + capacity: { storage: 1Gi } |
| 151 | + phase: Bound |
| 152 | + - assert: |
| 153 | + resource: |
| 154 | + apiVersion: v1 |
| 155 | + kind: PersistentVolumeClaim |
| 156 | + metadata: |
| 157 | + labels: |
| 158 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 159 | + postgres-operator.crunchydata.com/data: pgbackrest |
| 160 | + postgres-operator.crunchydata.com/pgbackrest: "" |
| 161 | + postgres-operator.crunchydata.com/pgbackrest-repo: repo2 |
| 162 | + postgres-operator.crunchydata.com/pgbackrest-volume: "" |
| 163 | + spec: |
| 164 | + resources: |
| 165 | + requests: |
| 166 | + storage: 1Gi |
| 167 | + status: |
| 168 | + accessModes: |
| 169 | + - ReadWriteOnce |
| 170 | + capacity: |
| 171 | + storage: 1Gi |
| 172 | + phase: Bound |
| 173 | + |
| 174 | + - name: Write to the instance volumes to trigger default limit |
| 175 | + try: |
| 176 | + - script: |
| 177 | + env: |
| 178 | + - name: NAMESPACE |
| 179 | + value: ($namespace) |
| 180 | + - name: SELECTOR |
| 181 | + value: (join(',', ['postgres-operator.crunchydata.com/role=master',(concat('postgres-operator.crunchydata.com/cluster=', $cluster.name))])) |
| 182 | + content: >- |
| 183 | + kubectl get pods |
| 184 | + --namespace="${NAMESPACE}" |
| 185 | + --selector=${SELECTOR} |
| 186 | + --output=jsonpath={.items..metadata.name} |
| 187 | + check: |
| 188 | + (contains($stdout, 'instance1')): true |
| 189 | + outputs: |
| 190 | + - name: PRIMARY_POD_NAME |
| 191 | + value: (trim_space($stdout)) |
| 192 | + - script: |
| 193 | + env: |
| 194 | + - name: NAMESPACE |
| 195 | + value: ($namespace) |
| 196 | + - name: PRIMARY_POD_NAME |
| 197 | + value: ($PRIMARY_POD_NAME) |
| 198 | + content: >- |
| 199 | + kubectl exec "${PRIMARY_POD_NAME}" |
| 200 | + --namespace="${NAMESPACE}" |
| 201 | + -- bash -c "dd if=/dev/zero of=/pgdata/testfile.$(date +%s) bs=1M count=750" |
| 202 | + - script: |
| 203 | + env: |
| 204 | + - name: NAMESPACE |
| 205 | + value: ($namespace) |
| 206 | + - name: PRIMARY_POD_NAME |
| 207 | + value: ($PRIMARY_POD_NAME) |
| 208 | + content: >- |
| 209 | + kubectl exec "${PRIMARY_POD_NAME}" |
| 210 | + --namespace="${NAMESPACE}" |
| 211 | + -- bash -c "dd if=/dev/zero of=/pgwal/testfile.$(date +%s) bs=1M count=750" |
| 212 | +
|
| 213 | + - name: Write to the repo volumes to trigger default limit |
| 214 | + try: |
| 215 | + - script: |
| 216 | + env: |
| 217 | + - name: NAMESPACE |
| 218 | + value: ($namespace) |
| 219 | + - name: SELECTOR |
| 220 | + value: (join(',', ['postgres-operator.crunchydata.com/pgbackrest-dedicated',(concat('postgres-operator.crunchydata.com/cluster=', $cluster.name))])) |
| 221 | + content: >- |
| 222 | + kubectl get pods |
| 223 | + --namespace="${NAMESPACE}" |
| 224 | + --output=jsonpath={.items..metadata.name} |
| 225 | + --selector="${SELECTOR}" |
| 226 | + check: |
| 227 | + (contains($stdout, 'repo-host')): true |
| 228 | + outputs: |
| 229 | + - name: REPO_HOST_POD_NAME |
| 230 | + value: (trim_space($stdout)) |
| 231 | + - script: |
| 232 | + env: |
| 233 | + - name: NAMESPACE |
| 234 | + value: ($namespace) |
| 235 | + - name: REPO_HOST_POD_NAME |
| 236 | + value: ($REPO_HOST_POD_NAME) |
| 237 | + content: >- |
| 238 | + kubectl exec "${REPO_HOST_POD_NAME}" |
| 239 | + --namespace="${NAMESPACE}" |
| 240 | + -- bash -c "dd if=/dev/zero of=/pgbackrest/repo1/testfile.$(date +%s) bs=1M count=750" |
| 241 | + - script: |
| 242 | + env: |
| 243 | + - name: NAMESPACE |
| 244 | + value: ($namespace) |
| 245 | + - name: REPO_HOST_POD_NAME |
| 246 | + value: ($REPO_HOST_POD_NAME) |
| 247 | + content: >- |
| 248 | + kubectl exec "${REPO_HOST_POD_NAME}" |
| 249 | + --namespace="${NAMESPACE}" |
| 250 | + -- bash -c "dd if=/dev/zero of=/pgbackrest/repo2/testfile.$(date +%s) bs=1M count=750" |
| 251 | +
|
| 252 | + - name: Check that default volume expansion has been requested |
| 253 | + try: |
| 254 | + - assert: |
| 255 | + resource: |
| 256 | + # Check that annotation is set |
| 257 | + apiVersion: v1 |
| 258 | + kind: Pod |
| 259 | + metadata: |
| 260 | + labels: |
| 261 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 262 | + postgres-operator.crunchydata.com/data: postgres |
| 263 | + postgres-operator.crunchydata.com/instance-set: instance1 |
| 264 | + annotations: |
| 265 | + suggested-pgdata-pvc-size: 1461Mi |
| 266 | + suggested-pgwal-pvc-size: 1461Mi |
| 267 | + - assert: |
| 268 | + resource: |
| 269 | + apiVersion: v1 |
| 270 | + kind: Pod |
| 271 | + metadata: |
| 272 | + labels: |
| 273 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 274 | + postgres-operator.crunchydata.com/data: pgbackrest |
| 275 | + postgres-operator.crunchydata.com/pgbackrest: "" |
| 276 | + postgres-operator.crunchydata.com/pgbackrest-dedicated: "" |
| 277 | + annotations: |
| 278 | + suggested-repo1-pvc-size: 1461Mi |
| 279 | + suggested-repo2-pvc-size: 1461Mi |
| 280 | + |
| 281 | + - name: Check that the PVCs size requests have been updated |
| 282 | + try: |
| 283 | + - assert: |
| 284 | + resource: |
| 285 | + apiVersion: v1 |
| 286 | + kind: PersistentVolumeClaim |
| 287 | + metadata: |
| 288 | + labels: |
| 289 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 290 | + postgres-operator.crunchydata.com/instance-set: instance1 |
| 291 | + postgres-operator.crunchydata.com/role: pgdata |
| 292 | + spec: |
| 293 | + resources: |
| 294 | + requests: { storage: 1461Mi } |
| 295 | + status: |
| 296 | + accessModes: [ ReadWriteOnce ] |
| 297 | + capacity: { storage: 2Gi } |
| 298 | + phase: Bound |
| 299 | + - assert: |
| 300 | + resource: |
| 301 | + apiVersion: v1 |
| 302 | + kind: PersistentVolumeClaim |
| 303 | + metadata: |
| 304 | + labels: |
| 305 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 306 | + postgres-operator.crunchydata.com/instance-set: instance1 |
| 307 | + postgres-operator.crunchydata.com/role: pgwal |
| 308 | + spec: |
| 309 | + resources: |
| 310 | + requests: { storage: 1461Mi } |
| 311 | + status: |
| 312 | + accessModes: [ ReadWriteOnce ] |
| 313 | + capacity: { storage: 2Gi } |
| 314 | + phase: Bound |
| 315 | + - assert: |
| 316 | + resource: |
| 317 | + apiVersion: v1 |
| 318 | + kind: PersistentVolumeClaim |
| 319 | + metadata: |
| 320 | + labels: |
| 321 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 322 | + postgres-operator.crunchydata.com/data: pgbackrest |
| 323 | + postgres-operator.crunchydata.com/pgbackrest: "" |
| 324 | + postgres-operator.crunchydata.com/pgbackrest-repo: repo1 |
| 325 | + postgres-operator.crunchydata.com/pgbackrest-volume: "" |
| 326 | + spec: |
| 327 | + resources: |
| 328 | + requests: |
| 329 | + storage: 1461Mi |
| 330 | + status: |
| 331 | + accessModes: |
| 332 | + - ReadWriteOnce |
| 333 | + capacity: |
| 334 | + storage: 2Gi |
| 335 | + phase: Bound |
| 336 | + - assert: |
| 337 | + resource: |
| 338 | + apiVersion: v1 |
| 339 | + kind: PersistentVolumeClaim |
| 340 | + metadata: |
| 341 | + labels: |
| 342 | + postgres-operator.crunchydata.com/cluster: ($cluster.name) |
| 343 | + postgres-operator.crunchydata.com/data: pgbackrest |
| 344 | + postgres-operator.crunchydata.com/pgbackrest: "" |
| 345 | + postgres-operator.crunchydata.com/pgbackrest-repo: repo2 |
| 346 | + postgres-operator.crunchydata.com/pgbackrest-volume: "" |
| 347 | + spec: |
| 348 | + resources: |
| 349 | + requests: |
| 350 | + storage: 1461Mi |
| 351 | + status: |
| 352 | + accessModes: |
| 353 | + - ReadWriteOnce |
| 354 | + capacity: |
| 355 | + storage: 2Gi |
| 356 | + phase: Bound |
| 357 | + |
| 358 | + - name: Check for VolumeAutoGrow expansion events |
| 359 | + try: |
| 360 | + - script: |
| 361 | + env: |
| 362 | + - name: NAMESPACE |
| 363 | + value: ($namespace) |
| 364 | + - name: FIELD_SELECTOR |
| 365 | + value: (join(',', ['involvedObject.kind=PostgresCluster',(concat('involvedObject.name=', $cluster.name)),'reason=VolumeAutoGrow'])) |
| 366 | + content: >- |
| 367 | + kubectl get events |
| 368 | + --namespace="${NAMESPACE}" |
| 369 | + --field-selector="${FIELD_SELECTOR}" |
| 370 | + --output=jsonpath={.items} |
| 371 | + check: |
| 372 | + (parse_json($stdout)[?type == 'Warning']): |
| 373 | + - (contains("message", 'pgWAL volume expansion to 1461Mi requested')): true |
| 374 | + (parse_json($stdout)[?type == 'Normal']): |
| 375 | + - (contains("message", 'pgData volume expansion to 1461Mi requested')): true |
| 376 | + - (contains("message", 'repo1 volume expansion to 1461Mi requested')): true |
| 377 | + - (contains("message", 'repo2 volume expansion to 1461Mi requested')): true |
0 commit comments