Skip to content

Commit ce40968

Browse files
[DPE-4416] Fetch charm libs to the latest LIBPATCH (update dp-libs to v36 to fix secrets issue) (#475)
* [DPE-4416] Fetch charm libs to the latest LIBPATCH Co-authored-by: Alex Lutay <[email protected]>
1 parent fbffd4a commit ce40968

File tree

3 files changed

+50
-31
lines changed

3 files changed

+50
-31
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 34
334+
LIBPATCH = 36
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -642,16 +642,16 @@ def _move_to_new_label_if_needed(self):
642642
return
643643

644644
# Create a new secret with the new label
645-
old_meta = self._secret_meta
646645
content = self._secret_meta.get_content()
646+
self._secret_uri = None
647647

648648
# I wish we could just check if we are the owners of the secret...
649649
try:
650650
self._secret_meta = self.add_secret(content, label=self.label)
651651
except ModelError as err:
652652
if "this unit is not the leader" not in str(err):
653653
raise
654-
old_meta.remove_all_revisions()
654+
self.current_label = None
655655

656656
def set_content(self, content: Dict[str, str]) -> None:
657657
"""Setting cached secret content."""
@@ -1586,7 +1586,7 @@ def _register_secret_to_relation(
15861586
"""
15871587
label = self._generate_secret_label(relation_name, relation_id, group)
15881588

1589-
# Fetchin the Secret's meta information ensuring that it's locally getting registered with
1589+
# Fetching the Secret's meta information ensuring that it's locally getting registered with
15901590
CachedSecret(self._model, self.component, label, secret_id).meta
15911591

15921592
def _register_secrets_to_relation(self, relation: Relation, params_name_list: List[str]):
@@ -2309,7 +2309,7 @@ def _secrets(self) -> dict:
23092309
return self._cached_secrets
23102310

23112311
def _get_secret(self, group) -> Optional[Dict[str, str]]:
2312-
"""Retrieveing secrets."""
2312+
"""Retrieving secrets."""
23132313
if not self.app:
23142314
return
23152315
if not self._secrets.get(group):
@@ -3016,7 +3016,7 @@ class KafkaRequiresEvents(CharmEvents):
30163016
# Kafka Provides and Requires
30173017

30183018

3019-
class KafkaProvidesData(ProviderData):
3019+
class KafkaProviderData(ProviderData):
30203020
"""Provider-side of the Kafka relation."""
30213021

30223022
def __init__(self, model: Model, relation_name: str) -> None:
@@ -3059,12 +3059,12 @@ def set_zookeeper_uris(self, relation_id: int, zookeeper_uris: str) -> None:
30593059
self.update_relation_data(relation_id, {"zookeeper-uris": zookeeper_uris})
30603060

30613061

3062-
class KafkaProvidesEventHandlers(EventHandlers):
3062+
class KafkaProviderEventHandlers(EventHandlers):
30633063
"""Provider-side of the Kafka relation."""
30643064

30653065
on = KafkaProvidesEvents() # pyright: ignore [reportAssignmentType]
30663066

3067-
def __init__(self, charm: CharmBase, relation_data: KafkaProvidesData) -> None:
3067+
def __init__(self, charm: CharmBase, relation_data: KafkaProviderData) -> None:
30683068
super().__init__(charm, relation_data)
30693069
# Just to keep lint quiet, can't resolve inheritance. The same happened in super().__init__() above
30703070
self.relation_data = relation_data
@@ -3086,15 +3086,15 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
30863086
)
30873087

30883088

3089-
class KafkaProvides(KafkaProvidesData, KafkaProvidesEventHandlers):
3089+
class KafkaProvides(KafkaProviderData, KafkaProviderEventHandlers):
30903090
"""Provider-side of the Kafka relation."""
30913091

30923092
def __init__(self, charm: CharmBase, relation_name: str) -> None:
3093-
KafkaProvidesData.__init__(self, charm.model, relation_name)
3094-
KafkaProvidesEventHandlers.__init__(self, charm, self)
3093+
KafkaProviderData.__init__(self, charm.model, relation_name)
3094+
KafkaProviderEventHandlers.__init__(self, charm, self)
30953095

30963096

3097-
class KafkaRequiresData(RequirerData):
3097+
class KafkaRequirerData(RequirerData):
30983098
"""Requirer-side of the Kafka relation."""
30993099

31003100
def __init__(
@@ -3124,12 +3124,12 @@ def topic(self, value):
31243124
self._topic = value
31253125

31263126

3127-
class KafkaRequiresEventHandlers(RequirerEventHandlers):
3127+
class KafkaRequirerEventHandlers(RequirerEventHandlers):
31283128
"""Requires-side of the Kafka relation."""
31293129

31303130
on = KafkaRequiresEvents() # pyright: ignore [reportAssignmentType]
31313131

3132-
def __init__(self, charm: CharmBase, relation_data: KafkaRequiresData) -> None:
3132+
def __init__(self, charm: CharmBase, relation_data: KafkaRequirerData) -> None:
31333133
super().__init__(charm, relation_data)
31343134
# Just to keep lint quiet, can't resolve inheritance. The same happened in super().__init__() above
31353135
self.relation_data = relation_data
@@ -3142,10 +3142,13 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
31423142
return
31433143

31443144
# Sets topic, extra user roles, and "consumer-group-prefix" in the relation
3145-
relation_data = {
3146-
f: getattr(self, f.replace("-", "_"), "")
3147-
for f in ["consumer-group-prefix", "extra-user-roles", "topic"]
3148-
}
3145+
relation_data = {"topic": self.relation_data.topic}
3146+
3147+
if self.relation_data.extra_user_roles:
3148+
relation_data["extra-user-roles"] = self.relation_data.extra_user_roles
3149+
3150+
if self.relation_data.consumer_group_prefix:
3151+
relation_data["consumer-group-prefix"] = self.relation_data.consumer_group_prefix
31493152

31503153
self.relation_data.update_relation_data(event.relation.id, relation_data)
31513154

@@ -3188,7 +3191,7 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
31883191
return
31893192

31903193

3191-
class KafkaRequires(KafkaRequiresData, KafkaRequiresEventHandlers):
3194+
class KafkaRequires(KafkaRequirerData, KafkaRequirerEventHandlers):
31923195
"""Provider-side of the Kafka relation."""
31933196

31943197
def __init__(
@@ -3200,7 +3203,7 @@ def __init__(
32003203
consumer_group_prefix: Optional[str] = None,
32013204
additional_secret_fields: Optional[List[str]] = [],
32023205
) -> None:
3203-
KafkaRequiresData.__init__(
3206+
KafkaRequirerData.__init__(
32043207
self,
32053208
charm.model,
32063209
relation_name,
@@ -3209,7 +3212,7 @@ def __init__(
32093212
consumer_group_prefix,
32103213
additional_secret_fields,
32113214
)
3212-
KafkaRequiresEventHandlers.__init__(self, charm, self)
3215+
KafkaRequirerEventHandlers.__init__(self, charm, self)
32133216

32143217

32153218
# Opensearch related events

lib/charms/data_platform_libs/v0/upgrade.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def restart(self, event) -> None:
285285

286286
# Increment this PATCH version before using `charmcraft publish-lib` or reset
287287
# to 0 if you are raising the major API version
288-
LIBPATCH = 15
288+
LIBPATCH = 16
289289

290290
PYDEPS = ["pydantic>=1.10,<2", "poetry-core"]
291291

@@ -501,7 +501,7 @@ class DataUpgrade(Object, ABC):
501501

502502
STATES = ["recovery", "failed", "idle", "ready", "upgrading", "completed"]
503503

504-
on = UpgradeEvents() # pyright: ignore [reportGeneralTypeIssues]
504+
on = UpgradeEvents() # pyright: ignore [reportAssignmentType]
505505

506506
def __init__(
507507
self,
@@ -606,6 +606,21 @@ def upgrade_stack(self, stack: List[int]) -> None:
606606
self.peer_relation.data[self.charm.app].update({"upgrade-stack": json.dumps(stack)})
607607
self._upgrade_stack = stack
608608

609+
@property
610+
def other_unit_states(self) -> list:
611+
"""Current upgrade state for other units.
612+
613+
Returns:
614+
Unsorted list of upgrade states for other units.
615+
"""
616+
if not self.peer_relation:
617+
return []
618+
619+
return [
620+
self.peer_relation.data[unit].get("state", "")
621+
for unit in list(self.peer_relation.units)
622+
]
623+
609624
@property
610625
def unit_states(self) -> list:
611626
"""Current upgrade state for all units.
@@ -926,11 +941,8 @@ def on_upgrade_changed(self, event: EventBase) -> None:
926941
return
927942

928943
if self.substrate == "vm" and self.cluster_state == "recovery":
929-
# Only defer for vm, that will set unit states to "ready" on upgrade-charm
930-
# on k8s only the upgrading unit will receive the upgrade-charm event
931-
# and deferring will prevent the upgrade stack from being popped
932-
logger.debug("Cluster in recovery, deferring...")
933-
event.defer()
944+
# skip run while in recovery. The event will be retrigged when the cluster is ready
945+
logger.debug("Cluster in recovery, skip...")
934946
return
935947

936948
# if all units completed, mark as complete
@@ -981,6 +993,7 @@ def on_upgrade_changed(self, event: EventBase) -> None:
981993
self.charm.unit == top_unit
982994
and top_state in ["ready", "upgrading"]
983995
and self.cluster_state == "ready"
996+
and "upgrading" not in self.other_unit_states
984997
):
985998
logger.debug(
986999
f"{top_unit.name} is next to upgrade, emitting `upgrade_granted` event and upgrading..."

lib/charms/operator_libs_linux/v2/snap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

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

8888

8989
# Regex to locate 7-bit C1 ANSI sequences
@@ -584,13 +584,16 @@ def ensure(
584584
"Installing snap %s, revision %s, tracking %s", self._name, revision, channel
585585
)
586586
self._install(channel, cohort, revision)
587-
else:
587+
logger.info("The snap installation completed successfully")
588+
elif revision is None or revision != self._revision:
588589
# The snap is installed, but we are changing it (e.g., switching channels).
589590
logger.info(
590591
"Refreshing snap %s, revision %s, tracking %s", self._name, revision, channel
591592
)
592593
self._refresh(channel=channel, cohort=cohort, revision=revision, devmode=devmode)
593-
logger.info("The snap installation completed successfully")
594+
logger.info("The snap refresh completed successfully")
595+
else:
596+
logger.info("Refresh of snap %s was unnecessary", self._name)
594597

595598
self._update_snap_apps()
596599
self._state = state

0 commit comments

Comments
 (0)