Skip to content

Commit 8660d3a

Browse files
committed
Add new option admin_environment
- This is environment which is intended to be passed only to the batch commands, not to the user servers. However, it is unknown if any spawners support this. Don't rely on it unless the spawner explicitely says it supports it.
1 parent 179dc03 commit 8660d3a

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Added (user)
99
* Add `req_prologue` and `req_epilogue` options to scripts which are inserted before/after the main jupyterhub-singleuser command, which allow for generic setup/cleanup without overriding the entire script. #96
1010
* SlurmSpawner: add the `req_reservation` option. #91
1111
* Add basic support for JupyterHub progress updates, but this is not used much yet. #86
12+
+* Add the option `admin_environment` which get passed to the batch submission commands (like for authentication) but *not* to the `--export
1213

1314
Added (developer)
1415

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ shell which will execute arbitrary user environment configuration
9898
access to their own cluster user account. This is something which we
9999
are working on.
100100

101+
The `admin_environment` option claims to pass environment only to the
102+
batch spawners, and not the user servers. This relies on each spawner
103+
handling environment correctly, and this is *not* checked so you
104+
should *not* rely on this yet.
101105

102106
## Provide different configurations of BatchSpawner
103107

SPAWNERS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ environment to be used, set `req_srun=''`. However, this is not
3434
perfect: there is still a bash shell begun as the user which could run
3535
arbitrary startup, define shell aliases for `srun`, etc.
3636

37+
`admin_environment` does work with SlurmSpawner.
38+
3739
Use of `srun` is required to gracefully terminate.
3840

3941

batchspawner/batchspawner.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ def cmd_formatted_for_batch(self):
213213
"""The command which is substituted inside of the batch script"""
214214
return ' '.join([self.batchspawner_singleuser_cmd] + self.cmd + self.get_args())
215215

216+
def get_admin_env(self):
217+
"""Get the environment passed to the batch submit/cancel/etc commands.
218+
219+
This contains all of the output from self.get_env(), plus any
220+
variables defined in self.admin_environment. In fact, only this
221+
command is used to pass to batch commands, and the only use of
222+
self.get_env() is producing the list of variables to be
223+
--export='ed to. Everything in get_env *must* also be in here
224+
or else it won't be used.
225+
"""
226+
env = self.get_env()
227+
if self.admin_environment:
228+
for key in self.admin_environment.split(','):
229+
if key in os.environ and key not in env:
230+
env[key] = os.environ[key]
231+
return env
232+
216233
async def run_command(self, cmd, input=None, env=None):
217234
proc = await asyncio.create_subprocess_shell(cmd, env=env,
218235
stdin=asyncio.subprocess.PIPE,

0 commit comments

Comments
 (0)