Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-leaders overwrite local keys with what the leader has #48435

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def setup_non_leader_authentication():
known_tokens = '/root/cdk/known_tokens.csv'

keys = [service_key, basic_auth, known_tokens]
if not get_keys_from_leader(keys):
# The source of truth for non-leaders is the leader.
# Therefore we overwrite_local with whatever the leader has.
if not get_keys_from_leader(keys, overwrite_local=True):
# the keys were not retrieved. Non-leaders have to retry.
return

Expand All @@ -268,7 +270,7 @@ def setup_non_leader_authentication():
set_state('authentication.setup')


def get_keys_from_leader(keys):
def get_keys_from_leader(keys, overwrite_local=False):
"""
Gets the broadcasted keys from the leader and stores them in
the corresponding files.
Expand All @@ -285,7 +287,7 @@ def get_keys_from_leader(keys):

for k in keys:
# If the path does not exist, assume we need it
if not os.path.exists(k):
if not os.path.exists(k) or overwrite_local:
# Fetch data from leadership broadcast
contents = charms.leadership.leader_get(k)
# Default to logging the warning and wait for leader data to be set
Expand Down