Skip to content

Commit

Permalink
Merge pull request #27 from Barteus/feature/azure-gateway
Browse files Browse the repository at this point in the history
Gateway mode added with storage options s3 and azure.
  • Loading branch information
DomFleischmann authored Jan 27, 2022
2 parents e9af80d + 6644a3a commit 65b1ccb
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 1 deletion.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,35 @@ To install MinIO, run:
juju deploy minio

For more information, see https://juju.is/docs

## Gateway mode

Supported data storage services: s3, azure

To install MinIO in gateway mode for s3, run:

juju deploy minio minio-s3-gateway \
--config mode=gateway \
--config gateway_storage_service=s3 \
--config access-key=<aws_s3_access_key> \
--config secret-key=<aws_s3_secret_key>

To install MinIO in gateway mode for azure, run:

juju deploy minio minio-azure-gateway \
--config mode=gateway \
--config gateway_storage_service=azure \
--config access-key=<azurestorageaccountname> \
--config secret-key=<azurestorageaccountkey>

If you do not want to share your data storage service credentials with users,
you can create users in MinIO console with proper permissions for them.

For more information,
see: https://docs.min.io/docs/minio-multi-user-quickstart-guide.html

The credentials access-key and secret-key differs for Azure and AWS. Improper
credential error will be visible in container logs.

For more information, see: https://docs.min.io/docs/minio-gateway-for-azure.html
and https://docs.min.io/docs/minio-gateway-for-s3.html
8 changes: 8 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ options:
type: string
default: ''
description: Secret key
mode:
type: string
default: 'server'
description: "Mode of operations. Possible values: server, gateway"
gateway_storage_service:
type: string
default: ''
description: "Storage service used by gateway to store objects. This value is required for gateway mode. Possible values: s3, azure"
27 changes: 26 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def main(self, event):

image_details = self._check_image_details()

minio_args = self._get_minio_args()

except CheckFailed as error:
self.model.unit.status = error.status
return
Expand All @@ -60,7 +62,7 @@ def main(self, event):
"containers": [
{
"name": "minio",
"args": ["server", "/data"],
"args": minio_args,
"imageDetails": image_details,
"ports": [
{
Expand Down Expand Up @@ -112,6 +114,29 @@ def _send_info(self, interfaces, secret_key):
}
)

def _get_minio_args(self):
model_mode = self.model.config["mode"]
if model_mode == "server":
return ["server", "/data"]
elif model_mode == "gateway":
storage = self.model.config.get("gateway_storage_service")
if storage:
self.log.debug(f"Minio args: gateway, {storage}")
return ["gateway", storage]
else:
raise CheckFailed(
"Minio in gateway mode requires gateway_storage_service "
"configuration. Possible values: s3, azure",
BlockedStatus,
)
else:
error_msg = (
f"Model mode {model_mode} is not supported. "
"Possible values server, gateway"
)
self.log.error(error_msg)
raise CheckFailed(error_msg, BlockedStatus)


def _gen_pass() -> str:
return "".join(choices(ascii_uppercase + digits, k=30))
Expand Down
106 changes: 106 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,109 @@ def test_main_with_manual_secret(harness):
"service": "minio",
}
assert harness.charm.model.unit.status == ActiveStatus("")


def test_server_minio_args(harness):
harness.set_leader(True)
harness.add_oci_resource(
"oci-image",
{
"registrypath": "ci-test",
"username": "",
"password": "",
},
)
harness.update_config({"secret-key": "test-key"})
harness.begin_with_initial_hooks()
pod_spec = harness.get_pod_spec()

assert pod_spec == (
{
"version": 3,
"containers": [
{
"name": "minio",
"args": ["server", "/data"],
"imageDetails": {
"imagePath": "ci-test",
"username": "",
"password": "",
},
"ports": [{"name": "minio", "containerPort": 9000}],
"envConfig": {
"MINIO_ACCESS_KEY": "minio",
"MINIO_SECRET_KEY": "test-key",
},
}
],
},
None,
)


def test_gateway_minio_args(harness):
harness.set_leader(True)
harness.add_oci_resource(
"oci-image",
{
"registrypath": "ci-test",
"username": "",
"password": "",
},
)
harness.update_config(
{
"secret-key": "test-key",
"mode": "gateway",
"gateway_storage_service": "azure",
}
)
harness.begin_with_initial_hooks()
pod_spec = harness.get_pod_spec()

assert pod_spec == (
{
"version": 3,
"containers": [
{
"name": "minio",
"args": ["gateway", "azure"],
"imageDetails": {
"imagePath": "ci-test",
"username": "",
"password": "",
},
"ports": [{"name": "minio", "containerPort": 9000}],
"envConfig": {
"MINIO_ACCESS_KEY": "minio",
"MINIO_SECRET_KEY": "test-key",
},
}
],
},
None,
)


def test_gateway_minio_missing_args(harness):
harness.set_leader(True)
harness.add_oci_resource(
"oci-image",
{
"registrypath": "ci-test",
"username": "",
"password": "",
},
)
harness.update_config(
{
"secret-key": "test-key",
"mode": "gateway",
}
)
harness.begin_with_initial_hooks()

assert harness.charm.model.unit.status == BlockedStatus(
"Minio in gateway mode requires gateway_storage_service configuration. "
"Possible values: s3, azure"
)

0 comments on commit 65b1ccb

Please sign in to comment.