|
65 | 65 | RelationDepartedEvent, |
66 | 66 | SecretChangedEvent, |
67 | 67 | SecretNotFoundError, |
| 68 | + SecretRemoveEvent, |
68 | 69 | Unit, |
69 | 70 | UnknownStatus, |
70 | 71 | WaitingStatus, |
@@ -247,6 +248,7 @@ def __init__(self, *args): |
247 | 248 | self.framework.observe(self.on.promote_to_primary_action, self._on_promote_to_primary) |
248 | 249 | self.framework.observe(self.on.get_primary_action, self._on_get_primary) |
249 | 250 | self.framework.observe(self.on.update_status, self._on_update_status) |
| 251 | + self.framework.observe(self.on.secret_remove, self._on_secret_remove) |
250 | 252 |
|
251 | 253 | self._certs_path = "/usr/local/share/ca-certificates" |
252 | 254 | self._storage_path = str(self.meta.storages["data"].location) |
@@ -1439,6 +1441,17 @@ def promote_primary_unit(self, event: ActionEvent) -> None: |
1439 | 1441 | except SwitchoverFailedError: |
1440 | 1442 | event.fail("Switchover failed or timed out, check the logs for details") |
1441 | 1443 |
|
| 1444 | + def _on_secret_remove(self, event: SecretRemoveEvent) -> None: |
| 1445 | + # A secret removal (entire removal, not just a revision removal) causes |
| 1446 | + # https://github.com/juju/juju/issues/20794. This check is to avoid the |
| 1447 | + # errors that would happen if we tried to remove the revision in that case |
| 1448 | + # (in the revision removal, the label is present). |
| 1449 | + if event.secret.label is None: |
| 1450 | + logger.debug("Secret with no label cannot be removed") |
| 1451 | + return |
| 1452 | + logger.debug(f"Removing secret with label {event.secret.label} revision {event.revision}") |
| 1453 | + event.remove_revision() |
| 1454 | + |
1442 | 1455 | def _on_get_primary(self, event: ActionEvent) -> None: |
1443 | 1456 | """Get primary instance.""" |
1444 | 1457 | try: |
|
0 commit comments