Skip to content

Commit 475b990

Browse files
committed
ci: Improve Couchbase K8s resilience with health probes and password reset on restart
Move admin password reset outside the one-time guard file check so it runs on every container start, preventing auth failures when the sandbox image reinitializes after a restart. Add liveness and readiness probes to auto-detect and recover from degraded Couchbase state.
1 parent 1983240 commit 475b990

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

tests/Agent/IntegrationTests/UnboundedServices/couchbase/configure-server.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
#!/bin/sh
2-
set -e
2+
set -e
33
/entrypoint.sh couchbase-server &
44

5-
if [ ! -f /nr-container-configured ]; then
5+
# wait for the server to be up and running
6+
# when the file /opt/couchbase/var/lib/couchbase/container-configured exists, the server is ready
7+
while [ ! -f /opt/couchbase/var/lib/couchbase/container-configured ]; do
8+
sleep 1
9+
done
610

7-
# wait for the server to be up and running
8-
# when the file /opt/couchbase/var/lib/couchbase/container-configured exists, the server is ready
9-
while [ ! -f /opt/couchbase/var/lib/couchbase/container-configured ]; do
10-
sleep 1
11-
done
11+
echo "Waiting a bit longer for the server to be ready..."
12+
sleep 15s
1213

13-
echo "Waiting a bit longer for the server to be ready..."
14-
sleep 15s
14+
# Always reset the administrator password on startup to ensure it matches
15+
# the expected value, even after container restarts where the sandbox image
16+
# may have re-initialized with its default password.
17+
echo "Resetting administrator password"
18+
/opt/couchbase/bin/couchbase-cli reset-admin-password --new-password ${COUCHBASE_ADMINISTRATOR_PASSWORD} || { echo "Error: Failed to reset administrator password"; exit 1; }
1519

16-
# use the couchbase cli to change the administrator password
17-
echo "Changing administrator password"
18-
/opt/couchbase/bin/couchbase-cli reset-admin-password --new-password ${COUCHBASE_ADMINISTRATOR_PASSWORD} || { echo "Error: Failed to reset administrator password"; exit 1; }
20+
# Only create the FTS index on first run (idempotent but avoids noisy errors on restart)
21+
if [ ! -f /nr-container-configured ]; then
1922

2023
# Get UUID of travel-sample bucket
2124
uuid=$(curl -u Administrator:${COUCHBASE_ADMINISTRATOR_PASSWORD} http://127.0.0.1:8091/pools/default/buckets/travel-sample | jq '. | .uuid') || { echo "Error: Failed to retrieve UUID"; exit 1; }
2225

2326
echo "Creating a full text search index on the hotel collection in the inventory scope"
24-
27+
2528
curl -XPUT -H "Content-Type: application/json" -u Administrator:${COUCHBASE_ADMINISTRATOR_PASSWORD} \
2629
http://localhost:8094/api/bucket/travel-sample/scope/inventory/index/index-hotel-description \
2730
-d '{

tests/Agent/IntegrationTests/UnboundedServices/k8s/couchbase.yaml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ spec:
3232
secretKeyRef:
3333
name: unboundedservices-secrets
3434
key: COUCHBASE_ADMINISTRATOR_PASSWORD
35-
# livenessProbe:
36-
# exec:
37-
# command:
38-
# - /bin/sh
39-
# - -c
40-
# - "couchbase-cli server-info -c localhost:8091 -u Administrator -p $COUCHBASE_ADMINISTRATOR_PASSWORD | grep -q '\"status\": \"healthy\"' || exit 1"
41-
# initialDelaySeconds: 120 # wait a while because couchbase takes time to start
42-
# periodSeconds: 60
43-
# timeoutSeconds: 5
44-
# failureThreshold: 3
45-
# resources:
46-
# requests:
47-
# memory: "8Gi"
48-
# limits:
49-
# memory: "8Gi"
35+
readinessProbe:
36+
exec:
37+
command:
38+
- /bin/sh
39+
- -c
40+
- "couchbase-cli server-info -c localhost:8091 -u Administrator -p $COUCHBASE_ADMINISTRATOR_PASSWORD | grep -q '\"status\": \"healthy\"' || exit 1"
41+
initialDelaySeconds: 90
42+
periodSeconds: 15
43+
timeoutSeconds: 10
44+
failureThreshold: 3
45+
livenessProbe:
46+
exec:
47+
command:
48+
- /bin/sh
49+
- -c
50+
- "couchbase-cli server-info -c localhost:8091 -u Administrator -p $COUCHBASE_ADMINISTRATOR_PASSWORD | grep -q '\"status\": \"healthy\"' || exit 1"
51+
initialDelaySeconds: 120
52+
periodSeconds: 60
53+
timeoutSeconds: 10
54+
failureThreshold: 3
5055
---
5156
apiVersion: v1
5257
kind: Service

0 commit comments

Comments
 (0)