Skip to content

Commit

Permalink
Merge pull request #46 from kiwix/worker-manager-add-wgport-setting
Browse files Browse the repository at this point in the history
add setting for client to update wireguard port.
  • Loading branch information
elfkuzco authored Sep 2, 2024
2 parents b522855 + dffca52 commit 355dbfa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ The `backend` code houses the `scheduler` and the `RESTful API`. The following e
- `DOCKER_API_RETRIES`: how many times to retry requests to the Docker daemon
- `DOCKER_API_RETRY_DURATION`: how long to wait before retrying a failed request
- `WIREGUARD_IMAGE`
- `WIREGUARD_PORT`: port for routing wireguard traffic in the wireguard container. This is not the exposed port.
- `WIREGUARD_KERNEL_MODULES`: where to load wireguard kernel modules from (default `/lib/modules`)
- `WIREGUARD_HEALTHCHECK_INTERVAL_SECONDS`
- `WIREGUARD_HEALTHCHECK_TIMEOUT_SECONDS`
Expand Down
1 change: 1 addition & 0 deletions worker/manager/src/mirrors_qa_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Settings:
WIREGUARD_CONTAINER_NAME = getenv(
"WIREGUARD_CONTAINER_NAME", default="mirrors-qa-wireguard"
)
WIREGUARD_PORT = int(getenv("WIREGUARD_PORT", default=51820))
# Optional path for loading kernel modules for wireguard container
WIREGUARD_KERNEL_MODULES_FPATH = Path(
getenv("WIREGUARD_KERNEL_MODULES", default="/lib/modules")
Expand Down
12 changes: 7 additions & 5 deletions worker/manager/src/mirrors_qa_manager/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import signal
import sys
import time
from collections.abc import Iterable
from collections.abc import Generator
from enum import Enum
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -131,8 +131,8 @@ def wg_container_is_healthy(self) -> ExecResult | None:
Settings.WIREGUARD_CONTAINER_NAME,
self.wg_healthcheck_cmd,
)
except APIError:
logger.error("error whlie performing healthcheck: {exc!s}")
except APIError as exc:
logger.error(f"error whlie performing healthcheck: {exc!s}")
return None

def wg_healthcheck_untill_healthy(
Expand Down Expand Up @@ -201,7 +201,9 @@ def start_wireguard_container(self, image_name: str, conf_fpath: Path) -> Contai
"timeout": Settings.WIREGUARD_HEALTHCHECK_TIMEOUT_NANOSECONDS,
"retries": Settings.WIREGUARD_HEALTHCHECK_RETRIES,
},
ports={"51820/udp": None}, # Let the host assign a random port
ports={
f"{Settings.WIREGUARD_PORT}/udp": None
}, # Let the host assign a random port
sysctls={"net.ipv4.conf.all.src_valid_mark": 1},
environment={
"PUID": 1000,
Expand Down Expand Up @@ -292,7 +294,7 @@ def update_countries_list(self):
"countries."
)

def fetch_tests(self) -> Iterable[dict[str, str]]:
def fetch_tests(self) -> Generator[dict[str, str], None, None]:
logger.debug("Fetching tasks from backend API")
# Fetch tasks that were assigned to the worker that haven't been expired
params = urlencode({"worker_id": self.worker_id, "status": "PENDING"})
Expand Down

0 comments on commit 355dbfa

Please sign in to comment.