From 6cd096b78b2e35e9a8231d087edefa62f996775a Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Wed, 7 Feb 2024 19:10:23 +0100 Subject: [PATCH 01/10] Uses BlockedStatus instead of ErrorStatus, which when set explicitly results in an error with the new version of Ops. --- src/charm.py | 5 +++-- tests/test_charm.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index 302014b..43a5e1e 100755 --- a/src/charm.py +++ b/src/charm.py @@ -12,7 +12,7 @@ from ops.framework import StoredState from ops.charm import RelationJoinedEvent, RelationDepartedEvent from ops.main import main -from ops.model import ActiveStatus, BlockedStatus, ErrorStatus, Relation +from ops.model import ActiveStatus, BlockedStatus, Relation from typing import List logger = logging.getLogger(__name__) @@ -84,7 +84,8 @@ def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent): try: api_port = self.api_port() except AgentConfException as e: - self.unit.status = ErrorStatus(f"can't read controller API port from agent.conf: {e}") + self.unit.status = BlockedStatus( + f"can't read controller API port from agent.conf: {e}") return metrics_endpoint = MetricsEndpointProvider( diff --git a/tests/test_charm.py b/tests/test_charm.py index 3d51315..b970ea8 100644 --- a/tests/test_charm.py +++ b/tests/test_charm.py @@ -4,7 +4,7 @@ import os import unittest from charm import JujuControllerCharm, AgentConfException -from ops import ErrorStatus +from ops import BlockedStatus from ops.testing import Harness from unittest.mock import mock_open, patch @@ -140,7 +140,7 @@ def test_apiaddresses_missing_status(self, *_): harness.begin() harness.add_relation('metrics-endpoint', 'prometheus-k8s') - self.assertEqual(harness.charm.unit.status, ErrorStatus( + self.assertEqual(harness.charm.unit.status, BlockedStatus( "can't read controller API port from agent.conf: agent.conf key 'apiaddresses' missing" )) From 209f9c8a0be7ac4cacb86f5fc4f227fcf2bf39c3 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Sat, 10 Feb 2024 14:35:40 +0100 Subject: [PATCH 02/10] Updates charm metadata with correct Juju version restriction. --- metadata.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.yaml b/metadata.yaml index ea1f386..8e62e76 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -2,7 +2,7 @@ # Licensed under the GPLv3, see LICENSE file for details. name: juju-controller assumes: -- juju >= 3.3 +- juju >= 3.5 description: | The Juju controller charm is used to expose various pieces of functionality of a Juju controller. From bac5d77f4aabed82a3374b42e9b55eb5db083890 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Fri, 7 Jun 2024 11:26:53 +0200 Subject: [PATCH 03/10] feat: adds 24.04 as a supported Ubuntu base. --- charmcraft.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/charmcraft.yaml b/charmcraft.yaml index c8f0a13..df1859a 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -8,6 +8,13 @@ bases: channel: "22.04" architectures: ["amd64"] run-on: + - name: ubuntu + channel: "24.04" + architectures: + - amd64 + - aarch64 + - arm64 + - s390x - name: ubuntu channel: "22.04" architectures: From 62422e1fcc6f967b9d126d6bd0583ddc49989d82 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Sat, 5 Oct 2024 08:29:49 +0200 Subject: [PATCH 04/10] fix: adds Cargo as a build dependency to charmcraft.yaml. This required in order to build the binary wheel(s) required by the included COS libs. --- charmcraft.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charmcraft.yaml b/charmcraft.yaml index df1859a..4954c1c 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -2,6 +2,8 @@ type: charm parts: charm: charm-python-packages: [setuptools,markdown] + build-packages: + - cargo bases: - build-on: - name: ubuntu From e5b9963d56b16f2326e8a1493aedee3573d2e3a2 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Sat, 5 Oct 2024 08:29:49 +0200 Subject: [PATCH 05/10] fix: adds Cargo as a build dependency to charmcraft.yaml. This required in order to build the binary wheel(s) required by the included COS libs. --- charmcraft.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charmcraft.yaml b/charmcraft.yaml index df1859a..4954c1c 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -2,6 +2,8 @@ type: charm parts: charm: charm-python-packages: [setuptools,markdown] + build-packages: + - cargo bases: - build-on: - name: ubuntu From 55fc19da97563df7253b8e98fa98218583faea92 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Fri, 8 Nov 2024 15:08:49 +0100 Subject: [PATCH 06/10] fix: use charmcraft 2.x to build Version 3 of charmcraft does not allow a run-on stanza that includes 24.04 with other versions, but 2 does. So we install this versions for our Github workflows. --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b07cd1..93b0357 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: needs: unit-tests uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4 with: + charmcraft-snap-channel: 2.x/stable artifact-name: charm-packed @@ -93,7 +94,7 @@ jobs: env: CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} run: | - sudo snap install charmcraft --classic + sudo snap install charmcraft --channel 2.x/stable --classic charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ --name $CHARM_NAME \ --release ${{ needs.channel.outputs.test }} @@ -143,7 +144,7 @@ jobs: - name: Install Juju run: | - sudo snap install juju --channel 3.3/beta + sudo snap install juju --channel 3.5/stable - name: Bootstrap on LXD if: matrix.cloud == 'lxd' @@ -179,7 +180,7 @@ jobs: steps: - name: Install Charmcraft run: | - sudo snap install charmcraft --classic + sudo snap install charmcraft --channel 2.x/stable --classic - name: Get uploaded revision id: revision From 8bceb7d7673ea9b07828c0a819d8dd73f227d41d Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Fri, 8 Nov 2024 17:07:01 +0100 Subject: [PATCH 07/10] fix: use Juju 3.6 for tests Testing on an old version was vestigial. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93b0357..d900e88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -144,7 +144,7 @@ jobs: - name: Install Juju run: | - sudo snap install juju --channel 3.5/stable + sudo snap install juju --channel 3.6/candidate - name: Bootstrap on LXD if: matrix.cloud == 'lxd' From ab25b1f9829add6662b7da78d39a22101be90f62 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Fri, 8 Nov 2024 17:12:14 +0100 Subject: [PATCH 08/10] fix: replace aarch46 with ppc64el Not sure how we ended up with this list of architectures. --- charmcraft.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 4954c1c..88df105 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -14,20 +14,20 @@ bases: channel: "24.04" architectures: - amd64 - - aarch64 - arm64 - s390x + - ppc64el - name: ubuntu channel: "22.04" architectures: - amd64 - - aarch64 - arm64 - s390x + - ppc64el - name: ubuntu channel: "20.04" architectures: - amd64 - - aarch64 - arm64 - s390x + - ppc64el From c257e1750b7b44e101bc49c9ea985994358a9ac5 Mon Sep 17 00:00:00 2001 From: wallyworld Date: Tue, 12 Nov 2024 16:31:06 +1000 Subject: [PATCH 09/10] chore: use charmcraft 3 We can only currently build for one base, but we can remote build on launchpad and thus get builds for all supported arches. --- .github/workflows/ci.yml | 9 ++++----- charmcraft.yaml | 33 ++++++--------------------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d900e88..1697b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,9 @@ jobs: build: name: Build charms needs: unit-tests - uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23 with: - charmcraft-snap-channel: 2.x/stable - artifact-name: charm-packed + charmcraft-snap-channel: 3.x/stable channel: @@ -94,7 +93,7 @@ jobs: env: CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} run: | - sudo snap install charmcraft --channel 2.x/stable --classic + sudo snap install charmcraft --channel 3.x/stable --classic charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ --name $CHARM_NAME \ --release ${{ needs.channel.outputs.test }} @@ -180,7 +179,7 @@ jobs: steps: - name: Install Charmcraft run: | - sudo snap install charmcraft --channel 2.x/stable --classic + sudo snap install charmcraft --channel 3.x/stable --classic - name: Get uploaded revision id: revision diff --git a/charmcraft.yaml b/charmcraft.yaml index 88df105..8f15b7a 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -4,30 +4,9 @@ parts: charm-python-packages: [setuptools,markdown] build-packages: - cargo -bases: - - build-on: - - name: ubuntu - channel: "22.04" - architectures: ["amd64"] - run-on: - - name: ubuntu - channel: "24.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el - - name: ubuntu - channel: "22.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el - - name: ubuntu - channel: "20.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el +base: ubuntu@24.04 +platforms: + amd64: + arm64: + s390x: + ppc64el: From e5204f924646f3098ca4c91e38a8b08a333437ab Mon Sep 17 00:00:00 2001 From: Harry Pidcock Date: Fri, 22 Nov 2024 09:12:44 +1000 Subject: [PATCH 10/10] test: fix blocked status and blocked status tests --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 37 +++++++++++++++++++++++++++++++++++++ src/charm.py | 2 +- tests/test_charm.py | 3 ++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4583957 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1731797254, + "narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7d72a07 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "juju controller charm shell"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + }; + + outputs = { self, nixpkgs, ... } @ inputs: + let + forAllSystems = inputs.nixpkgs.lib.genAttrs [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + ]; + in + { + devShells = forAllSystems (system: { + default = + let + pkgs = nixpkgs.legacyPackages.${system}; + in + pkgs.mkShell { + name = "juju-controller-charm"; + # Enable experimental features without having to specify the argument + NIX_CONFIG = "experimental-features = nix-command flakes"; + nativeBuildInputs = with pkgs; [ + coreutils + findutils + zsh + python312 + ]; + shellHook = '' + exec zsh + ''; + }; + }); + }; +} \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index f04a999..d0ccffb 100755 --- a/src/charm.py +++ b/src/charm.py @@ -131,7 +131,7 @@ def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent): except AgentConfException as e: logger.error('cannot read controller API port from agent configuration: %s', e) self.unit.status = BlockedStatus( - f"can't read controller API port from agent.conf: {e}") + f"cannot read controller API port from agent configuration: {e}") return metrics_endpoint = MetricsEndpointProvider( diff --git a/tests/test_charm.py b/tests/test_charm.py index 003d6a3..d61566f 100644 --- a/tests/test_charm.py +++ b/tests/test_charm.py @@ -140,7 +140,8 @@ def test_apiaddresses_missing_status(self, *_): harness.add_relation('metrics-endpoint', 'prometheus-k8s') harness.evaluate_status() self.assertEqual(harness.charm.unit.status, BlockedStatus( - "can't read controller API port from agent.conf: agent.conf key 'apiaddresses' missing" + "cannot read controller API port from agent configuration: " + "agent.conf key 'apiaddresses' missing" )) @patch("builtins.open", new_callable=mock_open, read_data=agent_conf_ipv4)