From 775a0fc792158f55e8205b3e3dd7b3833328e634 Mon Sep 17 00:00:00 2001 From: javierdelapuente Date: Wed, 3 Jul 2024 18:30:02 +0200 Subject: [PATCH] feat: flask and django, update to paas-app-charmer 1.0.3 (#1691) Version 1.0.3 of [paas-app-charmer](https://github.com/canonical/paas-app-charmer) has been released, providing the new following functionality: - Two new integrations, SAML and S3. - Blocking on non optional integrations. If the optional attribute in the `charmcraft.yaml` file is set to false and the integration is not active, paas-app-charmer will block the charm (and stop all the services). This PR adapts charmcraft to get advantage of that functionality. Besides those changes, `charm-libs` has been added to the extension (including the new two new libraries for SAML and S3). That way the user can do `charmcraft fetch-libs` instead of one `fetch-lib` per library. --- charmcraft/extensions/gunicorn.py | 13 ++++++++++- .../init-django-framework/charmcraft.yaml.j2 | 20 +++++++++++++++++ .../init-flask-framework/charmcraft.yaml.j2 | 22 ++++++++++++++++++- tests/extensions/test_gunicorn.py | 22 +++++++++++++++++++ .../commands/init-flask-framework/task.yaml | 7 +----- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/charmcraft/extensions/gunicorn.py b/charmcraft/extensions/gunicorn.py index 1f34c1837..a1e3f7101 100644 --- a/charmcraft/extensions/gunicorn.py +++ b/charmcraft/extensions/gunicorn.py @@ -98,7 +98,7 @@ def _check_input(self) -> None: f"{protected!r} in charmcraft.yaml conflicts with a reserved field " f"in the {self.framework}-framework extension, please remove it." ) - for merging in ("actions", "requires", "provides", "config.options"): + for merging in ("actions", "requires", "provides", "config.options", "charm-libs"): user_provided: dict[str, Any] = self._get_nested(self.yaml_data, merging) if not user_provided: continue @@ -134,6 +134,17 @@ def _get_root_snippet(self) -> dict[str, Any]: "description": f"{self.framework} application image.", }, }, + "charm-libs": [ + {"lib": "traefik_k8s.ingress", "version": "2"}, + {"lib": "observability_libs.juju_topology", "version": "0"}, + {"lib": "grafana_k8s.grafana_dashboard", "version": "0"}, + {"lib": "loki_k8s.loki_push_api", "version": "0"}, + {"lib": "data_platform_libs.data_interfaces", "version": "0"}, + {"lib": "prometheus_k8s.prometheus_scrape", "version": "0"}, + {"lib": "redis_k8s.redis", "version": "0"}, + {"lib": "data_platform_libs.s3", "version": "0"}, + {"lib": "saml_integrator.saml", "version": "0"}, + ], "peers": {"secret-storage": {"interface": "secret-storage"}}, "actions": self.actions, "requires": { diff --git a/charmcraft/templates/init-django-framework/charmcraft.yaml.j2 b/charmcraft/templates/init-django-framework/charmcraft.yaml.j2 index 7cf1a293d..25632b2d9 100644 --- a/charmcraft/templates/init-django-framework/charmcraft.yaml.j2 +++ b/charmcraft/templates/init-django-framework/charmcraft.yaml.j2 @@ -24,10 +24,30 @@ extensions: - django-framework # Uncomment the integrations used by your application +# Integrations set to "optional: false" will block the charm +# until the applications are integrated. # requires: # mysql: # interface: mysql_client +# optional: false # limit: 1 # postgresql: # interface: postgresql_client +# optional: false +# limit: 1 +# mongodb: +# interface: mongodb_client +# optional: false +# limit: 1 +# redis: +# interface: redis +# optional: false +# limit: 1 +# s3: +# interface: s3 +# optional: false +# limit: 1 +# saml: +# interface: saml +# optional: false # limit: 1 diff --git a/charmcraft/templates/init-flask-framework/charmcraft.yaml.j2 b/charmcraft/templates/init-flask-framework/charmcraft.yaml.j2 index eb7ee0aa9..7421920fc 100644 --- a/charmcraft/templates/init-flask-framework/charmcraft.yaml.j2 +++ b/charmcraft/templates/init-flask-framework/charmcraft.yaml.j2 @@ -14,7 +14,7 @@ bases: channel: "22.04" # (Required) -summary: A very short one-line summary of the flask application. +summary: A very short one-line summary of the Flask application. # (Required) description: | @@ -24,10 +24,30 @@ extensions: - flask-framework # Uncomment the integrations used by your application +# Integrations set to "optional: false" will block the charm +# until the applications are integrated. # requires: # mysql: # interface: mysql_client +# optional: false # limit: 1 # postgresql: # interface: postgresql_client +# optional: false +# limit: 1 +# mongodb: +# interface: mongodb_client +# optional: false +# limit: 1 +# redis: +# interface: redis +# optional: false +# limit: 1 +# s3: +# interface: s3 +# optional: false +# limit: 1 +# saml: +# interface: saml +# optional: false # limit: 1 diff --git a/tests/extensions/test_gunicorn.py b/tests/extensions/test_gunicorn.py index a1b2b9f22..cf18d28b9 100644 --- a/tests/extensions/test_gunicorn.py +++ b/tests/extensions/test_gunicorn.py @@ -51,6 +51,17 @@ def flask_input_yaml_fixture(): }, "description": "test description", "name": "test-flask", + "charm-libs": [ + {"lib": "traefik_k8s.ingress", "version": "2"}, + {"lib": "observability_libs.juju_topology", "version": "0"}, + {"lib": "grafana_k8s.grafana_dashboard", "version": "0"}, + {"lib": "loki_k8s.loki_push_api", "version": "0"}, + {"lib": "data_platform_libs.data_interfaces", "version": "0"}, + {"lib": "prometheus_k8s.prometheus_scrape", "version": "0"}, + {"lib": "redis_k8s.redis", "version": "0"}, + {"lib": "data_platform_libs.s3", "version": "0"}, + {"lib": "saml_integrator.saml", "version": "0"}, + ], "config": { "options": {**FlaskFramework.options, **FlaskFramework._WEBSERVER_OPTIONS} }, @@ -93,6 +104,17 @@ def flask_input_yaml_fixture(): }, "description": "test description", "name": "test-django", + "charm-libs": [ + {"lib": "traefik_k8s.ingress", "version": "2"}, + {"lib": "observability_libs.juju_topology", "version": "0"}, + {"lib": "grafana_k8s.grafana_dashboard", "version": "0"}, + {"lib": "loki_k8s.loki_push_api", "version": "0"}, + {"lib": "data_platform_libs.data_interfaces", "version": "0"}, + {"lib": "prometheus_k8s.prometheus_scrape", "version": "0"}, + {"lib": "redis_k8s.redis", "version": "0"}, + {"lib": "data_platform_libs.s3", "version": "0"}, + {"lib": "saml_integrator.saml", "version": "0"}, + ], "config": { "options": {**DjangoFramework.options, **DjangoFramework._WEBSERVER_OPTIONS} }, diff --git a/tests/spread/commands/init-flask-framework/task.yaml b/tests/spread/commands/init-flask-framework/task.yaml index 2fba60b52..65ad39731 100644 --- a/tests/spread/commands/init-flask-framework/task.yaml +++ b/tests/spread/commands/init-flask-framework/task.yaml @@ -7,12 +7,7 @@ execute: | mkdir -p test-init cd test-init charmcraft init --profile flask-framework - charmcraft fetch-lib charms.traefik_k8s.v2.ingress - charmcraft fetch-lib charms.observability_libs.v0.juju_topology - charmcraft fetch-lib charms.grafana_k8s.v0.grafana_dashboard - charmcraft fetch-lib charms.loki_k8s.v0.loki_push_api - charmcraft fetch-lib charms.data_platform_libs.v0.data_interfaces - charmcraft fetch-lib charms.prometheus_k8s.v0.prometheus_scrape + charmcraft fetch-libs charmcraft pack --verbose test -f *.charm