fix: db connection string lifecycle issues #45
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #37, #42
The underlying issue is that at times, the charm loses state and reverts to original configuration values. When this happens, we were losing the connection string, as the
_waiting_for_database_relation
flag and the_env_vars
we pass into the container were being reset.This change now has
__init__
check for existing db relations, and if one is found, skip setting the_waiting_for_database_relation
flag and go straight to setting up and passing in the connection string.I also added steps to the lifecycle tests that cold boot the charm and swap out ports while connected to the db to ensure we return to a running state and can reach the container.
In the future I want to rework this to trigger on supplying a db_name as config, but until we need to support metrics, I think we can kick the can down the road.