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

Add timeout to container.exec #218

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def _alertmanager_version(self) -> Optional[str]:
"""
if not self.is_ready:
return None
version_output, _ = self._container.exec([self._exe_name, "--version"]).wait_output()
version_output, _ = self._container.exec(
[self._exe_name, "--version"], timeout=3
).wait_output()
# Output looks like this:
# alertmanager, version 0.23.0 (branch: HEAD, ...
result = re.search(r"version (\d*\.\d*\.\d*)", version_output)
Expand All @@ -159,7 +161,9 @@ def check_config(self) -> Tuple[str, str]:
raise ContainerNotReady(
"cannot check config: alertmanager workload container not ready"
)
proc = self._container.exec([self._amtool_path, "check-config", self._config_path])
proc = self._container.exec(
[self._amtool_path, "check-config", self._config_path], timeout=3
)
try:
output, err = proc.wait_output()
except ExecError as e:
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def _on_upgrade_charm(self, _):

def _update_ca_certs(self):
# Workload container
self.container.exec(["update-ca-certificates", "--fresh"]).wait()
self.container.exec(["update-ca-certificates", "--fresh"], timeout=3).wait()

# Charm container
ca_cert_path = Path(self._ca_cert_path)
Expand Down
Loading