Skip to content

Commit b384fc9

Browse files
mathis-marcotteMathis Marcotte
and
Mathis Marcotte
authored
added fix to enumerate duplicate names in default notebook creation (#323)
* added fix to enumerate duplicate names in default notebook creation * updated cypress version to fix firefox issue --------- Co-authored-by: Mathis Marcotte <[email protected]>
1 parent 80d418d commit b384fc9

File tree

5 files changed

+90
-48
lines changed

5 files changed

+90
-48
lines changed

frontend/jupyter/package-lock.json

+17-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/jupyter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@types/node": "^18.19.18",
7171
"@typescript-eslint/eslint-plugin": "^6.10.0",
7272
"@typescript-eslint/parser": "^6.10.0",
73-
"cypress": "^13.2.0",
73+
"cypress": "^13.8.1",
7474
"eslint": "^8.53.0",
7575
"eslint-plugin-import": "latest",
7676
"eslint-plugin-jsdoc": "^39.9.1",

frontend/jupyter/yarn.lock

+18-13
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,7 @@
27902790
dependencies:
27912791
"@types/node" "*"
27922792

2793-
"@types/node@*", "@types/node@^18.0.0 || >=20.0.0", "@types/node@^18.17.5", "@types/node@^18.19.18", "@types/node@>=10.0.0":
2793+
"@types/node@*", "@types/node@^18.0.0 || >=20.0.0", "@types/node@^18.19.18", "@types/node@>=10.0.0":
27942794
version "18.19.18"
27952795
resolved "https://registry.npmjs.org/@types/node/-/node-18.19.18.tgz"
27962796
integrity sha512-80CP7B8y4PzZF0GWx15/gVWRrB5y/bIjNI84NK3cmQJu0WZwvmj2WMA5LcofQFVfLqqCSp545+U2LsrVzX36Zg==
@@ -3737,7 +3737,7 @@ buffer-from@^1.0.0:
37373737
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
37383738
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
37393739

3740-
buffer@^5.5.0, buffer@^5.6.0:
3740+
buffer@^5.5.0, buffer@^5.7.1:
37413741
version "5.7.1"
37423742
resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz"
37433743
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
@@ -3828,9 +3828,9 @@ camelcase@^5.3.1:
38283828
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
38293829

38303830
caniuse-lite@^1.0.30001578, caniuse-lite@^1.0.30001587:
3831-
version "1.0.30001589"
3832-
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001589.tgz"
3833-
integrity sha512-vNQWS6kI+q6sBlHbh71IIeC+sRwK2N3EDySc/updIGhIee2x5z00J4c1242/5/d6EpEMdOnk/m+6tuk4/tcsqg==
3831+
version "1.0.30001615"
3832+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001615.tgz"
3833+
integrity sha512-1IpazM5G3r38meiae0bHRnPhz+CBQ3ZLqbQMtrg+AsTPKAXgW38JNsXkyZ+v8waCsDmPq87lmfun5Q2AGysNEQ==
38343834

38353835
caseless@~0.12.0:
38363836
version "0.12.0"
@@ -4257,20 +4257,19 @@ custom-event@~1.0.0:
42574257
resolved "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz"
42584258
integrity sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==
42594259

4260-
cypress@^13.2.0:
4261-
version "13.2.0"
4262-
resolved "https://registry.npmjs.org/cypress/-/cypress-13.2.0.tgz"
4263-
integrity sha512-AvDQxBydE771GTq0TR4ZUBvv9m9ffXuB/ueEtpDF/6gOcvFR96amgwSJP16Yhqw6VhmwqspT5nAGzoxxB+D89g==
4260+
cypress@^13.8.1:
4261+
version "13.8.1"
4262+
resolved "https://registry.npmjs.org/cypress/-/cypress-13.8.1.tgz"
4263+
integrity sha512-Uk6ovhRbTg6FmXjeZW/TkbRM07KPtvM5gah1BIMp4Y2s+i/NMxgaLw0+PbYTOdw1+egE0FP3mWRiGcRkjjmhzA==
42644264
dependencies:
42654265
"@cypress/request" "^3.0.0"
42664266
"@cypress/xvfb" "^1.2.4"
4267-
"@types/node" "^18.17.5"
42684267
"@types/sinonjs__fake-timers" "8.1.1"
42694268
"@types/sizzle" "^2.3.2"
42704269
arch "^2.2.0"
42714270
blob-util "^2.0.2"
42724271
bluebird "^3.7.2"
4273-
buffer "^5.6.0"
4272+
buffer "^5.7.1"
42744273
cachedir "^2.3.0"
42754274
chalk "^4.1.0"
42764275
check-more-types "^2.24.0"
@@ -4288,7 +4287,7 @@ cypress@^13.2.0:
42884287
figures "^3.2.0"
42894288
fs-extra "^9.1.0"
42904289
getos "^3.2.1"
4291-
is-ci "^3.0.0"
4290+
is-ci "^3.0.1"
42924291
is-installed-globally "~0.4.0"
42934292
lazy-ass "^1.6.0"
42944293
listr2 "^3.8.3"
@@ -6054,7 +6053,7 @@ is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.7:
60546053
resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz"
60556054
integrity sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==
60566055

6057-
is-ci@^3.0.0:
6056+
is-ci@^3.0.1:
60586057
version "3.0.1"
60596058
resolved "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz"
60606059
integrity sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==
@@ -6630,6 +6629,12 @@ klona@^2.0.4:
66306629
resolved "https://registry.npmjs.org/klona/-/klona-2.0.6.tgz"
66316630
integrity sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==
66326631

6632+
"kubeflow@file:../common/kubeflow-common-lib/dist/kubeflow":
6633+
version "0.0.4"
6634+
resolved "file:../common/kubeflow-common-lib/dist/kubeflow"
6635+
dependencies:
6636+
tslib "^2.0.0"
6637+
66336638
launch-editor@^2.6.0:
66346639
version "2.6.1"
66356640
resolved "https://registry.npmjs.org/launch-editor/-/launch-editor-2.6.1.tgz"

notebooks.go

+47-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111
"net/http"
1212
"regexp"
1313
"sort"
14+
"strconv"
1415
"strings"
1516
"time"
1617

1718
kubeflowv1 "github.com/StatCan/kubeflow-apis/apis/kubeflow/v1"
1819
"github.com/gorilla/mux"
20+
"golang.org/x/exp/slices"
1921
"gopkg.in/inf.v0"
2022
corev1 "k8s.io/api/core/v1"
2123
"k8s.io/apimachinery/pkg/api/resource"
@@ -479,10 +481,27 @@ func (s *server) handleVolume(ctx context.Context, req volrequest, notebook *kub
479481
return nil
480482
}
481483

484+
func (s *server) enumerateNames(name string, nameList []string) string {
485+
if !slices.Contains(nameList, name) {
486+
return name
487+
}
488+
489+
count := 1
490+
for slices.Contains(nameList, name+"-"+strconv.Itoa(count)) {
491+
count++
492+
}
493+
494+
return name + "-" + strconv.Itoa(count)
495+
}
496+
482497
// Sets default values to notebook request if missing
483-
func (s *server) createDefaultNotebook(namespace string) (newnotebookrequest, error) {
498+
func (s *server) createDefaultNotebook(namespace string, notebookNames []string, pvcNames []string) (newnotebookrequest, error) {
484499
var notebook newnotebookrequest
485500
notebookname := namespace + "-notebook"
501+
502+
// updates the notebook name with a trailing number to avoid duplicate values
503+
notebookname = s.enumerateNames(notebookname, notebookNames)
504+
486505
cpuvalue, err := resource.ParseQuantity(s.Config.SpawnerFormDefaults.CPU.Value)
487506
if err != nil {
488507
return notebook, err
@@ -508,6 +527,10 @@ func (s *server) createDefaultNotebook(namespace string) (newnotebookrequest, er
508527
return notebook, err
509528
}
510529
workspacevolumename := notebookname + "-workspace"
530+
531+
// updates the volume name with a trailing number to avoid duplicate values
532+
workspacevolumename = s.enumerateNames(workspacevolumename, pvcNames)
533+
511534
workspaceVol := volrequest{
512535
Mount: s.Config.SpawnerFormDefaults.WorkspaceVolume.Value.Mount,
513536
NewPvc: NewPvc{
@@ -586,7 +609,29 @@ func (s *server) NewDefaultNotebook(w http.ResponseWriter, r *http.Request) {
586609
vars := mux.Vars(r)
587610
namespace := vars["namespace"]
588611

589-
req, err := s.createDefaultNotebook(namespace)
612+
notebooks, err := s.listers.notebooks.Notebooks(namespace).List(labels.Everything())
613+
if err != nil {
614+
s.error(w, r, err)
615+
return
616+
}
617+
618+
var notebookNames []string
619+
for _, notebook := range notebooks {
620+
notebookNames = append(notebookNames, notebook.Name)
621+
}
622+
623+
pvcs, err := s.listers.persistentVolumeClaims.PersistentVolumeClaims(namespace).List(labels.Everything())
624+
if err != nil {
625+
s.error(w, r, err)
626+
return
627+
}
628+
629+
var pvcNames []string
630+
for _, pvc := range pvcs {
631+
pvcNames = append(pvcNames, pvc.Name)
632+
}
633+
634+
req, err := s.createDefaultNotebook(namespace, notebookNames, pvcNames)
590635
if err != nil {
591636
s.error(w, r, err)
592637
return

samples/spawner_ui_config.yaml

+7-13
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,21 @@
1717
spawnerFormDefaults:
1818
image:
1919
# The container Image for the user's Jupyter Notebook
20-
value: k8scc01covidacr.azurecr.io/jupyterlab-cpu:v1
20+
value: artifactory.cloud.statcan.ca/das-aaw-docker/jupyterlab-cpu:v2
2121
# The list of available standard container Images
2222
options:
23-
- k8scc01covidacr.azurecr.io/jupyterlab-cpu:v1
24-
- k8scc01covidacr.azurecr.io/jupyterlab-pytorch:v1
25-
- k8scc01covidacr.azurecr.io/jupyterlab-tensorflow:v1
23+
- artifactory.cloud.statcan.ca/das-aaw-docker/jupyterlab-cpu:v2
24+
- artifactory.cloud.statcan.ca/das-aaw-docker/jupyterlab-pytorch:v2
25+
- artifactory.cloud.statcan.ca/das-aaw-docker/jupyterlab-tensorflow:v2
2626
readOnly: false
2727
imageGroupThree:
2828
# The container Image for the user's Group Three Server (SAS)
2929
# The annotation `notebooks.kubeflow.org/http-rewrite-uri: /`
3030
# is applied to notebook in this group, configuring
3131
# the Istio rewrite for containers that host their web UI at `/`
32-
enabledCondition:
33-
labels:
34-
state.aaw.statcan.gc.ca/exists-non-sas-notebook-user: false
35-
disabledMessage:
36-
en: "SAS is unavailable while non-employees have access to this profile."
37-
fr: "SAS n'est pas disponible lorsque des non-employés ont accès à ce profil."
38-
value: k8scc01covidacr.azurecr.io/sas:latest # The list of available standard container Images
32+
value: artifactory.cloud.statcan.ca/das-aaw-docker/sas:v2 # The list of available standard container Images
3933
options:
40-
- k8scc01covidacr.azurecr.io/sas:latest
34+
- artifactory.cloud.statcan.ca/das-aaw-docker/sas:v2
4135
hideRegistry: true
4236
hideTag: true
4337
allowCustomImage: true
@@ -172,7 +166,7 @@ spawnerFormDefaults:
172166
readOnly: false
173167
tolerationGroup:
174168
# The default `groupKey` from the options list
175-
# If readonly, the default value will be the only option
169+
# If readonly, the default value will be the only option
176170
value: "none"
177171
# The list of available tolerationGroup configs
178172
options: []

0 commit comments

Comments
 (0)