[juju secrets] Not able to retrieve a new secret in same execution hook
See original GitHub issueCreated a new juju secret and tried to retrieve the secret using id in the same hook execution resulted in SecretNotFoundError. Expectation is to get newly created secret information.
Sample code to reproduce:
def _test_secrets_action(self, event: ActionEvent) -> None:
if not self.unit.is_leader():
event.fail("Please run action on lead unit.")
return
logger.warning("test-secrets action event triggered")
secret = self.model.app.add_secret(
{'test': 'test'},
label="test-key",
)
logger.warning(f"Test Secret created: {secret.id}")
secret_ = self.model.get_secret(id=secret.id)
data = secret_.get_content()
logger.warning(f"Test secret retrieved {secret_}")
event.set_results({"secret": data})
Error logs:
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-keystone-0/charm/./src/charm.py", line 847, in <module>
main(KeystoneOperatorCharm, use_juju_for_storage=True)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/main.py", line 445, in main
_emit_charm_event(charm, dispatcher.event_name)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/main.py", line 150, in _emit_charm_event
event_to_emit.emit(*args, **kwargs)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/framework.py", line 355, in emit
framework._emit(event) # noqa
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/framework.py", line 839, in _emit
self._reemit(event_path)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/framework.py", line 914, in _reemit
custom_handler(event)
File "/var/lib/juju/agents/unit-keystone-0/charm/./src/charm.py", line 313, in _test_secrets_action
secret_ = self.model.get_secret(id=secret.id)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/model.py", line 283, in get_secret
info = self._backend.secret_info_get(id=id, label=label)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/model.py", line 2873, in secret_info_get
result = self._run_secret('secret-info-get', *args, return_output=True, use_json=True)
File "/var/lib/juju/agents/unit-keystone-0/charm/venv/ops/model.py", line 2837, in _run_secret
raise SecretNotFoundError() from e
ops.model.SecretNotFoundError
Environment details:
juju 3.0/edge + microk8s
ops framework - secrets branch
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to debug charm hooks - Juju
The juju debug-hooks command allows you to do exactly that, whether it's to debug a failed hook or to write and test new...
Read more >Juju Secrets - early access preview - Juju Discourse - Charmhub
In other cases, the charm may itself simply need to re-generate a new value for the secret. Either way, 2 hooks are used...
Read more >Operation - Go Packages
New ("saved uniter state does not exist") ErrSkipExecute = errors. ... error // SecretsRemoved updates the unit secret state when // secrets are...
Read more >View Hook Secrets - Auth0
In the Hook Editor, click the wrench icon, and click Secrets. All configured secrets for the selected Hook are listed. Get Hook Secrets...
Read more >Secrets | Kubernetes
Secrets are similar to ConfigMaps but are specifically intended ... However, this method creates a new Secret object with the edited data.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This appears to be a juju bug as I appear to be able to reproduce using the hook commands directly. We can close this issue once we determine for sure by doing a juju fix.
The fix in https://github.com/juju/juju/pull/14940 has been merged now, so closing this.