Skip to content

Commit 3d88f7a

Browse files
author
rafriat
committed
feat(ws): Notebooks 2.0 // Backend // add count to workspacekind schema response
Signed-off-by: rafriat <[email protected]>
1 parent 6490251 commit 3d88f7a

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

workspaces/backend/api/suite_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,5 +454,34 @@ func NewExampleWorkspaceKind(name string) *kubefloworgv1beta1.WorkspaceKind {
454454
},
455455
},
456456
},
457+
Status: kubefloworgv1beta1.WorkspaceKindStatus{
458+
Workspaces: 1,
459+
PodTemplateOptions: kubefloworgv1beta1.PodTemplateOptionsMetrics{
460+
ImageConfig: []kubefloworgv1beta1.OptionMetric{
461+
{
462+
Id: "jupyterlab_scipy_180",
463+
Workspaces: 1,
464+
},
465+
{
466+
Id: "jupyterlab_scipy_190",
467+
Workspaces: 0,
468+
},
469+
},
470+
PodConfig: []kubefloworgv1beta1.OptionMetric{
471+
{
472+
Id: "tiny_cpu",
473+
Workspaces: 1,
474+
},
475+
{
476+
Id: "small_cpu",
477+
Workspaces: 0,
478+
},
479+
{
480+
Id: "big_cpu",
481+
Workspaces: 0,
482+
},
483+
},
484+
},
485+
},
457486
}
458487
}

workspaces/backend/internal/models/workspacekinds/funcs.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewWorkspaceKindModelFromWorkspaceKind(wsk *kubefloworgv1beta1.WorkspaceKin
6060
Hidden: ptr.Deref(wsk.Spec.Spawner.Hidden, false),
6161
Icon: iconRef,
6262
Logo: logoRef,
63+
Workspaces: wsk.Status.Workspaces,
6364
PodTemplate: PodTemplate{
6465
PodMetadata: PodMetadata{
6566
Labels: podLabels,
@@ -71,18 +72,18 @@ func NewWorkspaceKindModelFromWorkspaceKind(wsk *kubefloworgv1beta1.WorkspaceKin
7172
Options: PodTemplateOptions{
7273
ImageConfig: ImageConfig{
7374
Default: wsk.Spec.PodTemplate.Options.ImageConfig.Spawner.Default,
74-
Values: buildImageConfigValues(wsk.Spec.PodTemplate.Options.ImageConfig),
75+
Values: buildImageConfigValues(wsk.Spec.PodTemplate.Options.ImageConfig, wsk.Status.PodTemplateOptions.ImageConfig),
7576
},
7677
PodConfig: PodConfig{
7778
Default: wsk.Spec.PodTemplate.Options.PodConfig.Spawner.Default,
78-
Values: buildPodConfigValues(wsk.Spec.PodTemplate.Options.PodConfig),
79+
Values: buildPodConfigValues(wsk.Spec.PodTemplate.Options.PodConfig, wsk.Status.PodTemplateOptions.PodConfig),
7980
},
8081
},
8182
},
8283
}
8384
}
8485

85-
func buildImageConfigValues(imageConfig kubefloworgv1beta1.ImageConfig) []ImageConfigValue {
86+
func buildImageConfigValues(imageConfig kubefloworgv1beta1.ImageConfig, statusImageConfig []kubefloworgv1beta1.OptionMetric) []ImageConfigValue {
8687
imageConfigValues := make([]ImageConfigValue, len(imageConfig.Values))
8788
for i := range imageConfig.Values {
8889
option := imageConfig.Values[i]
@@ -93,12 +94,13 @@ func buildImageConfigValues(imageConfig kubefloworgv1beta1.ImageConfig) []ImageC
9394
Labels: buildOptionLabels(option.Spawner.Labels),
9495
Hidden: ptr.Deref(option.Spawner.Hidden, false),
9596
Redirect: buildOptionRedirect(option.Redirect),
97+
Workspaces: FindConfigWorkspacesById(statusImageConfig, option.Id),
9698
}
9799
}
98100
return imageConfigValues
99101
}
100102

101-
func buildPodConfigValues(podConfig kubefloworgv1beta1.PodConfig) []PodConfigValue {
103+
func buildPodConfigValues(podConfig kubefloworgv1beta1.PodConfig, statusImageConfig []kubefloworgv1beta1.OptionMetric) []PodConfigValue {
102104
podConfigValues := make([]PodConfigValue, len(podConfig.Values))
103105
for i := range podConfig.Values {
104106
option := podConfig.Values[i]
@@ -109,6 +111,7 @@ func buildPodConfigValues(podConfig kubefloworgv1beta1.PodConfig) []PodConfigVal
109111
Labels: buildOptionLabels(option.Spawner.Labels),
110112
Hidden: ptr.Deref(option.Spawner.Hidden, false),
111113
Redirect: buildOptionRedirect(option.Redirect),
114+
Workspaces: FindConfigWorkspacesById(statusImageConfig, option.Id),
112115
}
113116
}
114117
return podConfigValues
@@ -153,3 +156,12 @@ func buildOptionRedirect(redirect *kubefloworgv1beta1.OptionRedirect) *OptionRed
153156
Message: message,
154157
}
155158
}
159+
160+
func FindConfigWorkspacesById(configs []kubefloworgv1beta1.OptionMetric, targetId string) int32 {
161+
for _, config := range configs {
162+
if config.Id == targetId {
163+
return config.Workspaces
164+
}
165+
}
166+
return -1
167+
}

workspaces/backend/internal/models/workspacekinds/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type WorkspaceKind struct {
2525
Hidden bool `json:"hidden"`
2626
Icon ImageRef `json:"icon"`
2727
Logo ImageRef `json:"logo"`
28+
Workspaces int32 `json:"workspacesCount"`
2829
PodTemplate PodTemplate `json:"podTemplate"`
2930
}
3031

@@ -64,6 +65,7 @@ type ImageConfigValue struct {
6465
Labels []OptionLabel `json:"labels"`
6566
Hidden bool `json:"hidden"`
6667
Redirect *OptionRedirect `json:"redirect,omitempty"`
68+
Workspaces int32 `json:"workspacesCount"`
6769
}
6870

6971
type PodConfig struct {
@@ -78,6 +80,7 @@ type PodConfigValue struct {
7880
Labels []OptionLabel `json:"labels"`
7981
Hidden bool `json:"hidden"`
8082
Redirect *OptionRedirect `json:"redirect,omitempty"`
83+
Workspaces int32 `json:"workspacesCount"`
8184
}
8285

8386
type OptionLabel struct {

workspaces/backend/openapi/docs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ const docTemplate = `{
740740
},
741741
"redirect": {
742742
"$ref": "#/definitions/workspacekinds.OptionRedirect"
743+
},
744+
"workspacesCount": {
745+
"type": "integer"
743746
}
744747
}
745748
},
@@ -810,6 +813,9 @@ const docTemplate = `{
810813
},
811814
"redirect": {
812815
"$ref": "#/definitions/workspacekinds.OptionRedirect"
816+
},
817+
"workspacesCount": {
818+
"type": "integer"
813819
}
814820
}
815821
},
@@ -916,6 +922,9 @@ const docTemplate = `{
916922
},
917923
"podTemplate": {
918924
"$ref": "#/definitions/workspacekinds.PodTemplate"
925+
},
926+
"workspacesCount": {
927+
"type": "integer"
919928
}
920929
}
921930
},

workspaces/backend/openapi/swagger.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@
738738
},
739739
"redirect": {
740740
"$ref": "#/definitions/workspacekinds.OptionRedirect"
741+
},
742+
"workspacesCount": {
743+
"type": "integer"
741744
}
742745
}
743746
},
@@ -808,6 +811,9 @@
808811
},
809812
"redirect": {
810813
"$ref": "#/definitions/workspacekinds.OptionRedirect"
814+
},
815+
"workspacesCount": {
816+
"type": "integer"
811817
}
812818
}
813819
},
@@ -914,6 +920,9 @@
914920
},
915921
"podTemplate": {
916922
"$ref": "#/definitions/workspacekinds.PodTemplate"
923+
},
924+
"workspacesCount": {
925+
"type": "integer"
917926
}
918927
}
919928
},

workspaces/backend/openapi/swagger.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ definitions:
140140
type: array
141141
redirect:
142142
$ref: '#/definitions/workspacekinds.OptionRedirect'
143+
workspacesCount:
144+
type: integer
143145
type: object
144146
workspacekinds.ImageRef:
145147
properties:
@@ -185,6 +187,8 @@ definitions:
185187
type: array
186188
redirect:
187189
$ref: '#/definitions/workspacekinds.OptionRedirect'
190+
workspacesCount:
191+
type: integer
188192
type: object
189193
workspacekinds.PodMetadata:
190194
properties:
@@ -255,6 +259,8 @@ definitions:
255259
type: string
256260
podTemplate:
257261
$ref: '#/definitions/workspacekinds.PodTemplate'
262+
workspacesCount:
263+
type: integer
258264
type: object
259265
workspaces.Activity:
260266
properties:

0 commit comments

Comments
 (0)