Bundle deploy not working for Kubernetes (using Mattermost + PostgreSQL Charms)

Hi there,

I tried to use the a bundle.yaml file to deploy Mattermost + PostgreSQL together, but failed.

First, I deployed them manually following the Mattermost docs and used the juju export-bundle > file.yaml command to generate a Bundle file.

Later, I removed the applications and tried to deploy using the command juju deploy file.yaml and got the following error:

$ juju debug-log

application-postgresql: 15:34:09 ERROR unit.postgresql/8.juju-log db:11: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 237, in <module>
    ops.main.main(PostgreSQLCharm, use_juju_for_storage=True)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/main.py", line 402, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/main.py", line 140, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/framework.py", line 278, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/framework.py", line 722, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/framework.py", line 767, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/src/clientrel.py", line 115, in on_db_relation_changed
    req = _ClientRequests(event)
  File "/var/lib/juju/agents/unit-postgresql-8/charm/src/clientrel.py", line 234, in __init__
    buckets = [event.relation.data[event.app]]
  File "/var/lib/juju/agents/unit-postgresql-8/charm/venv/ops/model.py", line 699, in __getitem__
    return self._data[key]
KeyError: <ops.model.Application mattermost>
application-postgresql: 15:34:09 ERROR juju.worker.caasoperator.uniter.postgresql/8.operation hook "db-relation-changed" (via hook dispatching script: dispatch) failed: exit status 1
application-postgresql: 15:34:09 INFO juju.worker.caasoperator.uniter.postgresql/8 awaiting error resolution for "relation-changed" hook

Even if I nuke the whole cluster and try to deploy from the Bundle file from scratch, I got the same error.

I’m using Kind as a K8s cluster and Juju v2.9-rc6.

This looks to be Bug #1914415 “Potential race condition leads to broken applicati...” : Bugs : charm-k8s-postgresql - a fix has landed in the Operator Framework for this, and we plan to update the charm with the fix as soon as a new version of the Operator Framework is released.

You can work around this by running juju resolved --no-retry postgresql/0, or deploying with a version I built for confirming the fix works as expected, which is cs:~mthaddon/postgresql-k8s.

Let us know if it’s critical and we can potentially look into releasing a version of the charm with the fix applied before it makes it into an Operator Framework release.

This is not urgent, it affects a tutorial I’m writing for Canonical tho. Is there any expectation on when the release will be made?

It seems it could be a while until the next Operator Framework release, so we’ve updated the postgresql k8s charm to include the required version.

If you retry the bundle now (assuming you’re not pinning the charm version, it will need revno 10) it should work. I’ve just confirmed it does for me locally.