Skip to content

Commit c414df5

Browse files
committed
fix: resolve postgresql image from operator csv in setup-database
replace the hardcoded postgresql image with a dynamic lookup from the rhoai operator csv's spec.relatedImages. this ensures the setup script uses the digest-pinned image shipped with the operator, which is critical for disconnected environments where idms redirects registry.redhat.io references to the local mirror. the csv lookup extracts the image for "postgresql_16_image", strips the mirror registry prefix, and reconstructs it with the canonical registry.redhat.io path. if the csv is not available (e.g., dev/odh environments without olm), falls back to a :latest tag. an explicit POSTGRES_IMAGE env var override is also supported. Signed-off-by: Chaitanya Kulkarni <chkulkar@redhat.com> Made-with: Cursor
1 parent dbf6d03 commit c414df5

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

scripts/setup-database.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# - Default: opendatahub (ODH) or redhat-ods-applications (RHOAI)
1212
#
1313
# Environment variables:
14-
# NAMESPACE Target namespace (default: opendatahub)
15-
# POSTGRES_USER Database user (default: maas)
16-
# POSTGRES_DB Database name (default: maas)
14+
# NAMESPACE Target namespace (default: opendatahub)
15+
# POSTGRES_IMAGE Override PostgreSQL image (default: resolved from operator CSV,
16+
# falls back to registry.redhat.io/rhel9/postgresql-16:latest)
17+
# POSTGRES_USER Database user (default: maas)
18+
# POSTGRES_DB Database name (default: maas)
1719
# POSTGRES_PASSWORD Database password (default: auto-generated)
1820
#
1921
# Usage:
@@ -33,6 +35,30 @@ source "${SCRIPT_DIR}/deployment-helpers.sh"
3335
# Default namespace for ODH; use redhat-ods-applications for RHOAI
3436
: "${NAMESPACE:=opendatahub}"
3537

38+
# Fallback image when the RHOAI operator CSV is not available (e.g., vanilla
39+
# Kubernetes, ODH-only clusters, or dev environments without OLM).
40+
DEFAULT_POSTGRES_IMAGE="registry.redhat.io/rhel9/postgresql-16:latest"
41+
42+
# Resolve the PostgreSQL image from the RHOAI operator CSV's relatedImages.
43+
# Expects the RHOAI operator (or its CSV) to be installed on the cluster.
44+
# Replaces the registry prefix with registry.redhat.io so that IDMS can
45+
# redirect to the correct mirror in disconnected environments.
46+
# Falls back to DEFAULT_POSTGRES_IMAGE if the CSV is not found or the entry
47+
# is missing.
48+
resolve_postgres_image() {
49+
local csv_image
50+
csv_image=$(kubectl get csv -l 'olm.copiedFrom=redhat-ods-operator' \
51+
-o jsonpath='{.items[0].spec.relatedImages[?(@.name=="postgresql_16_image")].image}' 2>/dev/null) || true
52+
53+
if [[ -n "${csv_image}" ]]; then
54+
# Strip the registry host and prepend the canonical registry.redhat.io
55+
# e.g., bastion.example.com:8443/rhel9/postgresql-16@sha256:abc → registry.redhat.io/rhel9/postgresql-16@sha256:abc
56+
echo "registry.redhat.io/${csv_image#*/}"
57+
else
58+
echo "${DEFAULT_POSTGRES_IMAGE}"
59+
fi
60+
}
61+
3662
# Ensure namespace exists
3763
if ! kubectl get namespace "$NAMESPACE" >/dev/null 2>&1; then
3864
echo "📦 Creating namespace '$NAMESPACE'..."
@@ -70,6 +96,16 @@ fi
7096

7197
echo " Creating PostgreSQL deployment..."
7298
echo " ⚠️ Using POC configuration (ephemeral storage)"
99+
100+
# Allow explicit override via POSTGRES_IMAGE env var; otherwise resolve from
101+
# the operator CSV, falling back to the default :latest tag.
102+
POSTGRES_IMAGE="${POSTGRES_IMAGE:-$(resolve_postgres_image)}"
103+
if [[ "${POSTGRES_IMAGE}" == "${DEFAULT_POSTGRES_IMAGE}" ]]; then
104+
echo " Using default PostgreSQL image (operator CSV not available)"
105+
else
106+
echo " Resolved PostgreSQL image from operator CSV"
107+
fi
108+
echo " Image: ${POSTGRES_IMAGE}"
73109
echo ""
74110

75111
# Deploy PostgreSQL resources
@@ -105,7 +141,7 @@ spec:
105141
spec:
106142
containers:
107143
- name: postgres
108-
image: registry.redhat.io/rhel9/postgresql-16:latest@sha256:680b42d2c51b76d23cd5b68dd774af456b1e4c98c4aaeb49d0de0948dc933716
144+
image: ${POSTGRES_IMAGE}
109145
env:
110146
- name: POSTGRESQL_USER
111147
valueFrom:

0 commit comments

Comments
 (0)