|
68 | 68 | HookEvent, |
69 | 69 | LeaderElectedEvent, |
70 | 70 | RelationDepartedEvent, |
| 71 | + SecretRemoveEvent, |
71 | 72 | WorkloadEvent, |
72 | 73 | ) |
73 | 74 | from ops.model import ( |
@@ -238,6 +239,7 @@ def __init__(self, *args): |
238 | 239 | self.framework.observe(self.on.promote_to_primary_action, self._on_promote_to_primary) |
239 | 240 | self.framework.observe(self.on.get_primary_action, self._on_get_primary) |
240 | 241 | self.framework.observe(self.on.update_status, self._on_update_status) |
| 242 | + self.framework.observe(self.on.secret_remove, self._on_secret_remove) |
241 | 243 |
|
242 | 244 | self._certs_path = "/usr/local/share/ca-certificates" |
243 | 245 | self._storage_path = self.meta.storages["pgdata"].location |
@@ -1359,6 +1361,17 @@ def promote_primary_unit(self, event: ActionEvent) -> None: |
1359 | 1361 | except SwitchoverFailedError: |
1360 | 1362 | event.fail("Switchover failed or timed out, check the logs for details") |
1361 | 1363 |
|
| 1364 | + def _on_secret_remove(self, event: SecretRemoveEvent) -> None: |
| 1365 | + # A secret removal (entire removal, not just a revision removal) causes |
| 1366 | + # https://github.com/juju/juju/issues/20794. This check is to avoid the |
| 1367 | + # errors that would happen if we tried to remove the revision in that case |
| 1368 | + # (in the revision removal, the label is present). |
| 1369 | + if event.secret.label is None: |
| 1370 | + logger.debug("Secret with no label cannot be removed") |
| 1371 | + return |
| 1372 | + logger.debug(f"Removing secret with label {event.secret.label} revision {event.revision}") |
| 1373 | + event.remove_revision() |
| 1374 | + |
1362 | 1375 | def _on_get_primary(self, event: ActionEvent) -> None: |
1363 | 1376 | """Get primary instance.""" |
1364 | 1377 | try: |
|
0 commit comments