Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Csusb-hub-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
csusb-prp
Csusb-hub-dev
Commits
8421d325
Commit
8421d325
authored
10 months ago
by
Dung Vu
Browse files
Options
Downloads
Patches
Plain Diff
Update my_spawner.py
parent
a4dc8b74
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#46859
passed
10 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extraFiles/my_spawner.py
+53
-16
53 additions, 16 deletions
extraFiles/my_spawner.py
with
53 additions
and
16 deletions
extraFiles/my_spawner.py
+
53
−
16
View file @
8421d325
...
...
@@ -14,20 +14,56 @@ class MySpawner(KubeSpawner):
if
not
self
.
profile_list
or
not
hasattr
(
self
,
'
_profile_list
'
):
return
formdata
selected_profile
=
int
(
formdata
.
get
(
'
profile
'
,
[
0
])[
0
])
options
=
self
.
_profile_list
[
selected_profile
]
self
.
log
.
debug
(
"
Applying KubeSpawner override for profile
'
%s
'"
,
options
[
'
display_name
'
])
kubespawner_override
=
options
.
get
(
'
kubespawner_override
'
,
{})
for
k
,
v
in
kubespawner_override
.
items
():
if
callable
(
v
):
v
=
v
(
self
)
self
.
log
.
debug
(
"
.. overriding KubeSpawner value %s=%s (callable result)
"
,
k
,
v
)
else
:
self
.
log
.
debug
(
"
.. overriding KubeSpawner value %s=%s
"
,
k
,
v
)
setattr
(
self
,
k
,
v
)
gpus
=
int
(
formdata
.
get
(
'
gpus
'
,
[
0
])[
0
])
#https://github.com/jupyterhub/kubespawner/blob/main/kubespawner/spawner.py#L3046
profile_slug
=
formdata
.
get
(
'
profile
'
,
[
None
])[
0
]
# initialize a dictionary to return
user_options
=
{}
# if a profile is declared, add a dictionary key for the profile, and
# dictionary keys for the formdata related to the profile's
# profile_options, as recognized by being named like:
#
# profile-option-{profile_slug}--{profile_option_slug}
#
if
profile_slug
:
user_options
[
"
profile
"
]
=
profile_slug
prefix
=
f
'
profile-option-
{
profile_slug
}
--
'
for
k
,
v
in
formdata
.
items
():
if
k
.
startswith
(
prefix
):
profile_option_slug
=
k
[
len
(
prefix
)
:]
user_options
[
profile_option_slug
]
=
v
[
0
]
gpus
=
int
(
formdata
.
get
(
'
gpus
'
,
[
0
])[
0
])
for
k
,
v
in
kubespawner_override
.
items
():
if
callable
(
v
):
v
=
v
(
self
)
self
.
log
.
info
(
"
.. overriding KubeSpawner value %s=%s (callable result)
"
,
k
,
v
)
else
:
self
.
log
.
info
(
"
.. overriding KubeSpawner value %s=%s
"
,
k
,
v
)
if
k
!=
"
image
"
:
setattr
(
self
,
k
,
v
)
else
:
image
=
v
if
isinstance
(
v
,
dict
):
if
gpus
>
0
:
image
=
v
[
"
cuda
"
]
else
:
image
=
v
[
"
cpu
"
]
if
not
(
"
:
"
in
image
):
self
.
log
.
info
(
"
.. adding tag %s to image %s
"
,
formdata
.
get
(
'
tag
'
,
[
0
])[
0
],
image
)
image
+=
"
:
"
+
formdata
.
get
(
'
tag
'
,
[
0
])[
0
]
setattr
(
self
,
k
,
image
)
setattr
(
self
,
"
tag
"
,
formdata
.
get
(
'
tag
'
,
[
0
])[
0
])
setattr
(
self
,
"
extra_resource_limits
"
,
{
"
nvidia.com/gpu
"
:
gpus
})
setattr
(
self
,
"
mem_guarantee
"
,
formdata
.
get
(
'
ram
'
,
[
0
])[
0
]
+
"
G
"
)
setattr
(
self
,
"
cpu_guarantee
"
,
float
(
formdata
.
get
(
'
cores
'
,
[
0
])[
0
]))
...
...
@@ -133,8 +169,9 @@ class MySpawner(KubeSpawner):
setattr
(
self
,
'
startTimeout
'
,
1200
)
return
options
self
.
log
.
info
(
options
)
return
user_options
profile_list
=
[
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment