Skip to content

Commit 24d5144

Browse files
committed
feat: add capabiilty support to create Workbench and Job commands (WORKBENCH-4534)
Signed-off-by: m-d-key <m-d-key@users.noreply.github.com>
1 parent 9db2e43 commit 24d5144

12 files changed

Lines changed: 476 additions & 102 deletions

File tree

‎doc/wbctl create job.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Aliases:
99

1010
Flags:
1111
-a, --application string The application to run in the job. Not required if at least one service is specified.
12+
--capability strings The capability to include in the job.
1213
-c, --command string The command to run in the job.
1314
--context string The context (volume, snapshot, or s3 bucket) for the job.
1415
--dataplane string The ID of the dataplane where the job will be created. If only one dataplane is available, this flag can be omitted.

‎doc/wbctl create workbench.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Aliases:
99

1010
Flags:
1111
-a, --application string The application to run in the workbench. Not required if at least one service is specified.
12+
--capability strings The capability to include in the workbench.
1213
--dataplane string The ID of the dataplane where the workbench will be created. If only one dataplane is available, this flag can be omitted.
1314
--desired-state string The desired state of the workbench (e.g., RUNNING, STOPPED).
1415
-d, --dry-run Only print the object that would be sent, without sending it.

‎internal/cmd/create/job/job.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func CreateCommand(
6060
flags.AddApplicationFlag(cmd, constants.JobType)
6161
flags.AddServiceFlag(cmd, constants.JobType)
6262
flags.AddEnvironmentFlag(cmd, constants.JobType)
63+
flags.AddCapabilityFlag(cmd, constants.JobType)
6364
return cmd
6465
}
6566

@@ -210,7 +211,7 @@ func getJobRequestBody(
210211
}
211212
services := v.GetStringSlice(constants.ServiceFlag)
212213
envs := v.GetStringSlice(constants.EnvironmentFlag)
213-
214+
capabilities := v.GetStringSlice(constants.CapabilityFlag)
214215
workspaceRequests, err := workbench.GetValidWorkspaceRequests(ctx, svc, volumes)
215216
if err != nil {
216217
return types.Job{}, err
@@ -247,6 +248,16 @@ func getJobRequestBody(
247248
"folderName": workspaceRequests[0].MountName,
248249
}
249250
}
251+
if len(capabilities) > 0 {
252+
job.Mounts = make([]types.MountRequest, 0, len(capabilities))
253+
for _, capability := range capabilities {
254+
job.Mounts = append(job.Mounts, types.MountRequest{
255+
Capability: &types.CapabilityRequest{
256+
ID: capability,
257+
},
258+
})
259+
}
260+
}
250261
job.Properties = properties
251262
return job, nil
252263
}

‎internal/cmd/create/job/job_test.go‎

Lines changed: 118 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,70 @@ const (
203203
}
204204
}
205205
}
206+
`
207+
expectedCreateJobRequestBodyWithCapabilities = `
208+
{
209+
"param": {
210+
"dataplane_id": "123e4567-e89b-12d3-a456-426614174000",
211+
"description": "job desc",
212+
"name": "job-2",
213+
"nodepool": "np-2",
214+
"services": [
215+
{
216+
"id": "service-1",
217+
"env": {
218+
"DEFAULT_MOUNTNAME": "data"
219+
}
220+
},
221+
{
222+
"id": "service-2",
223+
"env": {
224+
"DEFAULT_MOUNTNAME": "data"
225+
}
226+
}
227+
],
228+
"spec": {
229+
"tasks": {
230+
"default": {
231+
"cmds": [
232+
"run.sh"
233+
]
234+
}
235+
},
236+
"version": "3"
237+
},
238+
"workspaces": [
239+
{
240+
"id": "ctrl-home",
241+
"mountName": "sas"
242+
},
243+
{
244+
"id": "ctrl-data",
245+
"mountName": "data"
246+
}
247+
],
248+
"mounts": [
249+
{
250+
"capability": {
251+
"id": "capability1"
252+
}
253+
},
254+
{
255+
"capability": {
256+
"id": "capability2"
257+
}
258+
}
259+
],
260+
"properties": {
261+
"isWorkbenchAppCreated": true,
262+
"primaryVolume": {
263+
"controller_id": "ctrl-home",
264+
"folderName": "sas",
265+
"id": "ws-home"
266+
}
267+
}
268+
}
269+
}
206270
`
207271
expectedUpdateJobDryRunOutput = `{
208272
"ids": [
@@ -405,20 +469,21 @@ const (
405469
)
406470

407471
type createInput struct {
408-
endpoint string
409-
filename string
410-
fileContent string
411-
dryRun bool
412-
dataplane string
413-
name string
414-
description string
415-
context string
416-
command string
417-
application string
418-
services []string
419-
nodepool string
420-
subPath string
421-
workspaces []string
472+
endpoint string
473+
filename string
474+
fileContent string
475+
dryRun bool
476+
dataplane string
477+
name string
478+
description string
479+
context string
480+
command string
481+
application string
482+
services []string
483+
nodepool string
484+
subPath string
485+
workspaces []string
486+
capabilities []string
422487
}
423488

424489
type createExpected struct {
@@ -598,6 +663,42 @@ func TestCreateJobCommand(t *testing.T) {
598663
workspacesCalls: 2,
599664
},
600665
},
666+
{
667+
name: "create success with capabilities",
668+
input: createInput{
669+
dataplane: "123e4567-e89b-12d3-a456-426614174000",
670+
name: "job-2",
671+
description: "job desc",
672+
command: "run.sh",
673+
services: []string{"service-1", "service-2"},
674+
nodepool: "np-2",
675+
workspaces: []string{"ws-home", "ws-data"},
676+
capabilities: []string{"capability1", "capability2"},
677+
},
678+
mockEndpoints: getCreateJobEndpoints(jobEndpointsConfig{
679+
dataplaneConfig: stubs.StubHTTPPartialGetConfig{
680+
ExpectedQuery: expectedDataplaneQuery,
681+
ResponseBody: `[{"id":"123e4567-e89b-12d3-a456-426614174000"}]`,
682+
ResponseStatus: http.StatusOK,
683+
},
684+
servicesConfig: stubs.StubHTTPPartialGetConfig{
685+
ResponseBody: expectedServicesResponseBody,
686+
ResponseStatus: http.StatusOK,
687+
},
688+
jobConfig: stubs.StubHTTPPartialPostConfig{
689+
ExpectedRequestBody: expectedCreateJobRequestBodyWithCapabilities,
690+
ResponseBody: `{"id":"job-1"}`,
691+
ResponseStatus: http.StatusOK,
692+
},
693+
}),
694+
expected: createExpected{
695+
displays: []string{stubs.ExpectedDeviceAuthDisplay, expectedCreateJobID},
696+
createCalls: 1,
697+
dataplanesCalls: 1,
698+
servicesCalls: 1,
699+
workspacesCalls: 2,
700+
},
701+
},
601702
{
602703
name: "create error",
603704
input: createInput{
@@ -1303,6 +1404,9 @@ func getCreateArgs(
13031404
for _, workspaceID := range tt.input.workspaces {
13041405
args = append(args, "--"+constants.WorkspaceFlag, workspaceID)
13051406
}
1407+
for _, capabilityID := range tt.input.capabilities {
1408+
args = append(args, "--"+constants.CapabilityFlag, capabilityID)
1409+
}
13061410
return args
13071411
}
13081412

‎internal/cmd/create/workbench/workbench.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func CreateCommand(
5555
flags.AddApplicationFlag(cmd, constants.WorkbenchType)
5656
flags.AddServiceFlag(cmd, constants.WorkbenchType)
5757
flags.AddDesiredStateFlag(cmd, constants.WorkbenchType)
58+
flags.AddCapabilityFlag(cmd, constants.WorkbenchType)
5859
return cmd
5960
}
6061

@@ -193,6 +194,7 @@ func getWorkbenchRequestBody(
193194
volumes = v.GetStringSlice(constants.WorkspaceFlag)
194195
}
195196
services := v.GetStringSlice(constants.ServiceFlag)
197+
capabilities := v.GetStringSlice(constants.CapabilityFlag)
196198

197199
serviceRequests, err := workbench.GetServiceRequests(ctx, svc, application, services)
198200
if err != nil {
@@ -212,6 +214,16 @@ func getWorkbenchRequestBody(
212214
ApplicationID: application,
213215
}
214216
setWorkspaceRequests(&wkbnch, workspaceRequests)
217+
if len(capabilities) > 0 {
218+
wkbnch.Mounts = make([]types.MountRequest, 0, len(capabilities))
219+
for _, capability := range capabilities {
220+
wkbnch.Mounts = append(wkbnch.Mounts, types.MountRequest{
221+
Capability: &types.CapabilityRequest{
222+
ID: capability,
223+
},
224+
})
225+
}
226+
}
215227
return wkbnch, nil
216228
}
217229

0 commit comments

Comments
 (0)