Skip to content

Commit 9ab72b7

Browse files
authored
Merge branch 'develop' into AC-2010
2 parents 5fa35d4 + d7f993a commit 9ab72b7

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

src/TaskManager/Plug-ins/Argo/ArgoPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private void AddLimit(Template2 template, ResourcesKey key)
467467
value = bool.TryParse(value, out bool gpuRequired) && gpuRequired ? "1" : "0";
468468
}
469469

470-
template.Container.Resources.Limits.Add(key.ArgoKey, value);
470+
template.Container.Resources.Limits[key.ArgoKey] = value;
471471
}
472472

473473
private async Task AddMainWorkflowTemplate(Workflow workflow, CancellationToken cancellationToken)

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ private void ValidateArgoTask(TaskObject currentTask)
355355
Errors.Add($"Task: '{currentTask.Id}' workflow_template_name must be specified{Comma}this corresponds to an Argo template name.");
356356
}
357357

358+
var validKeys = new string[] { WorkflowTemplateName, TaskPriorityClassName, Cpu, Memory, GpuRequired };
359+
var invalidKeys = currentTask.Args.Keys.Where(k => !validKeys.Contains(k));
360+
if (invalidKeys.Count() > 0)
361+
{
362+
Errors.Add($"Task: '{currentTask.Id}' args has invalid keys: {string.Join(", ", invalidKeys)}. Please only specify keys from the following list: {string.Join(", ", validKeys)}.");
363+
return;
364+
}
365+
358366
if (currentTask.Args.ContainsKey(TaskPriorityClassName))
359367
{
360368
switch (currentTask.Args[TaskPriorityClassName].ToLower())

tests/UnitTests/TaskManager.Argo.Tests/ArgoPluginTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ private static void ValidateSimpleTemplate(TaskDispatchEvent message, Workflow w
371371
Assert.True(template.Container.Resources?.Limits is not null);
372372
var value = "";
373373

374-
Assert.True(template.Container.Resources?.Limits?.TryGetValue("limits.memory", out value));
374+
Assert.True(template.Container.Resources?.Limits?.TryGetValue("memory", out value));
375375
Assert.True(value == "1");
376-
Assert.True(template.Container.Resources?.Limits?.TryGetValue("limits.cpu", out value));
376+
Assert.True(template.Container.Resources?.Limits?.TryGetValue("cpu", out value));
377377
Assert.True(value == "1");
378378
Assert.True(template.Container.Resources?.Limits?.TryGetValue("nvidia.com/gpu", out value));
379379
Assert.True(value == "1");

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", "value" },
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: invalid_key. 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)