@@ -42,11 +42,20 @@ public class ClusterPostgresVersionContextAppender
4242 + " with CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY that"
4343 + " could cause silent data corruption of indexes. For more info"
4444 + " see https://www.postgresql.org/about/news/postgresql-144-released-2470/." ;
45+ private static final String REPLICATION_SLOTS_INVALIDATION_BUG =
46+ "A bug was introduced in Postgres versions 17.5, 16.9, 15.13, 14.18 and 13.21"
47+ + " that can invalidate logical replication slots. For more info see"
48+ + " https://www.postgresql.org/message-id/flat/680bdaf6-f7d1-4536-b580-05c2760c67c6%40deepbluecap.com" ;
4549 public static final Map <String , String > BUGGY_PG_VERSIONS = Map .ofEntries (
4650 Map .entry ("14.0" , PG_14_CREATE_CONCURRENT_INDEX_BUG ),
4751 Map .entry ("14.1" , PG_14_CREATE_CONCURRENT_INDEX_BUG ),
4852 Map .entry ("14.2" , PG_14_CREATE_CONCURRENT_INDEX_BUG ),
49- Map .entry ("14.3" , PG_14_CREATE_CONCURRENT_INDEX_BUG )
53+ Map .entry ("14.3" , PG_14_CREATE_CONCURRENT_INDEX_BUG ),
54+ Map .entry ("13.21" , REPLICATION_SLOTS_INVALIDATION_BUG ),
55+ Map .entry ("14.18" , REPLICATION_SLOTS_INVALIDATION_BUG ),
56+ Map .entry ("15.13" , REPLICATION_SLOTS_INVALIDATION_BUG ),
57+ Map .entry ("16.9" , REPLICATION_SLOTS_INVALIDATION_BUG ),
58+ Map .entry ("17.5" , REPLICATION_SLOTS_INVALIDATION_BUG )
5059 );
5160
5261 private final Map <StackGresComponent , Map <StackGresVersion , List <String >>>
@@ -99,11 +108,11 @@ public void appendContext(StackGresCluster cluster, Builder contextBuilder) {
99108 if (cluster .getStatus () == null ) {
100109 cluster .setStatus (new StackGresClusterStatus ());
101110 }
102- Optional <String > previousVersion = Optional .ofNullable (cluster .getStatus ())
111+ final Optional <String > previousVersion = Optional .ofNullable (cluster .getStatus ())
103112 .map (StackGresClusterStatus ::getPostgresVersion );
104- Optional <String > previousBuildVersion = Optional .ofNullable (cluster .getStatus ())
113+ final Optional <String > previousBuildVersion = Optional .ofNullable (cluster .getStatus ())
105114 .map (StackGresClusterStatus ::getBuildVersion );
106- boolean isRolloutAllowed = ClusterRolloutUtil .isRolloutAllowed (cluster );
115+ final boolean isRolloutAllowed = ClusterRolloutUtil .isRolloutAllowed (cluster );
107116 if (isRolloutAllowed
108117 && (
109118 cluster .getMetadata ().getAnnotations () == null
@@ -121,11 +130,37 @@ public void appendContext(StackGresCluster cluster, Builder contextBuilder) {
121130 .append (Map .entry (StackGresContext .VERSION_KEY , StackGresProperty .OPERATOR_VERSION .getString ()))
122131 .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
123132 }
124- String postgresVersion = previousVersion .filter (version -> !isRolloutAllowed )
125- .orElseGet (() -> Optional .ofNullable (cluster .getSpec ())
126- .map (StackGresClusterSpec ::getPostgres )
127- .map (StackGresClusterPostgres ::getVersion )
128- .orElse (StackGresComponent .LATEST ));
133+ String targetPostgresVersion = Optional .ofNullable (cluster .getSpec ())
134+ .map (StackGresClusterSpec ::getPostgres )
135+ .map (StackGresClusterPostgres ::getVersion )
136+ .orElse (StackGresComponent .LATEST );
137+
138+ if (!isPostgresVersionSupported (cluster , targetPostgresVersion )) {
139+ eventController .sendEvent (
140+ ClusterEventReason .CLUSTER_SECURITY_WARNING ,
141+ "Unsupported postgres version " + targetPostgresVersion
142+ + ". Supported postgres versions are: "
143+ + Seq .seq (supportedPostgresVersions .get (getPostgresFlavorComponent (cluster ))
144+ .get (StackGresVersion .getStackGresVersion (cluster )))
145+ .toString (", " ),
146+ cluster );
147+ }
148+
149+ Optional <String > targetVersion = getPostgresFlavorComponent (cluster )
150+ .get (cluster )
151+ .findVersion (targetPostgresVersion );
152+
153+ if (targetVersion .map (BUGGY_PG_VERSIONS .keySet ()::contains ).orElse (false )) {
154+ eventController .sendEvent (
155+ ClusterEventReason .CLUSTER_SECURITY_WARNING ,
156+ "Do not use PostgreSQL " + targetVersion .get () + ". "
157+ + BUGGY_PG_VERSIONS .get (targetVersion .get ()),
158+ cluster );
159+ }
160+
161+ String postgresVersion = previousVersion
162+ .filter (version -> !isRolloutAllowed )
163+ .orElse (targetPostgresVersion );
129164
130165 if (!isPostgresVersionSupported (cluster , postgresVersion )) {
131166 throw new IllegalArgumentException (
@@ -143,7 +178,8 @@ public void appendContext(StackGresCluster cluster, Builder contextBuilder) {
143178 .get (cluster )
144179 .getBuildVersion (postgresVersion );
145180
146- if (BUGGY_PG_VERSIONS .keySet ().contains (version )) {
181+ if (BUGGY_PG_VERSIONS .keySet ().contains (version )
182+ && Objects .equals (Optional .of (version ), previousVersion )) {
147183 throw new IllegalArgumentException (
148184 "Do not use PostgreSQL " + version + ". "
149185 + BUGGY_PG_VERSIONS .get (version ));
0 commit comments