Skip to content

Commit 42cdae0

Browse files
committed
update validation for argo task args and argo k8 keys
Signed-off-by: Sam Rooke <[email protected]>
1 parent 5394b27 commit 42cdae0

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/TaskManager/Plug-ins/Argo/StaticValues/ResourcesKeys.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ namespace Monai.Deploy.WorkflowManager.TaskManager.Argo.StaticValues
1818
{
1919
public static class ResourcesKeys
2020
{
21-
public static readonly ResourcesKey MemoryReservation = new() { TaskKey = "memory_reservation", ArgoKey = "requests.memory" };
22-
23-
public static readonly ResourcesKey CpuReservation = new() { TaskKey = "cpu_reservation", ArgoKey = "requests.cpu" };
24-
2521
public static readonly ResourcesKey GpuLimit = new() { TaskKey = "gpu_required", ArgoKey = "nvidia.com/gpu" };
2622

27-
public static readonly ResourcesKey MemoryLimit = new() { TaskKey = "memory_gb", ArgoKey = "limits.memory" };
23+
public static readonly ResourcesKey MemoryLimit = new() { TaskKey = "memory_gb", ArgoKey = "memory" };
2824

29-
public static readonly ResourcesKey CpuLimit = new() { TaskKey = "cpu", ArgoKey = "limits.cpu" };
25+
public static readonly ResourcesKey CpuLimit = new() { TaskKey = "cpu", ArgoKey = "cpu" };
3026
}
3127
}

src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ private void ValidateInputs(TaskObject currentTask)
350350

351351
private void ValidateArgoTask(TaskObject currentTask)
352352
{
353+
var validKeys = new string[] { WorkflowTemplateName, TaskPriorityClassName, Cpu, Memory, GpuRequired };
354+
if (currentTask.Args.Keys.Any(k => !validKeys.Contains(k)))
355+
{
356+
Errors.Add($"Task: '{currentTask.Id}' args has invalid keys. Please only specify keys from the following list: {string.Join(", ", validKeys)}.");
357+
return;
358+
}
359+
353360
if (!currentTask.Args.ContainsKey(WorkflowTemplateName))
354361
{
355362
Errors.Add($"Task: '{currentTask.Id}' workflow_template_name must be specified{Comma}this corresponds to an Argo template name.");

tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
208208
Type = "argo",
209209
Description = "Test Argo Task",
210210
Args = {
211-
{ "example", "value" },
212211
{ "cpu", "0.1" },
213212
{ "memory_gb", "0.1" },
214213
{ "gpu_required", "2" }
@@ -325,12 +324,30 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
325324
new TaskDestination
326325
{
327326
Name = "example-task"
327+
},
328+
new TaskDestination
329+
{
330+
Name = "invalid-key-argo-task"
328331
}
329332
}
330333
},
331334

332335
#endregion SelfReferencingTasks
333336

337+
new TaskObject
338+
{
339+
Id = "invalid-key-argo-task",
340+
Type = "argo",
341+
Description = "Invalid Key Argo Task",
342+
Args = {
343+
{ "invalid", "key" },
344+
{ "workflow_template_name" ,"spot"},
345+
{ "cpu", "1" },
346+
{ "memory_gb", "1" },
347+
{ "gpu_required", "1" }
348+
}
349+
},
350+
334351
// Unreferenced task
335352
new TaskObject {
336353
Id = "taskdesc3",
@@ -354,7 +371,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
354371

355372
Assert.True(errors.Count > 0);
356373

357-
Assert.Equal(44, errors.Count);
374+
Assert.Equal(46, errors.Count);
358375

359376
var convergingTasksDestinations = "Converging Tasks Destinations in tasks: (test-clinical-review-2, example-task) on task: example-task";
360377
Assert.Contains(convergingTasksDestinations, errors);
@@ -418,6 +435,9 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
418435

419436
var invalidSourceName = "Data origin invalid_origin does not exists. Please review sources configuration management.";
420437
Assert.Contains(invalidSourceName, errors);
438+
439+
var invalidArgoKey = $"Task: 'invalid-key-argo-task' args has invalid keys. Please only specify keys from the following list: workflow_template_name, priority, cpu, memory_gb, gpu_required.";
440+
Assert.Contains(invalidArgoKey, errors);
421441
}
422442

423443
[Fact]

0 commit comments

Comments
 (0)