Skip to content

Commit 15e589e

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 3c8c8e0 commit 15e589e

File tree

6 files changed

+183
-9
lines changed

6 files changed

+183
-9
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,25 @@ func NewWorkspaceKindModelFromWorkspaceKind(wsk *kubefloworgv1beta1.WorkspaceKin
7979
},
8080
},
8181
},
82+
Status: WorkspaceKindStatus{
83+
Workspaces: wsk.Status.Workspaces,
84+
PodTemplateOptions: PodTemplateOptionsMetrics{
85+
ImageConfig: buildStatusConfig(wsk.Status.PodTemplateOptions.ImageConfig),
86+
PodConfig: buildStatusConfig(wsk.Status.PodTemplateOptions.PodConfig),
87+
},
88+
},
89+
}
90+
}
91+
92+
func buildStatusConfig(config []kubefloworgv1beta1.OptionMetric) []OptionMetric {
93+
newConfig := make([]OptionMetric, len(config))
94+
for i := range config {
95+
newConfig[i] = OptionMetric{
96+
Id: config[i].Id,
97+
Workspaces: config[i].Workspaces,
98+
}
8299
}
100+
return newConfig
83101
}
84102

85103
func buildImageConfigValues(imageConfig kubefloworgv1beta1.ImageConfig) []ImageConfigValue {

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,31 @@ limitations under the License.
1717
package workspacekinds
1818

1919
type WorkspaceKind struct {
20-
Name string `json:"name"`
21-
DisplayName string `json:"displayName"`
22-
Description string `json:"description"`
23-
Deprecated bool `json:"deprecated"`
24-
DeprecationMessage string `json:"deprecationMessage"`
25-
Hidden bool `json:"hidden"`
26-
Icon ImageRef `json:"icon"`
27-
Logo ImageRef `json:"logo"`
28-
PodTemplate PodTemplate `json:"podTemplate"`
20+
Name string `json:"name"`
21+
DisplayName string `json:"displayName"`
22+
Description string `json:"description"`
23+
Deprecated bool `json:"deprecated"`
24+
DeprecationMessage string `json:"deprecationMessage"`
25+
Hidden bool `json:"hidden"`
26+
Icon ImageRef `json:"icon"`
27+
Logo ImageRef `json:"logo"`
28+
PodTemplate PodTemplate `json:"podTemplate"`
29+
Status WorkspaceKindStatus `json:"status"`
30+
}
31+
32+
type WorkspaceKindStatus struct {
33+
Workspaces int32 `json:"workspaces"`
34+
PodTemplateOptions PodTemplateOptionsMetrics `json:"podTemplateOptions"`
35+
}
36+
37+
type PodTemplateOptionsMetrics struct {
38+
ImageConfig []OptionMetric `json:"imageConfig"`
39+
PodConfig []OptionMetric `json:"podConfig"`
40+
}
41+
42+
type OptionMetric struct {
43+
Id string `json:"id"`
44+
Workspaces int32 `json:"workspaces"`
2945
}
3046

3147
type ImageRef struct {

workspaces/backend/openapi/docs.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,17 @@ const docTemplate = `{
762762
}
763763
}
764764
},
765+
"workspacekinds.OptionMetric": {
766+
"type": "object",
767+
"properties": {
768+
"id": {
769+
"type": "string"
770+
},
771+
"workspaces": {
772+
"type": "integer"
773+
}
774+
}
775+
},
765776
"workspacekinds.OptionRedirect": {
766777
"type": "object",
767778
"properties": {
@@ -855,6 +866,23 @@ const docTemplate = `{
855866
}
856867
}
857868
},
869+
"workspacekinds.PodTemplateOptionsMetrics": {
870+
"type": "object",
871+
"properties": {
872+
"imageConfig": {
873+
"type": "array",
874+
"items": {
875+
"$ref": "#/definitions/workspacekinds.OptionMetric"
876+
}
877+
},
878+
"podConfig": {
879+
"type": "array",
880+
"items": {
881+
"$ref": "#/definitions/workspacekinds.OptionMetric"
882+
}
883+
}
884+
}
885+
},
858886
"workspacekinds.PodVolumeMounts": {
859887
"type": "object",
860888
"properties": {
@@ -916,6 +944,20 @@ const docTemplate = `{
916944
},
917945
"podTemplate": {
918946
"$ref": "#/definitions/workspacekinds.PodTemplate"
947+
},
948+
"status": {
949+
"$ref": "#/definitions/workspacekinds.WorkspaceKindStatus"
950+
}
951+
}
952+
},
953+
"workspacekinds.WorkspaceKindStatus": {
954+
"type": "object",
955+
"properties": {
956+
"podTemplateOptions": {
957+
"$ref": "#/definitions/workspacekinds.PodTemplateOptionsMetrics"
958+
},
959+
"workspaces": {
960+
"type": "integer"
919961
}
920962
}
921963
},

workspaces/backend/openapi/swagger.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,17 @@
760760
}
761761
}
762762
},
763+
"workspacekinds.OptionMetric": {
764+
"type": "object",
765+
"properties": {
766+
"id": {
767+
"type": "string"
768+
},
769+
"workspaces": {
770+
"type": "integer"
771+
}
772+
}
773+
},
763774
"workspacekinds.OptionRedirect": {
764775
"type": "object",
765776
"properties": {
@@ -853,6 +864,23 @@
853864
}
854865
}
855866
},
867+
"workspacekinds.PodTemplateOptionsMetrics": {
868+
"type": "object",
869+
"properties": {
870+
"imageConfig": {
871+
"type": "array",
872+
"items": {
873+
"$ref": "#/definitions/workspacekinds.OptionMetric"
874+
}
875+
},
876+
"podConfig": {
877+
"type": "array",
878+
"items": {
879+
"$ref": "#/definitions/workspacekinds.OptionMetric"
880+
}
881+
}
882+
}
883+
},
856884
"workspacekinds.PodVolumeMounts": {
857885
"type": "object",
858886
"properties": {
@@ -914,6 +942,20 @@
914942
},
915943
"podTemplate": {
916944
"$ref": "#/definitions/workspacekinds.PodTemplate"
945+
},
946+
"status": {
947+
"$ref": "#/definitions/workspacekinds.WorkspaceKindStatus"
948+
}
949+
}
950+
},
951+
"workspacekinds.WorkspaceKindStatus": {
952+
"type": "object",
953+
"properties": {
954+
"podTemplateOptions": {
955+
"$ref": "#/definitions/workspacekinds.PodTemplateOptionsMetrics"
956+
},
957+
"workspaces": {
958+
"type": "integer"
917959
}
918960
}
919961
},

workspaces/backend/openapi/swagger.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ definitions:
153153
value:
154154
type: string
155155
type: object
156+
workspacekinds.OptionMetric:
157+
properties:
158+
id:
159+
type: string
160+
workspaces:
161+
type: integer
162+
type: object
156163
workspacekinds.OptionRedirect:
157164
properties:
158165
message:
@@ -213,6 +220,17 @@ definitions:
213220
podConfig:
214221
$ref: '#/definitions/workspacekinds.PodConfig'
215222
type: object
223+
workspacekinds.PodTemplateOptionsMetrics:
224+
properties:
225+
imageConfig:
226+
items:
227+
$ref: '#/definitions/workspacekinds.OptionMetric'
228+
type: array
229+
podConfig:
230+
items:
231+
$ref: '#/definitions/workspacekinds.OptionMetric'
232+
type: array
233+
type: object
216234
workspacekinds.PodVolumeMounts:
217235
properties:
218236
home:
@@ -255,6 +273,15 @@ definitions:
255273
type: string
256274
podTemplate:
257275
$ref: '#/definitions/workspacekinds.PodTemplate'
276+
status:
277+
$ref: '#/definitions/workspacekinds.WorkspaceKindStatus'
278+
type: object
279+
workspacekinds.WorkspaceKindStatus:
280+
properties:
281+
podTemplateOptions:
282+
$ref: '#/definitions/workspacekinds.PodTemplateOptionsMetrics'
283+
workspaces:
284+
type: integer
258285
type: object
259286
workspaces.Activity:
260287
properties:

0 commit comments

Comments
 (0)