|
| 1 | +--- |
| 2 | +apiVersion: v1 |
| 3 | +kind: Pod |
| 4 | +metadata: |
| 5 | + name: alloydb-client |
| 6 | +spec: |
| 7 | + initContainers: |
| 8 | + # - name: postgres-init |
| 9 | + # image: postgres:15-alpine |
| 10 | + # command: |
| 11 | + # - "bash" |
| 12 | + # - "-c" |
| 13 | + # args: |
| 14 | + # - | |
| 15 | + # until timeout 10 psql -h localhost -U postgres -c 'SELECT 1'; do |
| 16 | + # echo "Waiting to connection to be ready..." |
| 17 | + # sleep 3 |
| 18 | + # done |
| 19 | + # env: |
| 20 | + # - name: NEWUSER |
| 21 | + |
| 22 | + # - name: PGHOST |
| 23 | + # value: "127.0.0.1" |
| 24 | + # - name: PGPORT |
| 25 | + # value: "5432" |
| 26 | + # - name: NEWDB |
| 27 | + # value: "mydb" |
| 28 | + # - name: PGPASSWORD |
| 29 | + # valueFrom: |
| 30 | + # secretKeyRef: |
| 31 | + # name: alloydb-psc-test-creds |
| 32 | + # key: password |
| 33 | + - name: init-user |
| 34 | + image: google/cloud-sdk:slim # Image with gcloud CLI |
| 35 | + command: |
| 36 | + - /bin/bash |
| 37 | + - -cx |
| 38 | + - | |
| 39 | + # Provision the AlloyDB database user using gcloud CLI |
| 40 | + gcloud auth activate-service-account --key-file=/secrets/creds |
| 41 | + gcloud config set project $PROJECT |
| 42 | +
|
| 43 | + if gcloud alloydb users list --region $REGION --cluster=$CLUSTERNAME --format="value(name)" | grep -qw "$NEWUSER"; then |
| 44 | + echo "User already exists: $NEWUSER" |
| 45 | + else |
| 46 | + gcloud alloydb users create $NEWUSER --region $REGION --cluster=$CLUSTERNAME --type=IAM_BASED |
| 47 | + fi |
| 48 | + env: |
| 49 | + - name: REGION |
| 50 | + value: us-east1 |
| 51 | + - name: PROJECT |
| 52 | + value: gcp-eng-ddiaas-dev |
| 53 | + - name: NEWUSER |
| 54 | + |
| 55 | + - name: INSTANCENAME |
| 56 | + value: alloydb-psc-test |
| 57 | + - name: CLUSTERNAME |
| 58 | + value: alloydb-psc-test |
| 59 | + - name: PGHOST |
| 60 | + value: "127.0.0.1" |
| 61 | + - name: PGPORT |
| 62 | + value: "5432" |
| 63 | + - name: NEWDB |
| 64 | + value: "mydb" |
| 65 | + volumeMounts: |
| 66 | + - name: service-account |
| 67 | + mountPath: /secrets |
| 68 | + readOnly: true |
| 69 | + containers: |
| 70 | + - name: proxy |
| 71 | + image: gcr.io/alloydb-connectors/alloydb-auth-proxy:1.11.0-bullseye |
| 72 | + command: ["/alloydb-auth-proxy"] |
| 73 | + args: |
| 74 | + - projects/gcp-eng-ddiaas-dev/locations/us-east1/clusters/alloydb-psc-test/instances/alloydb-psc-test |
| 75 | + - --credentials-file=/secrets/creds |
| 76 | + - --auto-iam-authn |
| 77 | + - --run-connection-test |
| 78 | + - --psc |
| 79 | + - --debug-logs |
| 80 | + - --health-check |
| 81 | + - --address=0.0.0.0 |
| 82 | + # livenessProbe: |
| 83 | + # httpGet: |
| 84 | + # path: /liveness |
| 85 | + # port: 9090 |
| 86 | + # initialDelaySeconds: 15 |
| 87 | + # periodSeconds: 20 |
| 88 | + readinessProbe: |
| 89 | + httpGet: |
| 90 | + path: /readiness |
| 91 | + port: 9090 |
| 92 | + initialDelaySeconds: 5 |
| 93 | + periodSeconds: 10 |
| 94 | + volumeMounts: |
| 95 | + - name: service-account |
| 96 | + mountPath: /secrets |
| 97 | + readOnly: true |
| 98 | + - name: cli |
| 99 | + image: postgres:15-alpine |
| 100 | + command: |
| 101 | + - "bash" |
| 102 | + - "-c" |
| 103 | + args: |
| 104 | + - | |
| 105 | + export PGPASSWORD=$(cat /creds/password) |
| 106 | + until timeout 10 psql -h localhost -U "$USER" -d postgres -c 'SELECT 1'; do |
| 107 | + echo "Waiting to connection to be ready..." |
| 108 | + sleep 3 |
| 109 | + done |
| 110 | + # @echo "Provision Database" |
| 111 | + # psql -U "$USER" postgres << EOF |
| 112 | + # CREATE DATABASE $NEWDB; |
| 113 | + # EOF |
| 114 | +
|
| 115 | + sleep infinity; |
| 116 | + env: |
| 117 | + - name: USER |
| 118 | + |
| 119 | + - name: PGHOST |
| 120 | + value: "127.0.0.1" |
| 121 | + - name: PGPORT |
| 122 | + value: "5432" |
| 123 | + - name: PGDATABASE |
| 124 | + value: "mydb" |
| 125 | + volumeMounts: |
| 126 | + - name: service-account |
| 127 | + mountPath: /secrets |
| 128 | + readOnly: true |
| 129 | + - name: psql-creds |
| 130 | + mountPath: /creds |
| 131 | + readOnly: true |
| 132 | + volumes: |
| 133 | + - name: service-account |
| 134 | + secret: |
| 135 | + secretName: gcp-secret |
| 136 | + - name: psql-creds |
| 137 | + secret: |
| 138 | + secretName: alloydb-psc-test-creds |
0 commit comments