Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
Comment thread
sinclert-canonical marked this conversation as resolved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@

```python

from charms.data_platform_libs.v0.data_models import BaseConfigModel
from charms.data_platform_libs.v1.data_models import BaseConfigModel

class MyConfig(BaseConfigModel):

Expand Down Expand Up @@ -164,20 +164,27 @@ class MergedDataBag(ProviderDataBag, RequirerDataBag):
LIBID = "cb2094c5b07d47e1bf346aaee0fcfcfe"

# Increment this major API version when introducing breaking changes
LIBAPI = 0
LIBAPI = 1

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

PYDEPS = ["ops>=2.0.0", "pydantic>=1.10,<2"]
PYDEPS = ["ops>=2.0.0", "pydantic>=2,<3"]

G = TypeVar("G")
T = TypeVar("T", bound=BaseModel)
AppModel = TypeVar("AppModel", bound=BaseModel)
UnitModel = TypeVar("UnitModel", bound=BaseModel)

DataBagNativeTypes = (int, str, float)
DataBagNativeTypes = (
int,
str,
float,
Optional[int],
Optional[str],
Optional[float],
)


class BaseConfigModel(BaseModel):
Expand Down Expand Up @@ -233,7 +240,7 @@ def write(relation_data: RelationDataContent, model: BaseModel):
relation_data: pointer to the relation databag
model: instance of pydantic model to be written
"""
for key, value in model.dict(exclude_none=False).items():
for key, value in model.model_dump(exclude_none=False).items():
if value:
relation_data[key.replace("_", "-")] = (
str(value)
Expand All @@ -255,10 +262,10 @@ def read(relation_data: MutableMapping[str, str], obj: Type[T]) -> T:
**{
field_name: (
relation_data[parsed_key]
if field.outer_type_ in DataBagNativeTypes
if field_info.annotation in DataBagNativeTypes
else json.loads(relation_data[parsed_key])
)
for field_name, field in obj.__fields__.items()
for field_name, field_info in obj.model_fields.items()
# pyright: ignore[reportGeneralTypeIssues]
if (parsed_key := field_name.replace("_", "-")) in relation_data
if relation_data[parsed_key]
Expand Down
179 changes: 132 additions & 47 deletions kubernetes/poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions kubernetes/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ main = [
charm-libs = [
# data_platform_libs/v0/data_interfaces.py
"ops>=2.0.0",
# data_platform_libs/v0/data_models.py requires pydantic ^1.10
# tempo_coordinator_k8s/v0/charm_tracing.py requires pydantic
"pydantic~=1.10",
# data_platform_libs/v1/data_models.py
"pydantic~=2.0",
# mysql/v0/*.py"
"charm-refresh~=3.1.1",
"mysql_shell_client~=0.7",
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import charm_refresh
import ops
from charms.data_platform_libs.v0.data_models import TypedCharmBase
from charms.data_platform_libs.v1.data_models import TypedCharmBase
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer
from charms.mysql.v0.async_replication import (
Expand Down
30 changes: 15 additions & 15 deletions kubernetes/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import re
from typing import ClassVar

from charms.data_platform_libs.v0.data_models import BaseConfigModel
from charms.data_platform_libs.v1.data_models import BaseConfigModel
from charms.mysql.v0.mysql import MAX_CONNECTIONS_FLOOR
from pydantic import validator
from pydantic import Field, field_validator

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,18 +51,18 @@ class CharmConfig(BaseConfigModel):
"""Manager for the structured configuration."""

profile: str
cluster_name: str | None
cluster_set_name: str | None
profile_limit_memory: int | None
experimental_max_connections: int | None
cluster_name: str | None = Field(default=None)
cluster_set_name: str | None = Field(default=None)
profile_limit_memory: int | None = Field(default=None)
experimental_max_connections: int | None = Field(default=None)
Comment thread
sinclert-canonical marked this conversation as resolved.
binlog_retention_days: int
plugin_audit_enabled: bool
plugin_audit_strategy: str
logs_audit_policy: str
logs_retention_period: str
pause_after_unit_refresh: str

@validator("profile")
@field_validator("profile")
@classmethod
def profile_values(cls, value: str) -> str | None:
"""Check profile config option is one of `testing` or `production`."""
Expand All @@ -71,7 +71,7 @@ def profile_values(cls, value: str) -> str | None:

return value

@validator("cluster_name", "cluster_set_name")
@field_validator("cluster_name", "cluster_set_name")
@classmethod
def cluster_name_validator(cls, value: str) -> str | None:
"""Check for valid cluster, cluster-set name.
Expand All @@ -93,7 +93,7 @@ def cluster_name_validator(cls, value: str) -> str | None:

return value

@validator("profile_limit_memory")
@field_validator("profile_limit_memory")
@classmethod
def profile_limit_memory_validator(cls, value: int) -> int | None:
"""Check profile limit memory."""
Expand All @@ -104,7 +104,7 @@ def profile_limit_memory_validator(cls, value: int) -> int | None:

return value

@validator("experimental_max_connections")
@field_validator("experimental_max_connections")
@classmethod
def experimental_max_connections_validator(cls, value: int) -> int | None:
"""Check experimental max connections."""
Expand All @@ -116,7 +116,7 @@ def experimental_max_connections_validator(cls, value: int) -> int | None:

return value

@validator("binlog_retention_days")
@field_validator("binlog_retention_days")
@classmethod
def binlog_retention_days_validator(cls, value: int) -> int:
"""Check binlog retention days."""
Expand All @@ -125,7 +125,7 @@ def binlog_retention_days_validator(cls, value: int) -> int:

return value

@validator("plugin_audit_strategy")
@field_validator("plugin_audit_strategy")
@classmethod
def plugin_audit_strategy_validator(cls, value: str) -> str | None:
"""Check profile config option is one of `testing` or `production`."""
Expand All @@ -134,7 +134,7 @@ def plugin_audit_strategy_validator(cls, value: str) -> str | None:

return value

@validator("logs_audit_policy")
@field_validator("logs_audit_policy")
@classmethod
def logs_audit_policy_validator(cls, value: str) -> str | None:
"""Check values for audit log policy."""
Expand All @@ -144,7 +144,7 @@ def logs_audit_policy_validator(cls, value: str) -> str | None:

return value

@validator("logs_retention_period")
@field_validator("logs_retention_period")
@classmethod
def logs_retention_period_validator(cls, value: str) -> str:
"""Check logs retention period."""
Expand All @@ -153,7 +153,7 @@ def logs_retention_period_validator(cls, value: str) -> str:

return value

@validator("pause_after_unit_refresh")
@field_validator("pause_after_unit_refresh")
@classmethod
def pause_after_unit_refresh_validator(cls, value: str) -> str | None:
"""Check values for when to pause after unit refresh."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@

```python

from charms.data_platform_libs.v0.data_models import BaseConfigModel
from charms.data_platform_libs.v1.data_models import BaseConfigModel

class MyConfig(BaseConfigModel):

Expand Down Expand Up @@ -164,20 +164,27 @@ class MergedDataBag(ProviderDataBag, RequirerDataBag):
LIBID = "cb2094c5b07d47e1bf346aaee0fcfcfe"

# Increment this major API version when introducing breaking changes
LIBAPI = 0
LIBAPI = 1

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

PYDEPS = ["ops>=2.0.0", "pydantic>=1.10,<2"]
PYDEPS = ["ops>=2.0.0", "pydantic>=2,<3"]

G = TypeVar("G")
T = TypeVar("T", bound=BaseModel)
AppModel = TypeVar("AppModel", bound=BaseModel)
UnitModel = TypeVar("UnitModel", bound=BaseModel)

DataBagNativeTypes = (int, str, float)
DataBagNativeTypes = (
int,
str,
float,
Optional[int],
Optional[str],
Optional[float],
)


class BaseConfigModel(BaseModel):
Expand Down Expand Up @@ -233,7 +240,7 @@ def write(relation_data: RelationDataContent, model: BaseModel):
relation_data: pointer to the relation databag
model: instance of pydantic model to be written
"""
for key, value in model.dict(exclude_none=False).items():
for key, value in model.model_dump(exclude_none=False).items():
if value:
relation_data[key.replace("_", "-")] = (
str(value)
Expand All @@ -255,10 +262,10 @@ def read(relation_data: MutableMapping[str, str], obj: Type[T]) -> T:
**{
field_name: (
relation_data[parsed_key]
if field.outer_type_ in DataBagNativeTypes
if field_info.annotation in DataBagNativeTypes
else json.loads(relation_data[parsed_key])
)
for field_name, field in obj.__fields__.items()
for field_name, field_info in obj.model_fields.items()
# pyright: ignore[reportGeneralTypeIssues]
if (parsed_key := field_name.replace("_", "-")) in relation_data
if relation_data[parsed_key]
Expand Down
Loading
Loading