Skip to content

Commit 86cbc2c

Browse files
committed
implement review feedback
1 parent e3880de commit 86cbc2c

5 files changed

Lines changed: 50 additions & 20 deletions

File tree

operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class ClusterConnectionSpec {
1919
@Required
2020
@ValidationRule(
21-
value = "self.size() > 0",
21+
value = "self.trim().size() > 0",
2222
message = "The ClusterConnection host must not be empty."
2323
)
2424
private String host = "";
@@ -30,7 +30,7 @@ public class ClusterConnectionSpec {
3030

3131
@Required
3232
@ValidationRule(
33-
value = "self.size() > 0",
33+
value = "self.trim().size() > 0",
3434
message = "The ClusterConnection database must not be empty."
3535
)
3636
private String database = "postgres";

operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseReconciler.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public DeleteControl cleanup(
115115
if (spec.getReclaimPolicy() == ReclaimPolicy.DELETE) {
116116
status.setMessage("Database deletion in progress");
117117
}
118+
119+
context.getClient().resource(resource).patchStatus();
118120
}
119121

120122
// We do not actually delete the database if the reclaimPolicy is set to RETAIN, we only delete the CR instance
@@ -136,6 +138,8 @@ public DeleteControl cleanup(
136138
clusterRef.getName()
137139
));
138140

141+
context.getClient().resource(resource).patchStatus();
142+
139143
return DeleteControl.noFinalizerRemoval()
140144
.rescheduleAfter(60, TimeUnit.SECONDS);
141145
}
@@ -148,15 +152,19 @@ public DeleteControl cleanup(
148152
return DeleteControl.defaultDelete();
149153
} catch (Exception e) {
150154
log.error(
151-
"Failed to delete Database [resource={}/{}, spec.name={}, status.phase={}]",
152-
namespace,
153-
name,
154-
spec.getName(),
155-
status.getPhase()
155+
"Failed to delete Database [resource=%s/%s, spec.name=%s, status.phase=%s]".formatted(
156+
namespace,
157+
name,
158+
spec.getName(),
159+
status.getPhase()
160+
),
161+
e
156162
);
157163

158164
status.setMessage("Deletion failed: %s".formatted(e.getMessage()));
159165

166+
context.getClient().resource(resource).patchStatus();
167+
160168
return DeleteControl.noFinalizerRemoval()
161169
.rescheduleAfter(60, TimeUnit.SECONDS);
162170
}
@@ -177,7 +185,7 @@ private UpdateControl<Database> reconcile(
177185

178186
var spec = resource.getSpec();
179187

180-
// Create and return the role if it doesn't exist yet
188+
// Create and return the database if it doesn't exist yet
181189
if (!databaseService.databaseExists(dsl, spec)) {
182190
log.info(
183191
"Creating Database [resource={}/{}]",

operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantReconciler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public UpdateControl<Grant> reconcile(
122122
public DeleteControl cleanup(
123123
Grant resource,
124124
Context<Grant> context
125-
) throws Exception {
125+
) {
126126
var spec = resource.getSpec();
127127
var status = initializeStatus(resource);
128128

@@ -139,6 +139,8 @@ public DeleteControl cleanup(
139139
if (status.getPhase() != CRPhase.DELETING) {
140140
status.setPhase(CRPhase.DELETING)
141141
.setMessage("Grant deletion in progress");
142+
143+
context.getClient().resource(resource).patchStatus();
142144
}
143145

144146
var clusterRef = spec.getClusterRef();
@@ -155,6 +157,8 @@ public DeleteControl cleanup(
155157
clusterRef.getName()
156158
));
157159

160+
context.getClient().resource(resource).patchStatus();
161+
158162
return DeleteControl.noFinalizerRemoval()
159163
.rescheduleAfter(60, TimeUnit.SECONDS);
160164
}
@@ -191,6 +195,8 @@ public DeleteControl cleanup(
191195

192196
status.setMessage("Deletion failed: %s".formatted(e.getMessage()));
193197

198+
context.getClient().resource(resource).patchStatus();
199+
194200
return DeleteControl.noFinalizerRemoval()
195201
.rescheduleAfter(60, TimeUnit.SECONDS);
196202
}

operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleReconciler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public DeleteControl cleanup(
145145
if (status.getPhase() != CRPhase.DELETING) {
146146
status.setPhase(CRPhase.DELETING)
147147
.setMessage("Role deletion in progress");
148+
149+
context.getClient().resource(resource).patchStatus();
148150
}
149151

150152
var clusterRef = spec.getClusterRef();
@@ -161,6 +163,8 @@ public DeleteControl cleanup(
161163
clusterRef.getName()
162164
));
163165

166+
context.getClient().resource(resource).patchStatus();
167+
164168
return DeleteControl.noFinalizerRemoval()
165169
.rescheduleAfter(60, TimeUnit.SECONDS);
166170
}
@@ -173,15 +177,19 @@ public DeleteControl cleanup(
173177
return DeleteControl.defaultDelete();
174178
} catch (Exception e) {
175179
log.error(
176-
"Failed to delete Role [resource={}/{}, spec.name={}, status.phase={}]",
177-
namespace,
178-
name,
179-
spec.getName(),
180-
status.getPhase()
180+
"Failed to delete Role [resource=%s/%s, spec.name=%s, status.phase=%s]".formatted(
181+
namespace,
182+
name,
183+
spec.getName(),
184+
status.getPhase()
185+
),
186+
e
181187
);
182188

183189
status.setMessage("Deletion failed: %s".formatted(e.getMessage()));
184190

191+
context.getClient().resource(resource).patchStatus();
192+
185193
return DeleteControl.noFinalizerRemoval()
186194
.rescheduleAfter(60, TimeUnit.SECONDS);
187195
}

operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaReconciler.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public DeleteControl cleanup(
117117
if (spec.getReclaimPolicy() == ReclaimPolicy.DELETE) {
118118
status.setMessage("Schema deletion in progress");
119119
}
120+
121+
context.getClient().resource(resource).patchStatus();
120122
}
121123

122124
// We do not actually delete the schema if the reclaimPolicy is set to RETAIN, we only delete the CR instance
@@ -138,6 +140,8 @@ public DeleteControl cleanup(
138140
clusterRef.getName()
139141
));
140142

143+
context.getClient().resource(resource).patchStatus();
144+
141145
return DeleteControl.noFinalizerRemoval()
142146
.rescheduleAfter(60, TimeUnit.SECONDS);
143147
}
@@ -150,15 +154,19 @@ public DeleteControl cleanup(
150154
return DeleteControl.defaultDelete();
151155
} catch (Exception e) {
152156
log.error(
153-
"Failed to delete Schema [resource={}/{}, spec.name={}, status.phase={}]",
154-
namespace,
155-
name,
156-
spec.getName(),
157-
status.getPhase()
157+
"Failed to delete Schema [resource=%s/%s, spec.name=%s, status.phase=%s]".formatted(
158+
namespace,
159+
name,
160+
spec.getName(),
161+
status.getPhase()
162+
),
163+
e
158164
);
159165

160166
status.setMessage("Deletion failed: %s".formatted(e.getMessage()));
161167

168+
context.getClient().resource(resource).patchStatus();
169+
162170
return DeleteControl.noFinalizerRemoval()
163171
.rescheduleAfter(60, TimeUnit.SECONDS);
164172
}
@@ -179,7 +187,7 @@ private UpdateControl<Schema> reconcileInTransaction(
179187

180188
var spec = resource.getSpec();
181189

182-
// Create and return the role if it doesn't exist yet
190+
// Create and return the schema if it doesn't exist yet
183191
if (!schemaService.schemaExists(tx, spec)) {
184192
log.info(
185193
"Creating Schema [resource={}/{}]",

0 commit comments

Comments
 (0)