From 43d2a96bbd01870681be48af3d860f4a37169109 Mon Sep 17 00:00:00 2001 From: Kian Parvin <46668016+kian99@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:01:00 +0200 Subject: [PATCH 1/2] Checkout without shallow to grab tags (#1009) --- .github/workflows/charm-release.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/charm-release.yaml b/.github/workflows/charm-release.yaml index 589f471d1..7116e4390 100644 --- a/.github/workflows/charm-release.yaml +++ b/.github/workflows/charm-release.yaml @@ -28,6 +28,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Build local images run: make jimm-image - name: Upload charm to charmhub @@ -51,6 +53,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - uses: actions/download-artifact@master with: name: jimm-snap From b0bf50977b5d3fdf7b17a90de71c4d99f4f05323 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Fri, 28 Jul 2023 13:54:20 +0100 Subject: [PATCH 2/2] Defer database event when `username` is `None` (#1005) * Defer database event when `username` is `None` Signed-off-by: Babak K. Shandiz * Check for `event.password` being None Signed-off-by: Babak K. Shandiz * Fix lint issues Signed-off-by: Babak K. Shandiz * Set `ops >= 2.0.0` to match data platforms lib requirements Signed-off-by: Babak K. Shandiz --------- Signed-off-by: Babak K. Shandiz Co-authored-by: Kian Parvin <46668016+kian99@users.noreply.github.com> --- charms/jimm-k8s/src/charm.py | 8 ++++++++ charms/jimm/requirements.txt | 2 +- charms/jimm/src/charm.py | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/charms/jimm-k8s/src/charm.py b/charms/jimm-k8s/src/charm.py index 5563607e7..6a8e1cf24 100755 --- a/charms/jimm-k8s/src/charm.py +++ b/charms/jimm-k8s/src/charm.py @@ -316,6 +316,14 @@ def _on_dashboard_relation_joined(self, event: RelationJoinedEvent): def _on_database_event(self, event: DatabaseEvent) -> None: """Database event handler.""" + if event.username is None or event.password is None: + event.defer() + logger.info( + "(postgresql) Relation data is not complete (missing `username` or `password` field); " + "deferring the event." + ) + return + # get the first endpoint from a comma separate list ep = event.endpoints.split(",", 1)[0] # compose the db connection string diff --git a/charms/jimm/requirements.txt b/charms/jimm/requirements.txt index b7e096739..e88b52afa 100644 --- a/charms/jimm/requirements.txt +++ b/charms/jimm/requirements.txt @@ -1,6 +1,6 @@ markupsafe>=2.0.1 Jinja2 >= 2.11.3 -ops >= 1.4.0 +ops >= 2.0.0 charmhelpers >= 0.20.22 hvac >= 0.11.0 pydantic == 1.10.10 diff --git a/charms/jimm/src/charm.py b/charms/jimm/src/charm.py index b98b4b8fc..dd5d3178a 100755 --- a/charms/jimm/src/charm.py +++ b/charms/jimm/src/charm.py @@ -161,6 +161,14 @@ def _on_database_event(self, event: DatabaseRequiresEvent): event.defer() return + if event.username is None or event.password is None: + event.defer() + logger.info( + "(postgresql) Relation data is not complete (missing `username` or `password` field); " + "deferring the event." + ) + return + # get the first endpoint from a comma separate list host = event.endpoints.split(",", 1)[0] # compose the db connection string