Skip to content

Commit 481f170

Browse files
stuggiclaude
andcommitted
Fix pod name discovery using label selector instead of construction
Pod names vary based on Galera cluster names and cannot be reliably constructed from backup names alone. Use label selector to discover pods dynamically. Problem: - Cell1 pod: openstack-cell1-restore-openstack-cell1restore - Main pod: openstack-restore-openstackrestore - Pattern: <galera-cluster>-restore-<galerarestore-cr> - Galera cluster name comes from GaleraBackup spec, not backup name Solution: - Use label selector: -l cr=<galerarestore-cr-name> - Galera operator labels pods with cr=<galerarestore-name> - Discover pod dynamically instead of constructing name - Works for all Galera cluster naming conventions Changes: - Wait task: Discover pod using label selector - Automated restore: Discover pod using label selector - Helper script: Discover pod using label selector - Remove hardcoded pod name construction Example: GaleraRestore CR: openstack-cell1restore Label selector: -l cr=openstack-cell1restore Discovered pod: openstack-cell1-restore-openstack-cell1restore This fixes pod discovery for all Galera cluster configurations. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 27794a5 commit 481f170

2 files changed

Lines changed: 33 additions & 18 deletions

File tree

docs/dev/playbooks/restore-openstack-ctlplane.yaml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,20 +1035,28 @@
10351035
- name: Wait for GaleraRestore pods to be ready
10361036
ansible.builtin.shell: |
10371037
RESTORE_NAME="{{ item }}restore"
1038-
POD_NAME="openstack-restore-${RESTORE_NAME}"
10391038
1040-
echo "Waiting for pod: ${POD_NAME}"
1039+
echo "Waiting for GaleraRestore pod: ${RESTORE_NAME}"
10411040
1042-
# Wait for pod to exist
1041+
# Wait for pod to exist (find by label selector)
10431042
for i in {1..60}; do
1044-
if oc get pod "${POD_NAME}" -n {{ openstack_namespace }} &>/dev/null; then
1045-
echo "Pod found"
1043+
POD_NAME=$(oc get pod -n {{ openstack_namespace }} \
1044+
-l cr=${RESTORE_NAME} \
1045+
-o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
1046+
1047+
if [ -n "${POD_NAME}" ]; then
1048+
echo "Pod found: ${POD_NAME}"
10461049
break
10471050
fi
10481051
echo "Waiting for pod to be created... ($i/60)"
10491052
sleep 5
10501053
done
10511054
1055+
if [ -z "${POD_NAME}" ]; then
1056+
echo "ERROR: Pod for GaleraRestore ${RESTORE_NAME} not found after 5 minutes"
1057+
exit 1
1058+
fi
1059+
10521060
# Wait for pod to be running
10531061
oc wait --for=condition=Ready pod/"${POD_NAME}" -n {{ openstack_namespace }} --timeout=300s
10541062
@@ -1120,18 +1128,23 @@
11201128
set -e
11211129
BACKUP_NAME="{{ item }}"
11221130
RESTORE_NAME="${BACKUP_NAME}restore"
1123-
POD_NAME="openstack-restore-${RESTORE_NAME}"
11241131
11251132
echo "Processing restore for backup: ${BACKUP_NAME}"
11261133
echo "Restore CR: ${RESTORE_NAME}"
1127-
echo "Pod name: ${POD_NAME}"
11281134
1129-
# Verify pod exists and is running
1130-
if ! oc get pod "${POD_NAME}" -n {{ openstack_namespace }} &>/dev/null; then
1131-
echo "ERROR: Restore pod not found: ${POD_NAME}"
1135+
# Discover pod name using label selector
1136+
POD_NAME=$(oc get pod -n {{ openstack_namespace }} \
1137+
-l cr=${RESTORE_NAME} \
1138+
-o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
1139+
1140+
if [ -z "${POD_NAME}" ]; then
1141+
echo "ERROR: Restore pod not found for GaleraRestore: ${RESTORE_NAME}"
11321142
exit 1
11331143
fi
11341144
1145+
echo "Found pod: ${POD_NAME}"
1146+
1147+
# Verify pod is running
11351148
POD_PHASE=$(oc get pod "${POD_NAME}" -n {{ openstack_namespace }} -o jsonpath='{.status.phase}')
11361149
if [ "$POD_PHASE" != "Running" ]; then
11371150
echo "ERROR: Restore pod is not running (phase: ${POD_PHASE})"

docs/dev/scripts/restore-galera-latest.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ if [ -z "$RESTORE_NAME" ]; then
6666
exit 1
6767
fi
6868

69-
POD_NAME="openstack-restore-${RESTORE_NAME}"
70-
7169
print_header "Restore Galera Database from Latest Backup"
72-
echo "Restore Name: $RESTORE_NAME"
73-
echo "Pod Name: $POD_NAME"
70+
echo "GaleraRestore CR: $RESTORE_NAME"
7471
echo "Namespace: $OPENSTACK_NAMESPACE"
7572

76-
# Check if pod exists
77-
print_info "Checking if restore pod exists..."
78-
if ! oc get pod "$POD_NAME" -n "$OPENSTACK_NAMESPACE" &>/dev/null; then
79-
print_error "Restore pod not found: $POD_NAME"
73+
# Discover pod name using label selector
74+
print_info "Discovering restore pod using label selector..."
75+
POD_NAME=$(oc get pod -n "$OPENSTACK_NAMESPACE" \
76+
-l cr="${RESTORE_NAME}" \
77+
-o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
78+
79+
if [ -z "$POD_NAME" ]; then
80+
print_error "Restore pod not found for GaleraRestore: $RESTORE_NAME"
8081
print_info "Make sure the GaleraRestore CR has been created and the pod is running"
82+
print_info "Expected label: cr=${RESTORE_NAME}"
8183
exit 1
8284
fi
8385

0 commit comments

Comments
 (0)