|
17 | 17 |
|
18 | 18 | import java.util.ArrayList; |
19 | 19 | import java.util.List; |
20 | | -import java.util.Objects; |
21 | 20 | import java.util.concurrent.TimeUnit; |
22 | 21 |
|
| 22 | +import static it.aboutbits.postgresql.core.ReclaimPolicy.DELETE; |
| 23 | + |
23 | 24 | @NullMarked |
24 | 25 | @Setter |
25 | 26 | @Accessors(fluent = true, chain = true) |
@@ -161,57 +162,89 @@ private String getName() { |
161 | 162 | } |
162 | 163 |
|
163 | 164 | private String getClusterConnectionName() { |
164 | | - return Objects.requireNonNullElse( |
165 | | - withClusterConnectionName, |
166 | | - "test-cluster-connection" |
167 | | - ); |
| 165 | + if (withClusterConnectionName != null) { |
| 166 | + return withClusterConnectionName; |
| 167 | + } |
| 168 | + |
| 169 | + var clusterConnection = given.one() |
| 170 | + .clusterConnection() |
| 171 | + .returnFirst(); |
| 172 | + |
| 173 | + withClusterConnectionNamespace = clusterConnection.getMetadata().getNamespace(); |
| 174 | + |
| 175 | + return clusterConnection.getMetadata().getName(); |
168 | 176 | } |
169 | 177 |
|
170 | 178 | private String getDatabase() { |
171 | 179 | if (withDatabase != null) { |
172 | 180 | return withDatabase; |
173 | 181 | } |
174 | 182 |
|
175 | | - return given.one() |
| 183 | + var item = given.one() |
176 | 184 | .database() |
177 | | - .returnFirst() |
178 | | - .getSpec() |
179 | | - .getName(); |
| 185 | + .withClusterConnectionName(getClusterConnectionName()) |
| 186 | + .withClusterConnectionNamespace(withClusterConnectionNamespace) |
| 187 | + .withReclaimPolicy(DELETE) |
| 188 | + .returnFirst(); |
| 189 | + |
| 190 | + withDatabase = item.getSpec().getName(); |
| 191 | + |
| 192 | + return withDatabase; |
180 | 193 | } |
181 | 194 |
|
182 | 195 | private String getRole() { |
183 | 196 | if (withRole != null) { |
184 | 197 | return withRole; |
185 | 198 | } |
186 | 199 |
|
187 | | - return given.one() |
| 200 | + var item = given.one() |
188 | 201 | .role() |
189 | | - .returnFirst() |
190 | | - .getSpec() |
191 | | - .getName(); |
| 202 | + .withClusterConnectionName(getClusterConnectionName()) |
| 203 | + .withClusterConnectionNamespace(withClusterConnectionNamespace) |
| 204 | + .returnFirst(); |
| 205 | + |
| 206 | + withRole = item.getSpec().getName(); |
| 207 | + |
| 208 | + return withRole; |
192 | 209 | } |
193 | 210 |
|
194 | 211 | private String getOwner() { |
195 | 212 | if (withOwner != null) { |
196 | 213 | return withOwner; |
197 | 214 | } |
198 | 215 |
|
199 | | - return given.one() |
| 216 | + var item = given.one() |
200 | 217 | .role() |
201 | | - .returnFirst() |
202 | | - .getSpec() |
203 | | - .getName(); |
| 218 | + .withClusterConnectionName(getClusterConnectionName()) |
| 219 | + .withClusterConnectionNamespace(withClusterConnectionNamespace) |
| 220 | + .returnFirst(); |
| 221 | + |
| 222 | + withOwner = item.getSpec().getName(); |
| 223 | + |
| 224 | + return withOwner; |
204 | 225 | } |
205 | 226 |
|
206 | 227 | private String getSchema() { |
207 | 228 | if (withSchema != null) { |
208 | 229 | return withSchema; |
209 | 230 | } |
210 | 231 |
|
211 | | - return given.one() |
| 232 | + var clusterConnectionDb = given.one() |
| 233 | + .clusterConnection() |
| 234 | + .withName(getClusterConnectionName() + "-db") |
| 235 | + .withNamespace(withClusterConnectionNamespace) |
| 236 | + .withDatabase(getDatabase()) |
| 237 | + .returnFirst(); |
| 238 | + |
| 239 | + var item = given.one() |
212 | 240 | .schema() |
213 | | - .returnFirst() |
214 | | - .getSpec() |
215 | | - .getName(); |
| 241 | + .withClusterConnectionName(clusterConnectionDb.getMetadata().getName()) |
| 242 | + .withClusterConnectionNamespace(clusterConnectionDb.getMetadata().getNamespace()) |
| 243 | + .withReclaimPolicy(DELETE) |
| 244 | + .returnFirst(); |
| 245 | + |
| 246 | + withSchema = item.getSpec().getName(); |
| 247 | + |
| 248 | + return withSchema; |
216 | 249 | } |
217 | 250 | } |
0 commit comments