Skip to content

Commit 80e199a

Browse files
author
Drew Wells
committed
example of standing up alloydb instance
1 parent b656b1d commit 80e199a

File tree

3 files changed

+242
-0
lines changed

3 files changed

+242
-0
lines changed

sampleClaims/alloydb_psc.yaml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: alloydb-psc-test-creds
5+
namespace: dwells
6+
type: Opaque
7+
data:
8+
password: bXlwYXNzd29yZA== # mypassword
9+
---
10+
apiVersion: persistance.infoblox.com/v1alpha1
11+
kind: XNetworkRecord
12+
metadata:
13+
name: alloydb-psc-network
14+
annotations:
15+
crossplane.io/external-name: alloydb-psc-network
16+
spec:
17+
parameters:
18+
pscDNSName: ''
19+
serviceAttachmentLink: ''
20+
region: us-east1
21+
subnetwork: projects/gcp-eng-ddiaas-dev/regions/us-east1/subnetworks/private-service-connect
22+
network: projects/gcp-eng-ddiaas-dev/global/networks/ddiaas-dev-use1-vpc
23+
---
24+
apiVersion: alloydb.gcp.upbound.io/v1beta2
25+
kind: Cluster
26+
metadata:
27+
annotations:
28+
meta.upbound.io/example-id: alloydb/v1beta1/instance
29+
labels:
30+
testing.upbound.io/example-name: alloydb-psc-test
31+
name: alloydb-psc-test
32+
spec:
33+
providerConfigRef:
34+
name: default
35+
# writeConnectionSecretToRef:
36+
# name: alloydb-creds-cluster
37+
# namespace: dwells
38+
# Doesn't appear to work
39+
# publishConnectionDetailsTo:
40+
# name: publish-alloydb-creds-cluster
41+
forProvider:
42+
initialUser:
43+
passwordSecretRef:
44+
key: password
45+
name: alloydb-psc-test-creds
46+
namespace: dwells
47+
user: postgres
48+
location: us-east1
49+
networkConfig:
50+
pscConfig:
51+
pscEnabled: true
52+
---
53+
apiVersion: alloydb.gcp.upbound.io/v1beta2
54+
kind: Instance
55+
metadata:
56+
annotations:
57+
meta.upbound.io/example-id: alloydb/v1beta2/instance
58+
labels:
59+
testing.upbound.io/alloydbinstance: alloydb-psc-test
60+
name: alloydb-psc-test
61+
spec:
62+
providerConfigRef:
63+
name: default
64+
# writeConnectionSecretToRef:
65+
# name: alloydb-creds-instance
66+
# namespace: dwells
67+
forProvider:
68+
clusterSelector:
69+
matchLabels:
70+
testing.upbound.io/example-name: alloydb-psc-test
71+
# How to set this to basic? https://cloud.google.com/alloydb/docs/overview?authuser=3#instances
72+
databaseFlags:
73+
"alloydb.iam_authentication": "on"
74+
instanceType: PRIMARY
75+
machineConfig:
76+
cpuCount: 2
77+
pscInstanceConfig:
78+
allowedConsumerProjects:
79+
- gcp-eng-ddiaas-dev
80+
# publishConnectionDetailsTo:
81+
# name: publish-alloydb-creds-instance
82+
---

sampleClaims/alloydb_test.yaml

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
# value: "[email protected]"
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

sampleClaims/workloadid.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: gcloud-cli-pod
5+
annotations:
6+
# Workload Identity annotation to use the specific service account
7+
#iam.gke.io/gcp-service-account: "[email protected]"
8+
spec:
9+
containers:
10+
- name: gcloud-cli
11+
image: google/cloud-sdk:slim
12+
command:
13+
- /bin/bash
14+
- -c
15+
- |
16+
# Fetch IAM user name
17+
IAM_NAME=$(gcloud auth list --format='get(account)')
18+
echo "IAM User: $IAM_NAME"
19+
# Sleep indefinitely
20+
sleep infinity
21+
serviceAccountName: db-controller
22+
restartPolicy: Never

0 commit comments

Comments
 (0)