Skip to content

Commit

Permalink
fix(pods): set resources from script templates (#6450)
Browse files Browse the repository at this point in the history
Signed-off-by: AntoineDao <antoinedao1@gmail.com>
  • Loading branch information
AntoineDao authored Jul 30, 2021
1 parent a39725d commit 3e9d837
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
15 changes: 12 additions & 3 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,18 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
if isResourcesSpecified(woc.controller.Config.MainContainer) {
c.Resources = *woc.controller.Config.MainContainer.Resources.DeepCopy()
}
// Container resources in workflow spec takes precedence over the main container's configuration in controller.
if isResourcesSpecified(tmpl.Container) && tmpl.Container.Name == common.MainContainerName {
c.Resources = *tmpl.Container.Resources.DeepCopy()
// Template resources inv workflow spec takes precedence over the main container's configuration in controller
switch tmpl.GetType() {
case wfv1.TemplateTypeContainer:
if isResourcesSpecified(tmpl.Container) && tmpl.Container.Name == common.MainContainerName {
c.Resources = *tmpl.Container.Resources.DeepCopy()
}
case wfv1.TemplateTypeScript:
if isResourcesSpecified(&tmpl.Script.Container) {
c.Resources = *tmpl.Script.Resources.DeepCopy()
}
case wfv1.TemplateTypeContainerSet:

}
mainCtrs[i] = c
}
Expand Down
38 changes: 38 additions & 0 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ func newWoc(wfs ...wfv1.Workflow) *wfOperationCtx {
return woc
}

var scriptWf = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: hello-world
spec:
entrypoint: whalesay
templates:
- name: script-with-input-artifact
inputs:
artifacts:
- name: kubectl
path: /bin/kubectl
http:
url: https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl
script:
image: alpine:latest
command: [sh]
source: |
ls /bin/kubectl
`

var scriptTemplateWithInputArtifact = `
name: script-with-input-artifact
inputs:
Expand Down Expand Up @@ -1287,6 +1309,22 @@ func TestMainContainerCustomization(t *testing.T) {
}
pod, _ = woc.createWorkflowPod(ctx, wf.Name, []apiv1.Container{*mainCtr}, &wf.Spec.Templates[0], &createWorkflowPodOpts{})
assert.Equal(t, "0.100", pod.Spec.Containers[1].Resources.Limits.Cpu().AsDec().String())

// If script template has limits then they take precedence over config in controller
wf = wfv1.MustUnmarshalWorkflow(scriptWf)
woc = newWoc(*wf)
woc.controller.Config.MainContainer = mainCtrSpec
mainCtr = &woc.execWf.Spec.Templates[0].Script.Container
wf.Spec.Templates[0].Script.Container.Resources = apiv1.ResourceRequirements{
Limits: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("1"),
apiv1.ResourceMemory: resource.MustParse("123Mi"),
},
}
pod, _ = woc.createWorkflowPod(ctx, wf.Name, []apiv1.Container{*mainCtr}, &wf.Spec.Templates[0], &createWorkflowPodOpts{})
assert.Equal(t, "1", pod.Spec.Containers[1].Resources.Limits.Cpu().AsDec().String())
assert.Equal(t, "128974848", pod.Spec.Containers[1].Resources.Limits.Memory().AsDec().String())

}

func TestIsResourcesSpecified(t *testing.T) {
Expand Down

0 comments on commit 3e9d837

Please sign in to comment.