-
Notifications
You must be signed in to change notification settings - Fork 0
AB-449 Fix flaky tests and properly clean up resources #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a121886
1f7bd23
454a4b1
3423a1e
d400d37
7649ee5
491097a
793901a
950fe50
b8b6612
e9448d1
58ce8f8
9308661
8d6b540
423723f
b785a48
0792764
9d6a45e
fc72b1d
958e0f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ public Set<Privilege> determineCurrentDefaultPrivileges( | |
| DSLContext tx, | ||
| DefaultPrivilegeSpec spec | ||
| ) { | ||
| var owner = spec.getOwner(); | ||
|
||
| var role = spec.getRole(); | ||
| var schema = spec.getSchema(); | ||
|
|
||
|
|
@@ -65,6 +66,11 @@ public Set<Privilege> determineCurrentDefaultPrivileges( | |
| .from(PG_DEFAULT_ACL) | ||
| .crossJoin(Routines.aclexplode(PG_DEFAULT_ACL.DEFACLACL)) | ||
| .where( | ||
| PG_DEFAULT_ACL.DEFACLROLE.eq(field( | ||
| ROLE_OID_SQL, | ||
| OID_DATA_TYPE, | ||
| val(owner) | ||
| )), | ||
| PG_DEFAULT_ACL.DEFACLOBJTYPE.eq(objectType.objectTypeChar()), | ||
| objectType == SCHEMA | ||
| ? noCondition() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,8 @@ public static String randomKubernetesNameSuffix(String name) { | |
| } | ||
|
|
||
| var separator = "-"; | ||
| var suffixLength = maxLength - name.length() - separator.length(); | ||
| var availableSpace = maxLength - name.length() - separator.length(); | ||
| var suffixLength = Math.min(7, availableSpace); | ||
|
Comment on lines
+65
to
+66
|
||
|
|
||
| return name + separator + FAKER.regexify("[a-z0-9]{%d}".formatted(suffixLength)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package it.aboutbits.postgresql._support.testdata.base; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.HasMetadata; | ||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import it.aboutbits.postgresql.crd.clusterconnection.ClusterConnection; | ||
| import it.aboutbits.postgresql.crd.database.Database; | ||
| import it.aboutbits.postgresql.crd.defaultprivilege.DefaultPrivilege; | ||
| import it.aboutbits.postgresql.crd.grant.Grant; | ||
| import it.aboutbits.postgresql.crd.role.Role; | ||
| import it.aboutbits.postgresql.crd.schema.Schema; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| @NullMarked | ||
| public final class TestUtil { | ||
| public static void resetEnvironment(KubernetesClient kubernetesClient) { | ||
| // Reverse Dependency Deletion | ||
| deleteResource(kubernetesClient, DefaultPrivilege.class); | ||
| deleteResource(kubernetesClient, Grant.class); | ||
| deleteResource(kubernetesClient, Schema.class); | ||
| deleteResource(kubernetesClient, Role.class); | ||
| deleteResource(kubernetesClient, Database.class); | ||
| deleteResource(kubernetesClient, ClusterConnection.class); | ||
| } | ||
|
|
||
| public static void deleteResource( | ||
| KubernetesClient kubernetesClient, | ||
| Class<? extends HasMetadata> resourceClass | ||
| ) { | ||
| // Async call to the Kubernetes API Server that triggers the Operator Controllers | ||
| kubernetesClient.resources(resourceClass).delete(); | ||
|
|
||
| // Wait for the Operator Controller to finish the CR cleanup | ||
| await().atMost(5, TimeUnit.SECONDS) | ||
| .pollInterval(100, TimeUnit.MILLISECONDS) | ||
| .until(() -> kubernetesClient.resources(resourceClass).list().getItems().isEmpty()); | ||
| } | ||
|
|
||
| private TestUtil() { | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup method now connects to a specific database rather than the default connection. If the database doesn't exist or is inaccessible during cleanup, this could cause the cleanup to fail. Consider handling potential connection failures gracefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already handle any errors in the CRD and show the error in the CRStatus and logs.
I don't think there's a graceful way to handle a missing database when it was deleted from the RDBMS.