Skip to content

Commit 7b38949

Browse files
authored
fix: avoid retriggering the CONFIG_LOADED action multiple times (#186)
The get_init_tasks function is called a few times inside the Jinja2 templates. The function used internal Tutor modules to load the user configuration, this caused the `CONFIG_LOADED` action to trigger hooks multiple times. Instead of manually load the Tutor configuration using Tutor's internal functions we now rely on the very same `CONFIG_LOADED` action to register a hook that will store the value of the configuration in a global variable.
1 parent a46cdd5 commit 7b38949

5 files changed

Lines changed: 25 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ See the fragment files in the [changelog.d/ directory](./changelog.d).
1313

1414
<!-- scriv-insert-here -->
1515

16+
<a id='changelog-21.2.1'></a>
17+
## 21.2.1 — 2026-05-28
18+
19+
### Fixed
20+
21+
- Properly mirror the LMS caddy block in the default catch-all block used by `DRYDOCK_ENABLE_MULTITENANCY`.
22+
23+
- Avoid retriggering the CONFIG_LOADED action multiple times when redering the
24+
jobs templates.
25+
1626
<a id='changelog-21.2.0'></a>
1727
## 21.2.0 — 2026-04-24
1828

changelog.d/20260525_165246_deimer.morales_refactor_extra_lms_rules.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

drydock/plugin.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from glob import glob
66

77
import click
8-
from tutor import config as tutor_config
98
from tutor import env as tutor_env
109
from tutor import hooks as tutor_hooks
1110
from tutor import serialize, types
@@ -17,6 +16,8 @@
1716

1817
INIT_JOBS_SYNC_WAVE = 1
1918

19+
TUTOR_CONFIG: types.Config = {}
20+
2021
tutor_hooks.Filters.CONFIG_DEFAULTS.add_items(
2122
[
2223
("DRYDOCK_VERSION", __version__),
@@ -59,6 +60,12 @@
5960
)
6061

6162

63+
@tutor_hooks.Actions.CONFIG_LOADED.add()
64+
def _capture_config(config: types.Config) -> None:
65+
global TUTOR_CONFIG
66+
TUTOR_CONFIG = config
67+
68+
6269
# This function is taken from
6370
# https://github.com/overhangio/tutor/blob/v16.1.8/tutor/commands/k8s.py#L182
6471
def _load_jobs(tutor_conf: types.Config) -> t.Iterable[t.Any]:
@@ -73,21 +80,21 @@ def _load_jobs(tutor_conf: types.Config) -> t.Iterable[t.Any]:
7380
# and https://github.com/overhangio/tutor/blob/v16.1.8/tutor/commands/k8s.py#L82
7481
def get_init_tasks():
7582
"""Return the list of init tasks to run."""
83+
if not TUTOR_CONFIG:
84+
return []
7685
init_tasks = list(tutor_hooks.Filters.CLI_DO_INIT_TASKS.iterate())
77-
context = click.get_current_context().obj
78-
tutor_conf = tutor_config.load(context.root)
79-
jobs = tutor_conf.get("DRYDOCK_INIT_JOBS_EXCLUDED", [])
86+
jobs = TUTOR_CONFIG.get("DRYDOCK_INIT_JOBS_EXCLUDED", [])
8087
if not isinstance(jobs, list):
8188
click.secho("'DRYDOCK_INIT_JOBS_EXCLUDED' must be a list. Ignoring.", fg="yellow")
8289
jobs = []
8390
excluded_init_jobs = set(jobs)
8491

8592
for i, (service, command) in enumerate(init_tasks):
86-
for template in _load_jobs(tutor_conf):
93+
for template in _load_jobs(TUTOR_CONFIG):
8794
if template["metadata"]["name"] != service + "-job" or template["metadata"]["name"] in excluded_init_jobs:
8895
continue
8996

90-
render_command = tutor_env.render_str(tutor_conf, command)
97+
render_command = tutor_env.render_str(TUTOR_CONFIG, command)
9198

9299
template["metadata"]["name"] = "drydock-" + template["metadata"]["name"] + "-" + str(i)
93100
template["metadata"]["labels"].update(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "tutor-contrib-drydock"
3-
version = "21.2.0"
3+
version = "21.2.1"
44
description = "A Tutor plugin to manage our opinionated Open edX operations"
55
readme = "README.md"
66
requires-python = ">=3.10"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)