|
49 | 49 | kubectl -n tenant-test wait deployment.apps/mariadb-$name-metrics --timeout=90s --for=jsonpath='{.status.replicas}'=1 |
50 | 50 | kubectl -n tenant-test delete mariadbs.apps.cozystack.io $name |
51 | 51 | } |
| 52 | + |
| 53 | +@test "Create single-replica MariaDB" { |
| 54 | + name='single' |
| 55 | + kubectl -n tenant-test delete mariadbs.apps.cozystack.io $name --ignore-not-found --timeout=2m |
| 56 | + kubectl apply -f- <<EOF |
| 57 | +apiVersion: apps.cozystack.io/v1alpha1 |
| 58 | +kind: MariaDB |
| 59 | +metadata: |
| 60 | + name: $name |
| 61 | + namespace: tenant-test |
| 62 | +spec: |
| 63 | + external: false |
| 64 | + size: 10Gi |
| 65 | + replicas: 1 |
| 66 | + storageClass: "" |
| 67 | + users: |
| 68 | + testuser: |
| 69 | + maxUserConnections: 1000 |
| 70 | + password: xai7Wepo |
| 71 | + databases: |
| 72 | + testdb: |
| 73 | + roles: |
| 74 | + admin: |
| 75 | + - testuser |
| 76 | + backup: |
| 77 | + enabled: false |
| 78 | + s3Region: us-east-1 |
| 79 | + s3Bucket: s3.example.org/mariadb-backups |
| 80 | + schedule: "0 2 * * *" |
| 81 | + cleanupStrategy: "--keep-last=3 --keep-daily=3 --keep-within-weekly=1m" |
| 82 | + s3AccessKey: oobaiRus9pah8PhohL1ThaeTa4UVa7gu |
| 83 | + s3SecretKey: ju3eum4dekeich9ahM1te8waeGai0oog |
| 84 | + resticPassword: ChaXoveekoh6eigh4siesheeda2quai0 |
| 85 | + resources: {} |
| 86 | + resourcesPreset: "nano" |
| 87 | +EOF |
| 88 | + # Wait for the operator to materialise the HelmRelease before kubectl wait |
| 89 | + # kicks in (kubectl wait errors immediately if the object does not exist yet). |
| 90 | + timeout 60 sh -ec "until kubectl -n tenant-test get hr mariadb-$name >/dev/null 2>&1; do sleep 2; done" |
| 91 | + # A single-replica MariaDB must be accepted by the operator's validating |
| 92 | + # webhook: replication is guarded on replicas>1, so replicas=1 renders a CR |
| 93 | + # the webhook admits. Dump the HR + rendered CR on failure so a webhook |
| 94 | + # rejection (the regression this guards against) is legible in the log. |
| 95 | + kubectl -n tenant-test wait hr mariadb-$name --timeout=5m --for=condition=ready \ |
| 96 | + || { echo "HR mariadb-$name not ready — dumping state:"; \ |
| 97 | + kubectl -n tenant-test describe hr mariadb-$name; \ |
| 98 | + kubectl -n tenant-test get mariadbs.k8s.mariadb.com mariadb-$name -o yaml; false; } |
| 99 | + # With replicas=1 the operator provisions the bare <name> service (no |
| 100 | + # -primary/-secondary): assert it exists and has an endpoint. |
| 101 | + timeout 80 sh -ec "until kubectl -n tenant-test get svc mariadb-$name -o jsonpath='{.spec.ports[0].port}' | grep -q '3306'; do sleep 10; done" |
| 102 | + timeout 80 sh -ec "until kubectl -n tenant-test get endpoints mariadb-$name -o jsonpath='{.subsets[*].addresses[*].ip}' | grep -q '[0-9]'; do sleep 10; done" |
| 103 | + timeout 60 sh -ec "until kubectl -n tenant-test get statefulset.apps/mariadb-$name >/dev/null 2>&1; do sleep 2; done" |
| 104 | + kubectl -n tenant-test wait statefulset.apps/mariadb-$name --timeout=110s --for=jsonpath='{.status.replicas}'=1 |
| 105 | + timeout 80 sh -ec "until kubectl -n tenant-test get svc mariadb-$name-metrics -o jsonpath='{.spec.ports[0].port}' | grep -q '9104'; do sleep 10; done" |
| 106 | + timeout 40 sh -ec "until kubectl -n tenant-test get endpoints mariadb-$name-metrics -o jsonpath='{.subsets[*].addresses[*].ip}' | grep -q '[0-9]'; do sleep 10; done" |
| 107 | + timeout 60 sh -ec "until kubectl -n tenant-test get deployment.apps/mariadb-$name-metrics >/dev/null 2>&1; do sleep 2; done" |
| 108 | + kubectl -n tenant-test wait deployment.apps/mariadb-$name-metrics --timeout=90s --for=jsonpath='{.status.replicas}'=1 |
| 109 | + kubectl -n tenant-test delete mariadbs.apps.cozystack.io $name --ignore-not-found |
| 110 | +} |
0 commit comments