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

Restart if we get any updates to keys from concourse-worker #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _core_v1_api():

class ConcourseWebOperatorCharm(CharmBase):
_authed = False
_restart_required = False
_stored = StoredState()

def __init__(self, *args):
Expand Down Expand Up @@ -71,8 +72,6 @@ def _on_peer_relation_changed(self, event):
# defined on the peer relation, and if not, and we're the leader, create
# them.

# We're crea

# First, check if they already exist on disk, if so, exit. We're
# checking in the charm container and we'll "mirror" content from here
# into the workload container.
Expand Down Expand Up @@ -107,6 +106,9 @@ def _on_peer_relation_changed(self, event):
keys_found = False
if keys_found:
logger.info("Found all concourse keys via the relation.")
# Trigger our config changed hook again.
self._restart_required = True
self.on.config_changed.emit()
return

# Assuming they're not available on the relation, we need to generate
Expand Down Expand Up @@ -158,6 +160,10 @@ def _on_peer_relation_changed(self, event):
event.relation.data[self.app]["CONCOURSE_TSA_HOST_KEY_PUB"] = tsa_host_key_pub_data
logger.info("Set CONCOURSE_TSA_HOST_KEY_PUB on the concourse-web peer relation.")

# Trigger our config changed hook again.
self._restart_required = True
self.on.config_changed.emit()

def _get_concourse_binary_path(self):
container = self.unit.get_container("concourse-web")
with NamedTemporaryFile(delete=False) as temp:
Expand Down Expand Up @@ -283,6 +289,9 @@ def _on_concourse_worker_relation_changed(self, event):
with open(self._concourse_key_locations["CONCOURSE_TSA_AUTHORIZED_KEYS"], "w") as authorized_keys:
authorized_keys.write("\n".join(self._stored.concourse_worker_pub_keys))
logger.info("Updated CONCOURSE_TSA_AUTHORIZED_KEYS file")
# Trigger our config changed hook again.
self._restart_required = True
self.on.config_changed.emit()

def _on_concourse_worker_relation_broken(self, _):
self._stored.concourse_worker = False
Expand Down Expand Up @@ -378,12 +387,13 @@ def _on_config_changed(self, event):
return
# Update our ingress definition if appropriate.
self.ingress.update_config(self.ingress_config)
if services != layer["services"]:
if self._restart_required or services != layer["services"]:
container.add_layer("concourse-web", layer, combine=True)
logger.info("Added updated layer to concourse")
if container.get_service("concourse-web").is_running():
container.stop("concourse-web")
container.start("concourse-web")
self._restart_required = False
logger.info("Restarted concourse-web service")
self.unit.status = ActiveStatus()

Expand Down