Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't provision volumeMount for empty artifacts #1660

Merged
merged 7 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +106 to +107
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to capture the result of this command and test on it but was not able to find a way to do it. Is there a way how?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest implementation will ignore the script output if there is no reference for output in template.

`
// 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