forked from cloudnative-pg/charts
-
-
Notifications
You must be signed in to change notification settings - Fork 2
320 lines (261 loc) · 11.7 KB
/
test-helm-chart.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# workflows/test-helm-chart.yml
#
# Test Helm Chart
# Test the ParadeDB Helm chart against a local Minikube cluster and a local AWS EKS cluster.
name: Test Helm Chart
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "charts/paradedb/*"
- ".github/workflows/test-helm-chart.yml"
workflow_dispatch:
concurrency:
group: test-helm-chart-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
test-helm-minikube:
name: Test Helm Chart on Minikube
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4
- name: Set up Kubectl
uses: azure/setup-kubectl@v4
- name: Set up Helm
uses: azure/setup-helm@v4
# Enables the default-storageclass and storage-provisioner addons by default
- name: Set up & Start Minikube
uses: medyagh/setup-minikube@latest
- name: Install the CloudNativePG Operator
run: |
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install cnpg --namespace cnpg-system --create-namespace cnpg/cloudnative-pg
- name: Wait for CNPG Webhook Service to be Ready
run: |
kubectl wait --namespace cnpg-system --for=condition=available --timeout=120s deployment/cnpg-cloudnative-pg
kubectl get svc -n cnpg-system cnpg-webhook-service
- name: Test Helm Dependency Update
working-directory: charts/paradedb/
run: helm dependency update . --debug
- name: Update appVersion to Latest paradedb/paradedb Tag
working-directory: charts/paradedb/
run: |
# Fetch the latest release tag and strip the 'v' prefix
LATEST_TAG=$(curl -s https://api.github.com/repos/paradedb/paradedb/releases/latest | jq -r '.tag_name')
CLEANED_TAG=${LATEST_TAG#v}
# Update the appVersion in the Chart.yaml file
sed -i "s/^appVersion: .*/appVersion: $CLEANED_TAG/" Chart.yaml
cat Chart.yaml
- name: Test Helm Template
working-directory: charts/paradedb/
run: helm template paradedb . --debug
- name: Test Helm Install
working-directory: charts/paradedb/
run: helm install paradedb . --namespace paradedb --create-namespace --debug
- name: Test Helm Upgrade
working-directory: charts/paradedb/
run: helm upgrade paradedb . --namespace paradedb --debug
# TODO: This fails
- name: Test PostgreSQL Connection
run: |
# Get the ParadeDB K8s cluster secrets
kubectl -n paradedb get secrets paradedb-app -o yaml
# Decode the ParadeDB K8s cluster secrets
export PG_USERNAME=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.username}" | base64 --decode)
export PG_PASSWORD=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.password}" | base64 --decode)
export PG_DATABASE=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.dbname}" | base64 --decode)
# Wait for PostgreSQL to be ready
sleep 30
# Check if any pods were found
POD_NAMES=$(kubectl -n paradedb get pods --no-headers | grep 'paradedb-1-initdb-' | awk '{print $1}')
if [ -n "$POD_NAMES" ]; then
for POD_NAME in $POD_NAMES; do
echo "Fetching details for pod $POD_NAME..."
kubectl -n paradedb describe pod $POD_NAME
echo "Fetching logs for pod $POD_NAME..."
kubectl -n paradedb logs $POD_NAME || echo "No current logs available for $POD_NAME."
echo "--------------------------------------"
done
else
echo "No pods matching the pattern found."
fi
echo "Fetching details for all resources in the paradedb namespace..."
kubectl -n paradedb get all
echo "Waiting for the paradedb-rw service to be ready..."
while [[ $(kubectl -n paradedb get pods -l app=paradedb -o jsonpath="{.items[*].status.containerStatuses[*].ready}") != "true" ]]; do
echo "Waiting for pod(s) to be ready..."
sleep 5
done
echo "Starting port-forward..."
kubectl port-forward svc/paradedb-rw 5432:5432 &
echo "Connecting to ParadeDB via psql..."
psql -h localhost -p 5432 -U $PG_USERNAME -d $PG_DATABASE -c "SELECT * FROM pg_extension;"
- name: Test Helm Uninstall
run: helm uninstall paradedb --namespace paradedb --debug
test-helm-eks:
name: Test Helm Chart on AWS EKS via LocalStack
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Checkout Git Repository
uses: actions/checkout@v4
- name: Set up Kubectl
uses: azure/setup-kubectl@v4
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Start LocalStack
uses: LocalStack/[email protected]
with:
image-tag: "latest"
install-awslocal: "true"
configuration: DEBUG=1
use-pro: "true"
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
- name: Configure AWS CLI for LocalStack
run: |
awslocal configure set aws_secret_access_key test
awslocal configure set aws_access_key_id test
awslocal configure set region us-east-1
# As of writing, the latest Kubernetes version available on LocalStack EKS
# is 1.29. CloudNativePG requires version 1.25+
- name: Create the LocalStack AWS EKS Cluster
run: |
awslocal --endpoint-url=http://localhost:4566 eks create-cluster \
--name paradedb-eks \
--role-arn arn:aws:iam::000000000000:role/eks-service-role \
--resources-vpc-config subnetIds=subnet-12345 \
--kubernetes-version 1.29
- name: Wait for LocalStack AWS EKS Cluster to be Active
run: |
for i in {1..10}; do
STATUS=$(awslocal --endpoint-url=http://localhost:4566 --region us-east-1 eks describe-cluster --name paradedb-eks --query 'cluster.status' --output text)
if [ "$STATUS" == "ACTIVE" ]; then
echo "Cluster is ACTIVE"
break
else
echo "Cluster status is $STATUS. Waiting..."
sleep 10
fi
done
- name: Update Kubeconfig to Use the LocalStack AWS EKS Cluster
run: awslocal --endpoint-url=http://localhost:4566 eks update-kubeconfig --name paradedb-eks
- name: Wait for the LocalStack AWS EKS Cluster to be Ready
run: |
nodes=$(kubectl get nodes --no-headers -o custom-columns=NAME:.metadata.name)
for node in $nodes; do
kubectl wait --for=condition=ready node/$node --timeout=120s
done
# This is required to mock the AWS EKS storage class
- name: Create StorageClass
run: |
cat <<EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: manual
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Immediate
EOF
kubectl get storageclass
# This is required to mock the AWS EKS storage class
- name: Create PersistentVolume
run: |
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/data
storageClassName: manual
EOF
kubectl get pv
# This is required to mock the AWS EKS storage class
- name: Create PersistentVolumeClaim
run: |
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
storageClassName: manual
EOF
kubectl get pvc
- name: Install the CloudNativePG Operator
run: |
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install cnpg --namespace cnpg-system --create-namespace cnpg/cloudnative-pg
- name: Wait for CNPG Webhook Service to be Ready
run: |
kubectl wait --namespace cnpg-system --for=condition=available --timeout=120s deployment/cnpg-cloudnative-pg
kubectl get svc -n cnpg-system cnpg-webhook-service
- name: Test Helm Dependency Update
working-directory: charts/paradedb/
run: helm dependency update . --debug
- name: Update appVersion to Latest paradedb/paradedb Tag
working-directory: charts/paradedb/
run: |
# Fetch the latest release tag and strip the 'v' prefix
LATEST_TAG=$(curl -s https://api.github.com/repos/paradedb/paradedb/releases/latest | jq -r '.tag_name')
CLEANED_TAG=${LATEST_TAG#v}
# Update the appVersion in the Chart.yaml file
sed -i "s/^appVersion: .*/appVersion: $CLEANED_TAG/" Chart.yaml
cat Chart.yaml
- name: Test Helm Template
working-directory: charts/paradedb/
run: helm template paradedb . --debug
- name: Test Helm Install
working-directory: charts/paradedb/
run: helm install paradedb . --namespace paradedb --create-namespace --debug
- name: Test Helm Upgrade
working-directory: charts/paradedb/
run: helm upgrade paradedb . --namespace paradedb --debug
# TODO: This fails
- name: Test PostgreSQL Connection
run: |
# Get the ParadeDB K8s cluster secrets
kubectl -n paradedb get secrets paradedb-app -o yaml
# Decode the ParadeDB K8s cluster secrets
export PG_USERNAME=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.username}" | base64 --decode)
export PG_PASSWORD=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.password}" | base64 --decode)
export PG_DATABASE=$(kubectl -n paradedb get secrets paradedb-app -o jsonpath="{.data.dbname}" | base64 --decode)
# Wait for PostgreSQL to be ready
sleep 30
# Get the list of pods matching the pattern
POD_NAMES=$(kubectl -n paradedb get pods --no-headers | grep 'paradedb-1-initdb-' | awk '{print $1}')
# Check if any pods were found
if [ -n "$POD_NAMES" ]; then
# Loop through each pod name
for POD_NAME in $POD_NAMES; do
echo "Fetching details for pod $POD_NAME..."
# Describe the pod
kubectl -n paradedb describe pod $POD_NAME
echo "Fetching logs for pod $POD_NAME..."
# Fetch current logs
kubectl -n paradedb logs $POD_NAME || echo "No current logs available for $POD_NAME."
# Fetch previous logs (if any)
kubectl -n paradedb logs $POD_NAME --previous || echo "No previous logs available for $POD_NAME."
echo "--------------------------------------"
done
else
echo "No pods matching the pattern found."
fi
# Test that we can connect to the ParadeDB K8s cluster via psql and that the extensions are installed
kubectl port-forward svc/paradedb-rw 5432:5432 &
psql -h localhost -p 5432 -U $PG_USERNAME -d $PG_DATABASE -c "SELECT * FROM pg_extension;"
- name: Test Helm Uninstall
run: helm uninstall paradedb --namespace paradedb --debug