Skip to content

Commit 0e29e0e

Browse files
committed
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
1 parent d393710 commit 0e29e0e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/upgrade.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,27 @@ def _remove_secrets_old_revisions(self) -> None:
271271
"""Remove secrets' old revisions."""
272272
if self.charm.unit.is_leader():
273273
secret = self.charm.model.get_secret(label=f"{PEER}.{self.charm.app.name}.app")
274-
secret_id = secret.get_info().id
275274
latest_revision = secret.get_info().revision
275+
# We need to trick Juju into thinking that we are not running in a hook context,
276+
# as Juju will disallow use of juju-run / juju-exec.
276277
new_env = os.environ.copy()
277278
if "JUJU_CONTEXT_ID" in new_env:
278279
new_env.pop("JUJU_CONTEXT_ID")
279280
for revision in range(1, latest_revision):
281+
if str(latest_revision).startswith(str(revision)):
282+
# Skip if the revision is a prefix of the latest revision.
283+
logger.info(
284+
f"Skipping secret revision {revision} because it's the prefix of the latest revision (see https://github.com/juju/juju/issues/20782)"
285+
)
286+
continue
280287
command = [
281288
self.run_cmd,
282289
self.charm.unit.name,
283290
"--",
284291
"secret-remove",
285292
"--revision",
286293
str(revision),
287-
secret_id,
294+
secret.get_info().id,
288295
]
289296
# Input comes from the charm.
290297
subprocess.Popen(command, env=new_env) # noqa: S603

0 commit comments

Comments
 (0)