Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Iman Enami committed Dec 18, 2024
1 parent c492942 commit 4628288
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
16 changes: 1 addition & 15 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(
self._balancer_uris = balancer_uris
self._controller_password = controller_password

def _fetch_from_secrets(self, group, field):
def _fetch_from_secrets(self, group, field) -> str:
if not self.relation:
return ""

Expand Down Expand Up @@ -166,13 +166,6 @@ def broker_username(self) -> str:

return self._fetch_from_secrets("broker", "broker-username")

return self.data_interface._fetch_relation_data_with_secrets(
component=self.relation.app,
req_secret_fields=BALANCER.requested_secrets,
relation=self.relation,
fields=BALANCER.requested_secrets,
).get("broker-username", "")

@property
def broker_password(self) -> str:
"""The provided password for the broker application."""
Expand All @@ -184,13 +177,6 @@ def broker_password(self) -> str:

return self._fetch_from_secrets("broker", "broker-password")

return self.data_interface._fetch_relation_data_with_secrets(
component=self.relation.app,
req_secret_fields=BALANCER.requested_secrets,
relation=self.relation,
fields=BALANCER.requested_secrets,
).get("broker-password", "")

@property
def broker_uris(self) -> str:
"""The provided uris for the balancer application to connect to the broker application."""
Expand Down
4 changes: 2 additions & 2 deletions src/events/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _on_start(self, event: StartEvent | PebbleReadyEvent) -> None: # noqa: C901
event.defer()
return

self.broker.config_manager.set_server_properties()
self._format_storages()

# update status to add controller
Expand All @@ -97,7 +96,7 @@ def _init_kraft_mode(self) -> None:
"""Initialize the server when running controller mode."""
# NOTE: checks for `runs_broker` in this method should be `is_cluster_manager` in
# the large deployment feature.
if not self.model.unit.is_leader():
if not self.model.unit.is_leader() or not self.charm.state.kraft_mode:
return

if not self.charm.state.cluster.internal_user_credentials and self.charm.state.runs_broker:
Expand Down Expand Up @@ -143,6 +142,7 @@ def _format_storages(self) -> None:
if not self.charm.state.kraft_mode:
return

self.broker.config_manager.set_server_properties()
if self.charm.state.runs_broker:
credentials = self.charm.state.cluster.internal_user_credentials
elif self.charm.state.runs_controller:
Expand Down
1 change: 0 additions & 1 deletion src/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@ def controller_properties(self) -> list[str]:
properties = [
f"process.roles={','.join(roles)}",
f"node.id={node_id}",
# f"controller.quorum.voters={self.state.peer_cluster.controller_quorum_uris}",
f"controller.quorum.bootstrap.servers={self.state.peer_cluster.bootstrap_controller}",
f"controller.listener.names={CONTROLLER_LISTENER_NAME}",
*self.controller_scram_properties,
Expand Down
5 changes: 3 additions & 2 deletions src/managers/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
from subprocess import CalledProcessError
from typing import TYPE_CHECKING

from tenacity import retry, stop_after_attempt, wait_fixed
Expand Down Expand Up @@ -134,8 +135,8 @@ def remove_controller(
controller_directory_id,
],
)
except Exception as e:
error_details = getattr(e, "stderr")
except CalledProcessError as e:
error_details = e.stderr
if "VoterNotFoundException" in error_details or "TimeoutException" in error_details:
# successful
return
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_start_defers_without_zookeeper(ctx: Context, base_state: State) -> None
state_out = ctx.run(ctx.on.start(), state_in)

# Then
assert len(state_out.deferred) == 1
assert len(state_out.deferred) == 2
assert state_out.deferred[0].name == "start"


Expand Down

0 comments on commit 4628288

Please sign in to comment.