13
13
import sys
14
14
import time
15
15
from pathlib import Path
16
- from typing import Dict , List , Literal , Optional , Tuple , get_args
16
+ from typing import Literal , get_args
17
17
18
18
# First platform-specific import, will fail on wrong architecture
19
19
try :
@@ -254,7 +254,7 @@ def __init__(self, *args):
254
254
)
255
255
256
256
@property
257
- def tracing_endpoint (self ) -> Optional [ str ] :
257
+ def tracing_endpoint (self ) -> str | None :
258
258
"""Otlp http endpoint for charm instrumentation."""
259
259
if self .tracing .is_ready ():
260
260
return self .tracing .get_endpoint (TRACING_PROTOCOL )
@@ -267,7 +267,7 @@ def _pebble_log_forwarding_supported(self) -> bool:
267
267
juju_version = JujuVersion .from_environ ()
268
268
return juju_version > JujuVersion (version = "3.3" )
269
269
270
- def _generate_metrics_jobs (self , enable_tls : bool ) -> Dict :
270
+ def _generate_metrics_jobs (self , enable_tls : bool ) -> dict :
271
271
"""Generate spec for Prometheus scraping."""
272
272
return [
273
273
{"static_configs" : [{"targets" : [f"*:{ METRICS_PORT } " ]}]},
@@ -287,7 +287,7 @@ def app_units(self) -> set[Unit]:
287
287
return {self .unit , * self ._peers .units }
288
288
289
289
@property
290
- def app_peer_data (self ) -> Dict :
290
+ def app_peer_data (self ) -> dict :
291
291
"""Application peer relation data object."""
292
292
relation = self .model .get_relation (PEER )
293
293
if relation is None :
@@ -296,15 +296,15 @@ def app_peer_data(self) -> Dict:
296
296
return relation .data [self .app ]
297
297
298
298
@property
299
- def unit_peer_data (self ) -> Dict :
299
+ def unit_peer_data (self ) -> dict :
300
300
"""Unit peer relation data object."""
301
301
relation = self .model .get_relation (PEER )
302
302
if relation is None :
303
303
return {}
304
304
305
305
return relation .data [self .unit ]
306
306
307
- def _peer_data (self , scope : Scopes ) -> Dict :
307
+ def _peer_data (self , scope : Scopes ) -> dict :
308
308
"""Return corresponding databag for app/unit."""
309
309
relation = self .model .get_relation (PEER )
310
310
if relation is None :
@@ -333,7 +333,7 @@ def _translate_field_to_secret_key(self, key: str) -> str:
333
333
new_key = key .replace ("_" , "-" )
334
334
return new_key .strip ("-" )
335
335
336
- def get_secret (self , scope : Scopes , key : str ) -> Optional [ str ] :
336
+ def get_secret (self , scope : Scopes , key : str ) -> str | None :
337
337
"""Get secret from the secret storage."""
338
338
if scope not in get_args (Scopes ):
339
339
raise RuntimeError ("Unknown secret scope." )
@@ -348,7 +348,7 @@ def get_secret(self, scope: Scopes, key: str) -> Optional[str]:
348
348
349
349
return self .peer_relation_data (scope ).get_secret (peers .id , secret_key )
350
350
351
- def set_secret (self , scope : Scopes , key : str , value : Optional [ str ] ) -> Optional [ str ] :
351
+ def set_secret (self , scope : Scopes , key : str , value : str | None ) -> str | None :
352
352
"""Set secret from the secret storage."""
353
353
if scope not in get_args (Scopes ):
354
354
raise RuntimeError ("Unknown secret scope." )
@@ -426,14 +426,14 @@ def get_hostname_by_unit(self, unit_name: str) -> str:
426
426
unit_id = unit_name .split ("/" )[1 ]
427
427
return f"{ self .app .name } -{ unit_id } .{ self .app .name } -endpoints"
428
428
429
- def _get_endpoints_to_remove (self ) -> List [str ]:
429
+ def _get_endpoints_to_remove (self ) -> list [str ]:
430
430
"""List the endpoints that were part of the cluster but departed."""
431
431
old = self ._endpoints
432
432
current = [self ._get_hostname_from_unit (member ) for member in self ._hosts ]
433
433
endpoints_to_remove = list (set (old ) - set (current ))
434
434
return endpoints_to_remove
435
435
436
- def get_unit_ip (self , unit : Unit ) -> Optional [ str ] :
436
+ def get_unit_ip (self , unit : Unit ) -> str | None :
437
437
"""Get the IP address of a specific unit."""
438
438
# Check if host is current host.
439
439
if unit == self .unit :
@@ -683,7 +683,7 @@ def _on_config_changed(self, event) -> None:
683
683
)
684
684
return
685
685
686
- def enable_disable_extensions (self , database : Optional [ str ] = None ) -> None :
686
+ def enable_disable_extensions (self , database : str | None = None ) -> None :
687
687
"""Enable/disable PostgreSQL extensions set through config options.
688
688
689
689
Args:
@@ -1593,7 +1593,7 @@ def _endpoint(self) -> str:
1593
1593
return self ._get_hostname_from_unit (self ._unit_name_to_pod_name (self .unit .name ))
1594
1594
1595
1595
@property
1596
- def _endpoints (self ) -> List [str ]:
1596
+ def _endpoints (self ) -> list [str ]:
1597
1597
"""Cluster members hostnames."""
1598
1598
if self ._peers :
1599
1599
return json .loads (self ._peers .data [self .app ].get ("endpoints" , "[]" ))
@@ -1602,7 +1602,7 @@ def _endpoints(self) -> List[str]:
1602
1602
return [self ._endpoint ]
1603
1603
1604
1604
@property
1605
- def peer_members_endpoints (self ) -> List [str ]:
1605
+ def peer_members_endpoints (self ) -> list [str ]:
1606
1606
"""Fetch current list of peer members endpoints.
1607
1607
1608
1608
Returns:
@@ -1621,14 +1621,14 @@ def _add_to_endpoints(self, endpoint) -> None:
1621
1621
"""Add one endpoint to the members list."""
1622
1622
self ._update_endpoints (endpoint_to_add = endpoint )
1623
1623
1624
- def _remove_from_endpoints (self , endpoints : List [str ]) -> None :
1624
+ def _remove_from_endpoints (self , endpoints : list [str ]) -> None :
1625
1625
"""Remove endpoints from the members list."""
1626
1626
self ._update_endpoints (endpoints_to_remove = endpoints )
1627
1627
1628
1628
def _update_endpoints (
1629
1629
self ,
1630
- endpoint_to_add : Optional [ str ] = None ,
1631
- endpoints_to_remove : Optional [ List [ str ]] = None ,
1630
+ endpoint_to_add : str | None = None ,
1631
+ endpoints_to_remove : list [ str ] | None = None ,
1632
1632
) -> None :
1633
1633
"""Update members IPs."""
1634
1634
# Allow leader to reset which members are part of the cluster.
@@ -1643,7 +1643,7 @@ def _update_endpoints(
1643
1643
endpoints .remove (endpoint )
1644
1644
self ._peers .data [self .app ]["endpoints" ] = json .dumps (endpoints )
1645
1645
1646
- def _generate_metrics_service (self ) -> Dict :
1646
+ def _generate_metrics_service (self ) -> dict :
1647
1647
"""Generate the metrics service definition."""
1648
1648
return {
1649
1649
"override" : "replace" ,
@@ -2012,7 +2012,7 @@ def _get_node_name_for_pod(self) -> str:
2012
2012
)
2013
2013
return pod .spec .nodeName
2014
2014
2015
- def get_resources_limits (self , container_name : str ) -> Dict :
2015
+ def get_resources_limits (self , container_name : str ) -> dict :
2016
2016
"""Return resources limits for a given container.
2017
2017
2018
2018
Args:
@@ -2040,7 +2040,7 @@ def get_node_cpu_cores(self) -> int:
2040
2040
node = client .get (Node , name = self ._get_node_name_for_pod (), namespace = self ._namespace )
2041
2041
return any_cpu_to_cores (node .status .allocatable ["cpu" ])
2042
2042
2043
- def get_available_resources (self ) -> Tuple [int , int ]:
2043
+ def get_available_resources (self ) -> tuple [int , int ]:
2044
2044
"""Get available CPU cores and memory (in bytes) for the container."""
2045
2045
cpu_cores = self .get_node_cpu_cores ()
2046
2046
allocable_memory = self .get_node_allocable_memory ()
@@ -2073,7 +2073,7 @@ def on_deployed_without_trust(self) -> None:
2073
2073
)
2074
2074
2075
2075
@property
2076
- def client_relations (self ) -> List [Relation ]:
2076
+ def client_relations (self ) -> list [Relation ]:
2077
2077
"""Return the list of established client relations."""
2078
2078
relations = []
2079
2079
for relation_name in ["database" , "db" , "db-admin" ]:
@@ -2150,15 +2150,15 @@ def restore_patroni_on_failure_condition(self) -> None:
2150
2150
else :
2151
2151
logger .warning ("not restoring patroni on-failure condition as it's not overridden" )
2152
2152
2153
- def is_pitr_failed (self , container : Container ) -> Tuple [bool , bool ]:
2153
+ def is_pitr_failed (self , container : Container ) -> tuple [bool , bool ]:
2154
2154
"""Check if Patroni service failed to bootstrap cluster during point-in-time-recovery.
2155
2155
2156
2156
Typically, this means that database service failed to reach point-in-time-recovery target or has been
2157
2157
supplied with bad PITR parameter. Also, remembers last state and can provide info is it new event, or
2158
2158
it belongs to previous action. Executes only on current unit.
2159
2159
2160
2160
Returns:
2161
- Tuple [bool, bool]:
2161
+ tuple [bool, bool]:
2162
2162
- Is patroni service failed to bootstrap cluster.
2163
2163
- Is it new fail, that wasn't observed previously.
2164
2164
"""
@@ -2228,7 +2228,7 @@ def log_pitr_last_transaction_time(self) -> None:
2228
2228
else :
2229
2229
logger .error ("Can't tell last completed transaction time" )
2230
2230
2231
- def get_plugins (self ) -> List [str ]:
2231
+ def get_plugins (self ) -> list [str ]:
2232
2232
"""Return a list of installed plugins."""
2233
2233
plugins = [
2234
2234
"_" .join (plugin .split ("_" )[1 :- 1 ])
0 commit comments