@@ -60,6 +60,14 @@ public class ArgoPluginTest
60
60
private Workflow ? _submittedArgoTemplate ;
61
61
private readonly int _argoTtlStatergySeconds = 360 ;
62
62
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" ;
63
71
64
72
public ArgoPluginTest ( )
65
73
{
@@ -80,8 +88,16 @@ public ArgoPluginTest()
80
88
_options . Value . Messaging . PublisherSettings . Add ( "exchange" , "exchange" ) ;
81
89
_options . Value . Messaging . PublisherSettings . Add ( "virtualHost" , "vhost" ) ;
82
90
_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 ;
85
101
86
102
_serviceScopeFactory . Setup ( p => p . CreateScope ( ) ) . Returns ( _serviceScope . Object ) ;
87
103
@@ -630,8 +646,8 @@ public async Task ArgoPlugin_Copies_ImagePullSecrets()
630
646
Assert . Equal ( secret , _submittedArgoTemplate ? . Spec . ImagePullSecrets . First ( ) ) ;
631
647
}
632
648
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 ( )
635
651
{
636
652
var argoTemplate = LoadArgoTemplate ( "SimpleTemplate.yml" ) ;
637
653
Assert . NotNull ( argoTemplate ) ;
@@ -647,6 +663,34 @@ public async Task ArgoPlugin_Ensures_TTL_Added_If_Not_pressent()
647
663
Assert . Equal ( _argoTtlStatergySeconds , _submittedArgoTemplate ? . Spec . TtlStrategy ? . SecondsAfterCompletion ) ;
648
664
}
649
665
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
+
650
694
[ Theory ( DisplayName = "TTL gets extended if too short" ) ]
651
695
[ InlineData ( 31 , 31 , 29 ) ]
652
696
[ InlineData ( 1 , null , null ) ]
@@ -725,7 +769,7 @@ public async Task ArgoPlugin_Ensures_TTL_Remains(int? secondsAfterCompletion, in
725
769
Assert . Equal ( secondsAfterFailure , _submittedArgoTemplate ? . Spec . TtlStrategy . SecondsAfterFailure ) ;
726
770
}
727
771
728
- [ Fact ( DisplayName = "pocGC gets removed if pressent " ) ]
772
+ [ Fact ( DisplayName = "pocGC gets removed if present " ) ]
729
773
public async Task ArgoPlugin_Ensures_podGC_is_removed ( )
730
774
{
731
775
var argoTemplate = LoadArgoTemplate ( "SimpleTemplate.yml" ) ;
0 commit comments