Skip to content

Commit

Permalink
Don't provision VM for empty artifacts (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored and sarabala1979 committed Oct 8, 2019
1 parent b5dcac8 commit 502db42
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@ func (woc *wfOperationCtx) addInputArtifactsVolumes(pod *apiv1.Pod, tmpl *wfv1.T
if art.Path == "" {
return errors.Errorf(errors.CodeBadRequest, "inputs.artifacts.%s did not specify a path", art.Name)
}
if !art.HasLocation() && art.Optional {
woc.log.Infof("skip volume mount of %s (%s): optional artifact was not provided",
art.Name, art.Path)
continue
}
overlap := common.FindOverlappingVolume(tmpl, art.Path)
if overlap != nil {
// artifact path overlaps with a mounted volume. do not mount the
Expand Down
59 changes: 59 additions & 0 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,65 @@ func TestScriptTemplateWithVolume(t *testing.T) {
assert.NoError(t, err)
}

var scriptTemplateWithOptionalInputArtifactProvided = `
name: script-with-input-artifact
inputs:
artifacts:
- name: manifest
path: /manifest
optional: true
http:
url: https://raw.githubusercontent.com/argoproj/argo/stable/manifests/install.yaml
script:
image: alpine:latest
command: [sh]
source: |
ls -al
`

var scriptTemplateWithOptionalInputArtifactNotProvided = `
name: script-with-input-artifact
inputs:
artifacts:
- name: manifest
path: /manifest
optional: true
script:
image: alpine:latest
command: [sh]
source: |
ls -al
`
// TestScriptTemplateWithVolume ensure we can a script pod with input artifacts
func TestScriptTemplateWithoutVolumeOptionalArtifact(t *testing.T) {
volumeMount := apiv1.VolumeMount{
Name: "input-artifacts",
ReadOnly: false,
MountPath: "/manifest",
SubPath: "manifest",
MountPropagation: nil,
SubPathExpr: "",
}

// Ensure that volume mount is added when artifact is provided
tmpl := unmarshalTemplate(scriptTemplateWithOptionalInputArtifactProvided)
woc := newWoc()
mainCtr := tmpl.Script.Container
mainCtr.Args = append(mainCtr.Args, common.ExecutorScriptSourcePath)
pod, err := woc.createWorkflowPod(tmpl.Name, mainCtr, tmpl, true)
assert.NoError(t, err)
assert.Contains(t, pod.Spec.Containers[1].VolumeMounts, volumeMount)

// Ensure that volume mount is not created when artifact is not provided
tmpl = unmarshalTemplate(scriptTemplateWithOptionalInputArtifactNotProvided)
woc = newWoc()
mainCtr = tmpl.Script.Container
mainCtr.Args = append(mainCtr.Args, common.ExecutorScriptSourcePath)
pod, err = woc.createWorkflowPod(tmpl.Name, mainCtr, tmpl, true)
assert.NoError(t, err)
assert.NotContains(t, pod.Spec.Containers[1].VolumeMounts, volumeMount)
}

// TestWFLevelServiceAccount verifies the ability to carry forward the service account name
// for the pod from workflow.spec.serviceAccountName.
func TestWFLevelServiceAccount(t *testing.T) {
Expand Down

0 comments on commit 502db42

Please sign in to comment.