Skip to content

Conversation

@marceloneppel
Copy link
Member

@marceloneppel marceloneppel commented Jun 30, 2022

Issue

  • Both the PostgreSQL k8s charm and the workload it runs (Patroni) create some k8s resources that are not removed when the application is removed from a model.
  • This causes some issues to a new deployment of the charm in the same model later (Patroni can't elect a leader for the cluster).

Solution

  • During the charm stop event (application removal), remove the resources created by the PostgreSQL k8s charm and also the resources that were created by Patroni.

Context

  • In charm.py, the on stop event removes the k8s resources created in on install and also by Patroni.
  • In the on stop hook the leader unit was not checked because the leadership changes during the removal and sometimes if it is checked before we can do the resources removal we end up removing nothing.
  • In resources.yaml two unneeded resources were removed.
  • Some helpers were created for the integration tests.
  • Integration tests were added for checking that the right resources are created and then later removed.
  • Some details in the tests will be improved in the future, specially the charm build process (we should a fixture, and also update the other tests that are building the charm).

Testing

  • New integration tests were implemented to test that the correct resources were created when the application is deployed and also to test that all of them are removed when the application is removed from the model.
  • There is also a new test that checks that it works after being removed and deployed again in the same model.

Release Notes

  • Remove k8s resources created by the PostgreSQL k8s charm and Patroni when the application is removed.

@marceloneppel marceloneppel marked this pull request as ready for review August 26, 2022 19:30
Copy link
Contributor

@shayancanonical shayancanonical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@marceloneppel marceloneppel merged commit 90d4778 into main Aug 29, 2022
@marceloneppel marceloneppel deleted the DPE-466-remove-k8s-resources branch August 29, 2022 16:42
github-actions bot added a commit to canonical/test-runners-2-github-x64-postgresql-k8s-operator that referenced this pull request May 14, 2024
BON4 pushed a commit to BON4/postgresql-k8s-operator that referenced this pull request May 20, 2024
* Add k8s resources cleanup

* Improve code

* Uncomment previous tests

* Remove duplicated and imcomplete test

* Fix imports order

* Minor fixes

* Test idle period

* Test lib versions

* Change

* Remove version test

* Revert change

* Revert change

* Revert change

* Uncomment tests

* Fix CI workflow

* Fix tests

* Add test about redeployment

* Revert some test changes

* Improve code

* Fix docstring

* Add pytest marks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants