@@ -54,11 +54,12 @@ import (
5454
5555var _ = Describe ("Postgres Major Upgrade" , Label (tests .LabelPostgresMajorUpgrade ), func () {
5656 const (
57- level = tests .Medium
58- namespacePrefix = "cluster-major-upgrade"
59- postgisEntry = "postgis"
60- postgresqlEntry = "postgresql"
61- postgresqlMinimalEntry = "postgresql-minimal"
57+ level = tests .Medium
58+ namespacePrefix = "cluster-major-upgrade"
59+ postgisEntry = "postgis"
60+ postgresqlEntry = "postgresql"
61+ postgresqlMinimalEntry = "postgresql-minimal"
62+ customImageRegistryEnvVar = "MAJOR_UPGRADE_IMAGE_REGISTRY"
6263 )
6364
6465 var namespace string
@@ -111,14 +112,10 @@ var _ = Describe("Postgres Major Upgrade", Label(tests.LabelPostgresMajorUpgrade
111112
112113 generatePostgreSQLCluster := func (namespace string , storageClass string , majorVersion int ) * v1.Cluster {
113114 cluster := generateBaseCluster (namespace , storageClass )
114- cluster .Spec .ImageName = "ghcr.io/cloudnative-pg/postgresql:" + strconv .Itoa (majorVersion )
115- cluster .Spec .Bootstrap = & v1.BootstrapConfiguration {
116- InitDB : & v1.BootstrapInitDB {
117- PostInitSQL : []string {
118- "CREATE EXTENSION IF NOT EXISTS pg_stat_statements;" ,
119- "CREATE EXTENSION IF NOT EXISTS pg_trgm;" ,
120- },
121- },
115+ cluster .Spec .ImageName = fmt .Sprintf ("ghcr.io/cloudnative-pg/postgresql:%d-standard-bookworm" , majorVersion )
116+ cluster .Spec .Bootstrap .InitDB .PostInitSQL = []string {
117+ "CREATE EXTENSION IF NOT EXISTS pg_stat_statements;" ,
118+ "CREATE EXTENSION IF NOT EXISTS pg_trgm;" ,
122119 }
123120 cluster .Spec .PostgresConfiguration .Parameters ["pg_stat_statements.track" ] = "top"
124121 return cluster
@@ -132,26 +129,22 @@ var _ = Describe("Postgres Major Upgrade", Label(tests.LabelPostgresMajorUpgrade
132129 generatePostGISCluster := func (namespace string , storageClass string , majorVersion int ) * v1.Cluster {
133130 cluster := generateBaseCluster (namespace , storageClass )
134131 cluster .Spec .ImageName = "ghcr.io/cloudnative-pg/postgis:" + strconv .Itoa (majorVersion )
135- cluster .Spec .Bootstrap = & v1.BootstrapConfiguration {
136- InitDB : & v1.BootstrapInitDB {
137- PostInitApplicationSQL : []string {
138- "CREATE EXTENSION postgis" ,
139- "CREATE EXTENSION postgis_raster" ,
140- "CREATE EXTENSION postgis_sfcgal" ,
141- "CREATE EXTENSION fuzzystrmatch" ,
142- "CREATE EXTENSION address_standardizer" ,
143- "CREATE EXTENSION address_standardizer_data_us" ,
144- "CREATE EXTENSION postgis_tiger_geocoder" ,
145- "CREATE EXTENSION postgis_topology" ,
146- "CREATE TABLE geometries (name varchar, geom geometry)" ,
147- "INSERT INTO geometries VALUES" +
148- " ('Point', 'POINT(0 0)')," +
149- " ('Linestring', 'LINESTRING(0 0, 1 1, 2 1, 2 2)')," +
150- " ('Polygon', 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')," +
151- " ('PolygonWithHole', 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))')," +
152- " ('Collection', 'GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))');" ,
153- },
154- },
132+ cluster .Spec .Bootstrap .InitDB .PostInitApplicationSQL = []string {
133+ "CREATE EXTENSION postgis" ,
134+ "CREATE EXTENSION postgis_raster" ,
135+ "CREATE EXTENSION postgis_sfcgal" ,
136+ "CREATE EXTENSION fuzzystrmatch" ,
137+ "CREATE EXTENSION address_standardizer" ,
138+ "CREATE EXTENSION address_standardizer_data_us" ,
139+ "CREATE EXTENSION postgis_tiger_geocoder" ,
140+ "CREATE EXTENSION postgis_topology" ,
141+ "CREATE TABLE geometries (name varchar, geom geometry)" ,
142+ "INSERT INTO geometries VALUES" +
143+ " ('Point', 'POINT(0 0)')," +
144+ " ('Linestring', 'LINESTRING(0 0, 1 1, 2 1, 2 2)')," +
145+ " ('Polygon', 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')," +
146+ " ('PolygonWithHole', 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))')," +
147+ " ('Collection', 'GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))');" ,
155148 }
156149 return cluster
157150 }
@@ -177,26 +170,55 @@ var _ = Describe("Postgres Major Upgrade", Label(tests.LabelPostgresMajorUpgrade
177170 return currentMajor , targetMajor
178171 }
179172
173+ // generateTargetImages, given a targetMajor, generates a target image for each buildScenario.
174+ // MAJOR_UPGRADE_IMAGE_REPO env allows to customize the target image repository.
175+ generateTargetImages := func (targetMajor uint64 ) map [string ]string {
176+ const (
177+ // ImageRepository is the default repository for Postgres container images
178+ ImageRepository = "ghcr.io/cloudnative-pg/postgresql"
179+
180+ // PostgisImageRepository is the default repository for Postgis container images
181+ PostgisImageRepository = "ghcr.io/cloudnative-pg/postgis"
182+ )
183+
184+ // Default target Images
185+ targetImages := map [string ]string {
186+ postgisEntry : fmt .Sprintf ("%v:%v" , PostgisImageRepository , targetMajor ),
187+ postgresqlEntry : fmt .Sprintf ("%v:%v-standard-bookworm" , ImageRepository , targetMajor ),
188+ postgresqlMinimalEntry : fmt .Sprintf ("%v:%v-minimal-bookworm" , ImageRepository , targetMajor ),
189+ }
190+ // Set custom targets when detecting a given env variable
191+ if envValue := os .Getenv (customImageRegistryEnvVar ); envValue != "" {
192+ targetImages [postgisEntry ] = fmt .Sprintf ("%v:%v-postgis-bookworm" , envValue , targetMajor )
193+ targetImages [postgresqlEntry ] = fmt .Sprintf ("%v:%v-standard-bookworm" , envValue , targetMajor )
194+ targetImages [postgresqlMinimalEntry ] = fmt .Sprintf ("%v:%v-minimal-bookworm" , envValue , targetMajor )
195+ }
196+
197+ return targetImages
198+ }
199+
180200 buildScenarios := func (
181201 namespace string , storageClass string , currentMajor , targetMajor uint64 ,
182202 ) map [string ]* scenario {
203+ targetImages := generateTargetImages (targetMajor )
204+
183205 return map [string ]* scenario {
184206 postgisEntry : {
185207 startingCluster : generatePostGISCluster (namespace , storageClass , int (currentMajor )),
186208 startingMajor : int (currentMajor ),
187- targetImage : fmt . Sprintf ( "ghcr.io/cloudnative-pg/postgis:%v" , targetMajor ) ,
209+ targetImage : targetImages [ postgisEntry ] ,
188210 targetMajor : int (targetMajor ),
189211 },
190212 postgresqlEntry : {
191213 startingCluster : generatePostgreSQLCluster (namespace , storageClass , int (currentMajor )),
192214 startingMajor : int (currentMajor ),
193- targetImage : fmt . Sprintf ( "ghcr.io/cloudnative-pg/postgresql:%v" , targetMajor ) ,
215+ targetImage : targetImages [ postgresqlEntry ] ,
194216 targetMajor : int (targetMajor ),
195217 },
196218 postgresqlMinimalEntry : {
197219 startingCluster : generatePostgreSQLMinimalCluster (namespace , storageClass , int (currentMajor )),
198220 startingMajor : int (currentMajor ),
199- targetImage : fmt . Sprintf ( "ghcr.io/cloudnative-pg/postgresql:%v-minimal-bookworm" , targetMajor ) ,
221+ targetImage : targetImages [ postgresqlMinimalEntry ] ,
200222 targetMajor : int (targetMajor ),
201223 },
202224 }
@@ -285,6 +307,14 @@ var _ = Describe("Postgres Major Upgrade", Label(tests.LabelPostgresMajorUpgrade
285307
286308 DescribeTable ("can upgrade a Cluster to a newer major version" , func (scenarioName string ) {
287309 By ("Creating the starting cluster" )
310+ // Avoid running Postgis major upgrade tests when a custom registry is being specified, because our
311+ // PostGIS images are still based on Debian bullseye which uses OpenSSL 1.1, thus making them incompatible
312+ // with any other image that uses OpenSSL 3.0 or greater.
313+ // TODO: remove once we have PostGIS bookworm images
314+ if scenarioName == postgisEntry && os .Getenv (customImageRegistryEnvVar ) != "" {
315+ Skip ("Skipping PostGIS major upgrades when a custom registry is specified" )
316+ }
317+
288318 scenario := scenarios [scenarioName ]
289319 cluster := scenario .startingCluster
290320 err := env .Client .Create (env .Ctx , cluster )
0 commit comments