Skip to content

Commit

Permalink
Merge branch 'main' into cert-transfer-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
saltiyazan authored Nov 22, 2024
2 parents f449866 + f8b46b2 commit 9aa486d
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 466 deletions.
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ options:
will provide to the unit `my-unit/2` in the `my-model` model the following URL:
`http://my-model-my-unit-2.foo:8080`
Note that, for 'subdomain' routing mode, the external_hostname must be set and not be set to an IP address. This
is because subdomains are not supported for IP addresses.
type: string
default: path

Expand Down
301 changes: 0 additions & 301 deletions lib/charms/observability_libs/v0/juju_topology.py

This file was deleted.

40 changes: 34 additions & 6 deletions lib/charms/traefik_k8s/v2/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):
import typing
from dataclasses import dataclass
from functools import partial
from typing import Any, Callable, Dict, List, MutableMapping, Optional, Sequence, Tuple, Union
from typing import (
Any,
Callable,
Dict,
List,
MutableMapping,
Optional,
Sequence,
Tuple,
Union,
cast,
)

import pydantic
from ops.charm import CharmBase, RelationBrokenEvent, RelationEvent
Expand Down Expand Up @@ -226,7 +237,7 @@ class IngressUrl(BaseModel):
class IngressProviderAppData(DatabagModel):
"""Ingress application databag schema."""

ingress: IngressUrl
ingress: Optional[IngressUrl] = None


class ProviderSchema(BaseModel):
Expand Down Expand Up @@ -558,7 +569,16 @@ def _published_url(self, relation: Relation) -> Optional["IngressProviderAppData
def publish_url(self, relation: Relation, url: str):
"""Publish to the app databag the ingress url."""
ingress_url = {"url": url}
IngressProviderAppData(ingress=ingress_url).dump(relation.data[self.app]) # type: ignore
try:
IngressProviderAppData(ingress=ingress_url).dump(relation.data[self.app]) # type: ignore
except pydantic.ValidationError as e:
# If we cannot validate the url as valid, publish an empty databag and log the error.
log.error(f"Failed to validate ingress url '{url}' - got ValidationError {e}")
log.error(
"url was not published to ingress relation for {relation.app}. This error is likely due to an"
" error or misconfiguration of the charm calling this library."
)
IngressProviderAppData(ingress=None).dump(relation.data[self.app]) # type: ignore

@property
def proxied_endpoints(self) -> Dict[str, Dict[str, str]]:
Expand Down Expand Up @@ -596,10 +616,14 @@ def proxied_endpoints(self) -> Dict[str, Dict[str, str]]:
if not ingress_data:
log.warning(f"relation {ingress_relation} not ready yet: try again in some time.")
continue

# Validation above means ingress cannot be None, but type checker doesn't know that.
ingress = ingress_data.ingress
ingress = cast(IngressProviderAppData, ingress)
if PYDANTIC_IS_V1:
results[ingress_relation.app.name] = ingress_data.ingress.dict()
results[ingress_relation.app.name] = ingress.dict()
else:
results[ingress_relation.app.name] = ingress_data.ingress.model_dump(mode="json")
results[ingress_relation.app.name] = ingress.model_dump(mode="json")
return results


Expand Down Expand Up @@ -834,7 +858,11 @@ def _get_url_from_relation_data(self) -> Optional[str]:
if not databag: # not ready yet
return None

return str(IngressProviderAppData.load(databag).ingress.url)
ingress = IngressProviderAppData.load(databag).ingress
if ingress is None:
return None

return str(ingress.url)

@property
def url(self) -> Optional[str]:
Expand Down
Loading

0 comments on commit 9aa486d

Please sign in to comment.