From b1c0342570a76c3331def59618d28c4427ec8642 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Fri, 4 Mar 2022 14:40:04 -0500 Subject: [PATCH 1/6] Add minio engress --- metadata.yaml | 5 +++++ src/charm.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/metadata.yaml b/metadata.yaml index f648d1e..65abaa1 100755 --- a/metadata.yaml +++ b/metadata.yaml @@ -24,3 +24,8 @@ storage: type: filesystem location: /data minimum-size: 10G +requires: + ingress: + interface: ingress + schema: https://raw.githubusercontent.com/canonical/operator-schemas/master/ingress.yaml + versions: [v1] \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index 483d692..5ea6592 100755 --- a/src/charm.py +++ b/src/charm.py @@ -56,6 +56,8 @@ def main(self, event): secret_key = self.model.config["secret-key"] or self._stored.secret_key self._send_info(interfaces, secret_key) + self._configure_mesh(interfaces) + self.model.unit.status = MaintenanceStatus("Setting pod spec") self.model.pod.set_spec( { @@ -169,6 +171,17 @@ def _with_console_address(self, minio_args): console_port = str(self.model.config["console-port"]) return [*minio_args, "--console-address", ":" + console_port] + def _configure_mesh(self, interfaces): + if interfaces["ingress"]: + interfaces["ingress"].send_data( + { + "prefix": "/minio", + "rewrite": "/", + "service": self.model.app.name, + "port": self.model.config["port"], + } + ) + def _gen_pass() -> str: return "".join(choices(ascii_uppercase + digits, k=30)) From c80317ec470e2f083af30e48437a8319a126f15d Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Mon, 7 Mar 2022 17:21:03 -0500 Subject: [PATCH 2/6] Add api ingress --- src/charm.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index 5ea6592..b9caca0 100755 --- a/src/charm.py +++ b/src/charm.py @@ -56,7 +56,7 @@ def main(self, event): secret_key = self.model.config["secret-key"] or self._stored.secret_key self._send_info(interfaces, secret_key) - self._configure_mesh(interfaces) + self._configure_ingress(interfaces) self.model.unit.status = MaintenanceStatus("Setting pod spec") self.model.pod.set_spec( @@ -171,13 +171,21 @@ def _with_console_address(self, minio_args): console_port = str(self.model.config["console-port"]) return [*minio_args, "--console-address", ":" + console_port] - def _configure_mesh(self, interfaces): + def _configure_ingress(self, interfaces): if interfaces["ingress"]: interfaces["ingress"].send_data( { - "prefix": "/minio", + "prefix": "/", "rewrite": "/", - "service": self.model.app.name, + "service": f"{self.model.app.name}-console", + "port": self.model.config["console-port"], + } + ) + interfaces["ingress"].send_data( + { + "prefix": "/", + "rewrite": "/", + "service": f"{self.model.app.name}", "port": self.model.config["port"], } ) From b343d1504265aa72df5c788f3cffb6d385f8d688 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Tue, 8 Mar 2022 15:10:02 -0500 Subject: [PATCH 3/6] Add additional unit test --- tests/unit/test_charm.py | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 99a5d1b..3b45dcf 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -309,3 +309,65 @@ def test_minio_console_port_args(harness): "--console-address", ":9999", ] + +def test_install_with_all_inputs(harness): + harness.set_leader(True) + harness.add_oci_resource( + "oci-image", + { + "registrypath": "ci-test", + "username": "", + "password": "", + }, + ) + harness.update_config( + { + "secret-key": "test-secret-key", + "access-key": "test-access-key", + "mode": "gateway", + "gateway-storage-service": "azure", + } + ) + + # object storage + os_rel_id = harness.add_relation("object-storage", "foobar") + harness.add_relation_unit(os_rel_id, "foobar/0") + harness.update_relation_data( + os_rel_id, + "foobar", + {"_supported_versions": yaml.dump(["v1"])}, + ) + + # ingress + ingress_relation_name = "ingress" + relation_version_data = {"_supported_versions": "- v1"} + ingress_rel_id = harness.add_relation( + ingress_relation_name, f"{ingress_relation_name}-subscriber" + ) + harness.add_relation_unit(ingress_rel_id, f"{ingress_relation_name}-subscriber/0") + harness.update_relation_data( + ingress_rel_id, f"{ingress_relation_name}-subscriber", relation_version_data + ) + + harness.begin_with_initial_hooks() + + pod_spec = harness.get_pod_spec() + yaml.safe_dump(pod_spec) + assert harness.charm.model.unit.status == ActiveStatus() + + charm_name = harness.model.app.name + secrets = pod_spec[0]["kubernetesResources"]["secrets"] + env_config = pod_spec[0]["containers"][0]["envConfig"] + + pod_spec_secrets = pod_spec[0]["kubernetesResources"]["secrets"] + pod_spec_secret_key = pod_spec_secrets[0]["data"]["MINIO_SECRET_KEY"] + pod_spec_access_key = pod_spec_secrets[0]["data"]["MINIO_ACCESS_KEY"] + + assert b64decode(pod_spec_secret_key).decode("utf-8") == "test-secret-key" + assert b64decode(pod_spec_access_key).decode("utf-8") == "test-access-key" + assert pod_spec[0]["containers"][0]["args"] == [ + "gateway", + "azure", + "--console-address", + ":9001", + ] \ No newline at end of file From 770885c8fff8962a7a6737e7e181fcc71d2427d7 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Tue, 8 Mar 2022 16:34:46 -0500 Subject: [PATCH 4/6] Fix lint errors --- tests/unit/test_charm.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 3b45dcf..dce302f 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -310,6 +310,7 @@ def test_minio_console_port_args(harness): ":9999", ] + def test_install_with_all_inputs(harness): harness.set_leader(True) harness.add_oci_resource( @@ -355,10 +356,6 @@ def test_install_with_all_inputs(harness): yaml.safe_dump(pod_spec) assert harness.charm.model.unit.status == ActiveStatus() - charm_name = harness.model.app.name - secrets = pod_spec[0]["kubernetesResources"]["secrets"] - env_config = pod_spec[0]["containers"][0]["envConfig"] - pod_spec_secrets = pod_spec[0]["kubernetesResources"]["secrets"] pod_spec_secret_key = pod_spec_secrets[0]["data"]["MINIO_SECRET_KEY"] pod_spec_access_key = pod_spec_secrets[0]["data"]["MINIO_ACCESS_KEY"] @@ -370,4 +367,4 @@ def test_install_with_all_inputs(harness): "azure", "--console-address", ":9001", - ] \ No newline at end of file + ] From 1b59dea42b4119b50329473167c2f75139cff3b8 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Thu, 10 Mar 2022 10:06:55 -0500 Subject: [PATCH 5/6] Remove API ingress and update tests --- metadata.yaml | 2 +- src/charm.py | 12 ++---------- tests/unit/test_charm.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/metadata.yaml b/metadata.yaml index 65abaa1..4306d66 100755 --- a/metadata.yaml +++ b/metadata.yaml @@ -25,7 +25,7 @@ storage: location: /data minimum-size: 10G requires: - ingress: + console-ingress: interface: ingress schema: https://raw.githubusercontent.com/canonical/operator-schemas/master/ingress.yaml versions: [v1] \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index b9caca0..ad33c06 100755 --- a/src/charm.py +++ b/src/charm.py @@ -172,8 +172,8 @@ def _with_console_address(self, minio_args): return [*minio_args, "--console-address", ":" + console_port] def _configure_ingress(self, interfaces): - if interfaces["ingress"]: - interfaces["ingress"].send_data( + if interfaces["console-ingress"]: + interfaces["console-ingress"].send_data( { "prefix": "/", "rewrite": "/", @@ -181,14 +181,6 @@ def _configure_ingress(self, interfaces): "port": self.model.config["console-port"], } ) - interfaces["ingress"].send_data( - { - "prefix": "/", - "rewrite": "/", - "service": f"{self.model.app.name}", - "port": self.model.config["port"], - } - ) def _gen_pass() -> str: diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index dce302f..6959159 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -340,7 +340,7 @@ def test_install_with_all_inputs(harness): ) # ingress - ingress_relation_name = "ingress" + ingress_relation_name = "console-ingress" relation_version_data = {"_supported_versions": "- v1"} ingress_rel_id = harness.add_relation( ingress_relation_name, f"{ingress_relation_name}-subscriber" @@ -368,3 +368,12 @@ def test_install_with_all_inputs(harness): "--console-address", ":9001", ] + data = yaml.safe_load(harness.get_relation_data(os_rel_id, "minio")["data"]) + assert data == { + "access-key": "test-access-key", + "namespace": None, + "port": 9000, + "secret-key": "test-secret-key", + "secure": False, + "service": "minio", + } From cac7a4acf8a665c6061afeb9a9e55ab724109f87 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Wed, 30 Mar 2022 12:33:23 -0400 Subject: [PATCH 6/6] Add console-ingress events --- src/charm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/charm.py b/src/charm.py index ad33c06..1fef9ab 100755 --- a/src/charm.py +++ b/src/charm.py @@ -36,6 +36,8 @@ def __init__(self, *args): self.on.upgrade_charm, self.on["object-storage"].relation_changed, self.on["object-storage"].relation_joined, + self.on["console-ingress"].relation_changed, + self.on["console-ingress"].relation_joined, ]: self.framework.observe(event, self.main)