Skip to content

Commit 786f903

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 1238f67 commit 786f903

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

README.md

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

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

100104
## Provide different configurations of BatchSpawner
101105

@@ -162,6 +166,7 @@ Added (user)
162166
* Add new option exec_prefix, which defaults to `sudo -E -u {username}`. This replaces explicit `sudo` in every batch command - changes in local commands may be needed.
163167
* 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
164168
* SlurmSpawner: add the `req_reservation` option. #
169+
* Add the option `admin_environment` which get passed to the batch submission commands (like for authentication) but *not* to the `--export=keepvars` options. This *should* mean that it is not passed to the user, but not every spawner is checked, so this should *not* be relied on.
165170

166171
Added (developer)
167172

SPAWNERS.md

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

25+
`admin_environment` does work with SlurmSpawner.
26+
2527
Use of `srun` is required to gracefully terminate.
2628

2729

batchspawner/batchspawner.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ def parse_job_id(self, output):
205205
def cmd_formatted_for_batch(self):
206206
return ' '.join(self.cmd + self.get_args())
207207

208+
def get_admin_env(self):
209+
"""Get the environment passed to the batch submit/cancel/etc commands.
210+
211+
This contains all of the output from self.get_env(), plus any
212+
variables defined in self.admin_environment. In fact, only this
213+
command is used to pass to batch commands, and the only use of
214+
self.get_env() is producing the list of variables to be
215+
--export='ed to. Everything in get_env *must* also be in here
216+
or else it won't be used.
217+
"""
218+
env = self.get_env()
219+
if self.admin_environment:
220+
for key in self.admin_environment.split(','):
221+
if key in os.environ and key not in env:
222+
env[key] = os.environ[key]
223+
return env
224+
208225
@gen.coroutine
209226
def run_command(self, cmd, input=None, env=None):
210227
proc = Subprocess(cmd, shell=True, env=env, stdin=Subprocess.STREAM, stdout=Subprocess.STREAM,stderr=Subprocess.STREAM)

0 commit comments

Comments
 (0)