Skip to content

Commit

Permalink
Merge branch 'main' into feat/v3-rock
Browse files Browse the repository at this point in the history
  • Loading branch information
merkata committed Nov 24, 2023
2 parents 9485377 + d2a3dab commit 6524822
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/explanation/charm-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The OCI image is built using [Rockcraft](https://canonical-rockcraft.readthedocs

This is done by publishing a resource to Charmhub as described in the [Juju SDK How-to guides](https://juju.is/docs/sdk/publishing).

The OCI image is currently not made to work in an air-gapped environment. You should make sure that it has access to `https://rubygems.org/` (to install gems) and to `https://avatars.discourse.org/` (the official service to create letter avatars).

## Integrations

### Ingress
Expand Down Expand Up @@ -85,4 +87,4 @@ CharmBase is the base class from which all Charms are formed, defined by [Ops](h

See more information in [Charm](https://juju.is/docs/sdk/constructs#heading--charm).

The `__init__` method guarantees that the charm observes all events relevant to its operation and handles them.
The `__init__` method guarantees that the charm observes all events relevant to its operation and handles them.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ fixes and constructive feedback.
- [Code of conduct](https://ubuntu.com/community/code-of-conduct)
- [Get support](https://discourse.charmhub.io/)
- [Join our online chat](https://chat.charmhub.io/charmhub/channels/charm-dev)
- [Contribute](https://charmhub.io/discourse-k8s/docs/how-to-contribute)
- [Contribute](https://charmhub.io/discourse-k8s/docs/how-to-contribute)
2 changes: 1 addition & 1 deletion docs/reference/actions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Actions

See [Actions](https://charmhub.io/discourse-k8s/actions).
See [Actions](https://charmhub.io/discourse-k8s/actions).
2 changes: 1 addition & 1 deletion docs/reference/configurations.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Configurations

See [Configure](https://charmhub.io/discourse-k8s/configure).
See [Configure](https://charmhub.io/discourse-k8s/configure).
2 changes: 1 addition & 1 deletion docs/reference/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ By default, the following Discourse plugins are installed with the latest versio
- [Markdown Note](https://github.com/canonical-web-and-design/discourse-markdown-note)
- [Mermaid](https://github.com/unfoldingWord-dev/discourse-mermaid)
- [SAML](https://github.com/discourse/discourse-saml)
- [Prometheus export](https://github.com/discourse/discourse-prometheus)
- [Prometheus export](https://github.com/discourse/discourse-prometheus)
7 changes: 3 additions & 4 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ You will need:
## Deploy this charm

Discourse requires connections to PostgreSQL and Redis, so those will be deployed too and related to the Discourse charm. For more information, see the [Charm Architecture](https://charmhub.io/discourse-k8s/docs/charm-architecture).
Note that Discourse requires PostgreSQL extensions to be available in the relation. Extensions are currently available
in the `14/edge` and `14/candidate`.
Note that Discourse requires PostgreSQL extensions to be available in the relation.

All the above charms will the deployed in a new model named `discourse`:

Expand All @@ -23,7 +22,7 @@ juju add-model discourse
# Deploy the charms
juju deploy redis-k8s
juju deploy postgresql-k8s --channel 14/edge
juju deploy postgresql-k8s --channel 14/stable --trust
juju deploy discourse-k8s
# Enable required PostgreSQL extensions
Expand All @@ -43,7 +42,7 @@ discourse microk8s-localhost microk8s/localhost 2.9.37 unsupported 10:35:0
App Version Status Scale Charm Channel Rev Address Exposed Message
discourse-k8s active 1 discourse-k8s edge 13 10.152.183.34 no
postgresql-k8s res:postgresql-image@8a72e11 active 1 postgresql-k8s stable 20 no Pod configured
postgresql-k8s 14.9 active 1 postgresql-k8s stable 158 no Pod configured
redis-k8s ubuntu/redis@691f315 active 1 redis-k8s stable 7 no
Unit Workload Agent Address Ports Message
Expand Down
27 changes: 23 additions & 4 deletions lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 23
LIBPATCH = 24

PYDEPS = ["ops>=2.0.0"]

Expand Down Expand Up @@ -526,7 +526,16 @@ def get_content(self) -> Dict[str, str]:
"""Getting cached secret content."""
if not self._secret_content:
if self.meta:
self._secret_content = self.meta.get_content()
try:
self._secret_content = self.meta.get_content(refresh=True)
except (ValueError, ModelError) as err:
# https://bugs.launchpad.net/juju/+bug/2042596
# Only triggered when 'refresh' is set
msg = "ERROR either URI or label should be used for getting an owned secret but not both"
if isinstance(err, ModelError) and msg not in str(err):
raise
# Due to: ValueError: Secret owner cannot use refresh=True
self._secret_content = self.meta.get_content()
return self._secret_content

def set_content(self, content: Dict[str, str]) -> None:
Expand Down Expand Up @@ -1085,7 +1094,7 @@ def _delete_relation_secret(
secret = self._get_relation_secret(relation.id, group)

if not secret:
logging.error("Can't update secret for relation %s", str(relation.id))
logging.error("Can't delete secret for relation %s", str(relation.id))
return False

old_content = secret.get_content()
Expand Down Expand Up @@ -1827,7 +1836,8 @@ def _assign_relation_alias(self, relation_id: int) -> None:

# We need to set relation alias also on the application level so,
# it will be accessible in show-unit juju command, executed for a consumer application unit
self.update_relation_data(relation_id, {"alias": available_aliases[0]})
if self.local_unit.is_leader():
self.update_relation_data(relation_id, {"alias": available_aliases[0]})

def _emit_aliased_event(self, event: RelationChangedEvent, event_name: str) -> None:
"""Emit an aliased event to a particular relation if it has an alias.
Expand Down Expand Up @@ -1914,6 +1924,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:

# Sets both database and extra user roles in the relation
# if the roles are provided. Otherwise, sets only the database.
if not self.local_unit.is_leader():
return

if self.extra_user_roles:
self.update_relation_data(
event.relation.id,
Expand Down Expand Up @@ -2173,6 +2186,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
"""Event emitted when the Kafka relation is created."""
super()._on_relation_created_event(event)

if not self.local_unit.is_leader():
return

# Sets topic, extra user roles, and "consumer-group-prefix" in the relation
relation_data = {
f: getattr(self, f.replace("-", "_"), "")
Expand Down Expand Up @@ -2345,6 +2361,9 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
"""Event emitted when the OpenSearch relation is created."""
super()._on_relation_created_event(event)

if not self.local_unit.is_leader():
return

# Sets both index and extra user roles in the relation if the roles are provided.
# Otherwise, sets only the index.
data = {"index": self.index}
Expand Down

0 comments on commit 6524822

Please sign in to comment.