@@ -60,6 +60,14 @@ public class ArgoPluginTest
6060 private Workflow ? _submittedArgoTemplate ;
6161 private readonly int _argoTtlStatergySeconds = 360 ;
6262 private readonly int _minAgoTtlStatergySeconds = 30 ;
63+ private readonly string _initContainerCpuLimit = "100m" ;
64+ private readonly string _initContainerMemoryLimit = "200Mi" ;
65+ private readonly string _waitContainerCpuLimit = "200m" ;
66+ private readonly string _waitContainerMemoryLimit = "300Mi" ;
67+ private readonly string _messageGeneratorContainerCpuLimit = "300m" ;
68+ private readonly string _messageGeneratorContainerMemoryLimit = "400Mi" ;
69+ private readonly string _messageSenderContainerCpuLimit = "400m" ;
70+ private readonly string _messageSenderContainerMemoryLimit = "500Mi" ;
6371
6472 public ArgoPluginTest ( )
6573 {
@@ -80,8 +88,16 @@ public ArgoPluginTest()
8088 _options . Value . Messaging . PublisherSettings . Add ( "exchange" , "exchange" ) ;
8189 _options . Value . Messaging . PublisherSettings . Add ( "virtualHost" , "vhost" ) ;
8290 _options . Value . Messaging . Topics . TaskCallbackRequest = "md.tasks.callback" ;
83- _options . Value . ArgoTtlStatergySeconds = _argoTtlStatergySeconds ;
84- _options . Value . MinArgoTtlStatergySeconds = _minAgoTtlStatergySeconds ;
91+ _options . Value . ArgoTtlStrategySeconds = _argoTtlStatergySeconds ;
92+ _options . Value . MinArgoTtlStrategySeconds = _minAgoTtlStatergySeconds ;
93+ _options . Value . TaskManager . ArgoPluginArguments . InitContainerCpuLimit = _initContainerCpuLimit ;
94+ _options . Value . TaskManager . ArgoPluginArguments . InitContainerMemoryLimit = _initContainerMemoryLimit ;
95+ _options . Value . TaskManager . ArgoPluginArguments . WaitContainerCpuLimit = _waitContainerCpuLimit ;
96+ _options . Value . TaskManager . ArgoPluginArguments . WaitContainerMemoryLimit = _waitContainerMemoryLimit ;
97+ _options . Value . TaskManager . ArgoPluginArguments . MessageGeneratorContainerCpuLimit = _messageGeneratorContainerCpuLimit ;
98+ _options . Value . TaskManager . ArgoPluginArguments . MessageGeneratorContainerMemoryLimit = _messageGeneratorContainerMemoryLimit ;
99+ _options . Value . TaskManager . ArgoPluginArguments . MessageSenderContainerCpuLimit = _messageSenderContainerCpuLimit ;
100+ _options . Value . TaskManager . ArgoPluginArguments . MessageSenderContainerMemoryLimit = _messageSenderContainerMemoryLimit ;
85101
86102 _serviceScopeFactory . Setup ( p => p . CreateScope ( ) ) . Returns ( _serviceScope . Object ) ;
87103
@@ -630,8 +646,8 @@ public async Task ArgoPlugin_Copies_ImagePullSecrets()
630646 Assert . Equal ( secret , _submittedArgoTemplate ? . Spec . ImagePullSecrets . First ( ) ) ;
631647 }
632648
633- [ Fact ( DisplayName = "TTL gets added if not pressent " ) ]
634- public async Task ArgoPlugin_Ensures_TTL_Added_If_Not_pressent ( )
649+ [ Fact ( DisplayName = "TTL gets added if not present " ) ]
650+ public async Task ArgoPlugin_Ensures_TTL_Added_If_Not_present ( )
635651 {
636652 var argoTemplate = LoadArgoTemplate ( "SimpleTemplate.yml" ) ;
637653 Assert . NotNull ( argoTemplate ) ;
@@ -647,6 +663,34 @@ public async Task ArgoPlugin_Ensures_TTL_Added_If_Not_pressent()
647663 Assert . Equal ( _argoTtlStatergySeconds , _submittedArgoTemplate ? . Spec . TtlStrategy ? . SecondsAfterCompletion ) ;
648664 }
649665
666+ [ Fact ( DisplayName = "Argo Plugin adds required resource limits" ) ]
667+ public async Task ArgoPlugin_Adds_Container_Resource_Restrictions_Based_On_Configured_Values ( )
668+ {
669+ var argoTemplate = LoadArgoTemplate ( "SimpleTemplate.yml" ) ;
670+ Assert . NotNull ( argoTemplate ) ;
671+
672+ SetUpSimpleArgoWorkFlow ( argoTemplate ) ;
673+
674+ var message = GenerateTaskDispatchEventWithValidArguments ( ) ;
675+
676+ var expectedPodSpecPatch = "{\" initContainers\" :[{\" name\" :\" init\" ,\" resources\" :{\" limits\" :{\" cpu\" :\" " + _initContainerCpuLimit + "\" ,\" memory\" : \" " +
677+ _initContainerMemoryLimit +
678+ "\" },\" requests\" :{\" cpu\" :\" 0\" ,\" memory\" :\" 0Mi\" }}}],\" containers\" :[{\" name\" :\" wait\" ,\" resources\" :{\" limits\" :{\" cpu\" :\" " +
679+ _waitContainerCpuLimit + "\" ,\" memory\" :\" " + _waitContainerMemoryLimit +
680+ "\" },\" requests\" :{\" cpu\" :\" 0\" ,\" memory\" :\" 0Mi\" }}}]}" ;
681+
682+ var runner = new ArgoPlugin ( _serviceScopeFactory . Object , _logger . Object , _options , message ) ;
683+ var result = await runner . ExecuteTask ( CancellationToken . None ) . ConfigureAwait ( false ) ;
684+
685+ Assert . Equal ( TaskExecutionStatus . Accepted , result . Status ) ;
686+ Assert . Equal ( _messageGeneratorContainerCpuLimit , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateGenerateTemplateName ) . Container . Resources . Limits [ "cpu" ] ) ;
687+ Assert . Equal ( _messageGeneratorContainerMemoryLimit , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateGenerateTemplateName ) . Container . Resources . Limits [ "memory" ] ) ;
688+ Assert . Equal ( expectedPodSpecPatch , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateGenerateTemplateName ) . PodSpecPatch ) ;
689+ Assert . Equal ( _messageSenderContainerCpuLimit , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateSendTemplateName ) . Container . Resources . Limits [ "cpu" ] ) ;
690+ Assert . Equal ( _messageSenderContainerMemoryLimit , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateSendTemplateName ) . Container . Resources . Limits [ "memory" ] ) ;
691+ Assert . Equal ( expectedPodSpecPatch , _submittedArgoTemplate ? . Spec . Templates . FirstOrDefault ( p => p . Name == Strings . ExitHookTemplateSendTemplateName ) . PodSpecPatch ) ;
692+ }
693+
650694 [ Theory ( DisplayName = "TTL gets extended if too short" ) ]
651695 [ InlineData ( 31 , 31 , 29 ) ]
652696 [ InlineData ( 1 , null , null ) ]
@@ -725,7 +769,7 @@ public async Task ArgoPlugin_Ensures_TTL_Remains(int? secondsAfterCompletion, in
725769 Assert . Equal ( secondsAfterFailure , _submittedArgoTemplate ? . Spec . TtlStrategy . SecondsAfterFailure ) ;
726770 }
727771
728- [ Fact ( DisplayName = "pocGC gets removed if pressent " ) ]
772+ [ Fact ( DisplayName = "pocGC gets removed if present " ) ]
729773 public async Task ArgoPlugin_Ensures_podGC_is_removed ( )
730774 {
731775 var argoTemplate = LoadArgoTemplate ( "SimpleTemplate.yml" ) ;
0 commit comments