pod-spec-set will cause a new pod to be spun up and a new unit to be created, and the old pod and unit to be torn down. A side effect of this is that all relation data is also lost.
As an example, a k8s charm negotiates database credentials with a PostgreSQL server using interface:pgsql, including specifying the database name to use. The k8s charm calls pod-spec-set with the new pod spec and configuration, and terminates. The pod is spun up and a new unit created, and when the new units hooks are run its relation data is empty, and the database name to use is unset. The PostgreSQL charm at the other end also sees the old unit leave and the new unit join, and seeing that the database name has been unset, revokes access to the specified database and grants access to a default database.
Ideally, a new unit is not created and the existing relation data preserved. Only the pod would change, and relations updated with new IP network data. The charm would not need to renegotiate relations every time the config changes and a new pod spun up. Loops would be avoided, where renegotiating the relation gives different results, requiring a new pod to be spun up with the different results as config, triggering the relation data to be lost, requiring the relations to be renegotiated.
See the discussion here
https:/ /discourse. jujucharms. com/t/trying- to-wrap- my-head- around- k8s-charms- pod-spec- set-creates- new-agent- and-removes- old-one/ 1384/10
The issue is that for stateless deployments, k8s itself treats pods as disposable and that interferes with Juju's more stateful assumptions about unit behaviour.
The TL:DR; is that:
- charms now have a capability to specifically request a stateful deployment if they care about preserving relation data, see "Charms Can Specify Deployment Type" /discourse. jujucharms. com/t/whats- new-in- juju-k8s- for-2-6/ 1431
https:/
- in juju 2.7, we are moving to a support a more application centric view and adding an application level relation databag. This is obviously managed independently of any unit lifecycle and so units can come and go and the data is preserved.