From fc34bc74aacc802af746c1298bf1f88ce1b83880 Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Mon, 13 Feb 2023 11:59:30 +0000 Subject: [PATCH 1/4] added `remove_named_servers` setting --- docs/topic/idle-culler.md | 16 ++++++++++++++++ tljh/configurer.py | 3 +++ 2 files changed, 19 insertions(+) diff --git a/docs/topic/idle-culler.md b/docs/topic/idle-culler.md index ecb0243..89e400a 100644 --- a/docs/topic/idle-culler.md +++ b/docs/topic/idle-culler.md @@ -40,6 +40,12 @@ the users will not be culled alongside their notebooks and will continue to exis services.cull.users = False ``` +If named servers are in use, they are not removed after being culled. + +```python +services.cull.remove_named_servers = False +``` + ## Configuring the idle culler The available configuration options are: @@ -76,6 +82,16 @@ sudo tljh-config set services.cull.max_age sudo tljh-config reload ``` +### Remove Named Servers + +Remove named servers after they are shutdown. Only applies if named servers are +enabled on the hub installation: + +```bash +sudo tljh-config set services.cull.remove_named_servers True +sudo tljh-config reload +``` + ### User culling In addition to servers, it is also possible to cull the users. This is usually diff --git a/tljh/configurer.py b/tljh/configurer.py index e753afa..f731ee7 100644 --- a/tljh/configurer.py +++ b/tljh/configurer.py @@ -59,6 +59,7 @@ default = { "concurrency": 5, "users": False, "max_age": 0, + "remove_named_servers": False }, "configurator": {"enabled": False}, }, @@ -256,6 +257,8 @@ def set_cull_idle_service(config): cull_cmd += ["--max-age=%d" % cull_config["max_age"]] if cull_config["users"]: cull_cmd += ["--cull-users"] + if cull_config["remove_named_servers"]: + cull_cmd += ["--remove-named-servers"] cull_service = { "name": "cull-idle", From 3f180a939fd1fc675198d0d95db76e333d3a0f2b Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Mon, 20 Mar 2023 17:32:24 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A7=AA=20add=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_configurer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_configurer.py b/tests/test_configurer.py index 18586bf..e2f5179 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -193,6 +193,32 @@ def test_cull_service_default(): } ] +def test_cull_service_named(): + """ + Test default cull service settings with named server removal + """ + c = apply_mock_config( + {"services": {"cull": {"every": 10, "remove_named_servers": True, "max_age": 60}}} + ) + + cull_cmd = [ + sys.executable, + "-m", + "jupyterhub_idle_culler", + "--timeout=600", + "--cull-every=10", + "--concurrency=5", + "--max-age=60", + "--remove-named-servers", + ] + assert c.JupyterHub.services == [ + { + "name": "cull-idle", + "admin": True, + "command": cull_cmd, + } + ] + def test_set_cull_service(): """ From 836056f404fcd9f35e69267718db9d17c7144453 Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Mon, 20 Mar 2023 17:53:31 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=92=9A=20green=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_configurer.py | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/test_configurer.py b/tests/test_configurer.py index e2f5179..e05d051 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -193,33 +193,6 @@ def test_cull_service_default(): } ] -def test_cull_service_named(): - """ - Test default cull service settings with named server removal - """ - c = apply_mock_config( - {"services": {"cull": {"every": 10, "remove_named_servers": True, "max_age": 60}}} - ) - - cull_cmd = [ - sys.executable, - "-m", - "jupyterhub_idle_culler", - "--timeout=600", - "--cull-every=10", - "--concurrency=5", - "--max-age=60", - "--remove-named-servers", - ] - assert c.JupyterHub.services == [ - { - "name": "cull-idle", - "admin": True, - "command": cull_cmd, - } - ] - - def test_set_cull_service(): """ Test setting cull service options @@ -245,6 +218,32 @@ def test_set_cull_service(): } ] +def test_cull_service_named(): + """ + Test default cull service settings with named server removal + """ + c = apply_mock_config( + {"services": {"cull": {"every": 10, "cull_users": True, "remove_named_servers": True, "max_age": 60}}} + ) + + cull_cmd = [ + sys.executable, + "-m", + "jupyterhub_idle_culler", + "--timeout=600", + "--cull-every=10", + "--concurrency=5", + "--max-age=60", + "--cull-users", + "--remove-named-servers", + ] + assert c.JupyterHub.services == [ + { + "name": "cull-idle", + "admin": True, + "command": cull_cmd, + } + ] def test_load_secrets(tljh_dir): """ From e6994aab2da54b427328ec8168af933791f28002 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 00:10:25 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_configurer.py | 14 +++++++++++++- tljh/configurer.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_configurer.py b/tests/test_configurer.py index e05d051..bbef8c4 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -193,6 +193,7 @@ def test_cull_service_default(): } ] + def test_set_cull_service(): """ Test setting cull service options @@ -218,12 +219,22 @@ def test_set_cull_service(): } ] + def test_cull_service_named(): """ Test default cull service settings with named server removal """ c = apply_mock_config( - {"services": {"cull": {"every": 10, "cull_users": True, "remove_named_servers": True, "max_age": 60}}} + { + "services": { + "cull": { + "every": 10, + "cull_users": True, + "remove_named_servers": True, + "max_age": 60, + } + } + } ) cull_cmd = [ @@ -245,6 +256,7 @@ def test_cull_service_named(): } ] + def test_load_secrets(tljh_dir): """ Test loading secret files diff --git a/tljh/configurer.py b/tljh/configurer.py index f731ee7..e5c2ea2 100644 --- a/tljh/configurer.py +++ b/tljh/configurer.py @@ -59,7 +59,7 @@ default = { "concurrency": 5, "users": False, "max_age": 0, - "remove_named_servers": False + "remove_named_servers": False, }, "configurator": {"enabled": False}, },