Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Minio Console and API via Ingress #42

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
21 changes: 21 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_ingress(interfaces)

self.model.unit.status = MaintenanceStatus("Setting pod spec")
self.model.pod.set_spec(
{
Expand Down Expand Up @@ -169,6 +171,25 @@ def _with_console_address(self, minio_args):
console_port = str(self.model.config["console-port"])
return [*minio_args, "--console-address", ":" + console_port]

def _configure_ingress(self, interfaces):
if interfaces["ingress"]:
interfaces["ingress"].send_data(
{
"prefix": "/",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This'll define the endpoint that we claim on the ingress, as written we've claimed the root (or really, http://INGRESS_URL/). It probably makes the most sense that this be configurable via a config option. The config option could accept anything that would be valid in a URL (a good default value could be /minio).

"rewrite": "/",
"service": f"{self.model.app.name}-console",
"port": self.model.config["console-port"],
}
)
interfaces["ingress"].send_data(
{
"prefix": "/",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this prefix and the above one be the same? I don't know this for sure, but my expectation is that they will conflict. I think these might need to be something like "prefix": "/SOME_VALUE_FROM_CONFIG/console" and "/SOME_VALUE_FROM_CONFIG/api" (or whatever good name you suggest)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure either. I didn't consider it because the ports are different, but it doesnt serve it on the same port I would assume

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the only external facing thing is the prefix, and then the port is used when routing to the kubernetes service (eg: INGRESS/PREFIX routes to SERVICE:PORT inside kubernetes)

"rewrite": "/",
"service": f"{self.model.app.name}",
"port": self.model.config["port"],
}
)


def _gen_pass() -> str:
return "".join(choices(ascii_uppercase + digits, k=30))
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,65 @@ def test_minio_console_port_args(harness):
"--console-address",
":9999",
]

def test_install_with_all_inputs(harness):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test can work as a general "can I successfully invoke pod_spec" test, but I think we are missing something to actually check whether this charm has published what we expect to the relation. For example, like here

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",
]