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

Add AutoArchiveLogs option to send all workflow pod logs to Artifact Repository #1791

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions workflow/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type KubeConfig struct {
type ArtifactRepository struct {
// ArchiveLogs enables log archiving
ArchiveLogs *bool `json:"archiveLogs,omitempty"`
// AutoArchiveLogs enables log archiving for all tasks regardless of workflow configuration
AutoArchiveLogs *bool `json:"autoArchiveLogs,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Maybe ForceArchiveLogs is more explicit?

Copy link
Author

Choose a reason for hiding this comment

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

How about DefaultArchiveLogs? This change wouldn't force logs to be archived (users explicitly setting s3/artifactory destinations in template wouldn't be covered by this).

// S3 stores artifact in a S3-compliant object store
S3 *S3ArtifactRepository `json:"s3,omitempty"`
// Artifactory stores artifacts to JFrog Artifactory
Expand Down
3 changes: 3 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,9 @@ func (woc *wfOperationCtx) addArchiveLocation(pod *apiv1.Pod, tmpl *wfv1.Templat
break
}
}
if woc.artifactRepository.AutoArchiveLogs != nil && *woc.artifactRepository.AutoArchiveLogs {
needLocation = true
}
Copy link
Member

@simster7 simster7 Nov 26, 2019

Choose a reason for hiding this comment

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

Hmmm, currently it's not clear that even when enabling AutoArchiveLogs the user will also need to enable ArchiveLogs for the logs to be archived. Maybe a couple of lines below should actually be:

	tmpl.ArchiveLocation = &wfv1.ArtifactLocation{
		ArchiveLogs: woc.artifactRepository.ArchiveLogs || woc.artifactRepository.AutoArchiveLogs,
	}

Or something similar

Copy link
Author

Choose a reason for hiding this comment

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

Agreed on clarity. I think your proposal sounds reasonable.

if !needLocation {
woc.log.Debugf("archive location unnecessary")
return nil
Expand Down
27 changes: 26 additions & 1 deletion workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,31 @@ func TestConditionalArchiveLocation(t *testing.T) {
assert.Nil(t, tmpl.ArchiveLocation)
}

// TestDefaultAddArchiveLocationAutoArchiveLogs verifies we add archive location when AutoArchiveLogs is set
func TestDefaultAddArchiveLocationAutoArchiveLogs(t *testing.T) {
woc := newWoc()
trueValue := true
woc.artifactRepository = &config.ArtifactRepository{
AutoArchiveLogs: &trueValue,
ArchiveLogs: &trueValue,
}
woc.artifactRepository.S3 = &config.S3ArtifactRepository{
S3Bucket: wfv1.S3Bucket{
Bucket: "foo",
},
KeyFormat: "path/in/bucket",
}
woc.operate()
pods, err := woc.controller.kubeclientset.CoreV1().Pods("").List(metav1.ListOptions{})
assert.NoError(t, err)
assert.Len(t, pods.Items, 1)
pod := pods.Items[0]
var tmpl wfv1.Template
err = json.Unmarshal([]byte(pod.Annotations[common.AnnotationKeyTemplate]), &tmpl)
assert.NoError(t, err)
assert.True(t, *tmpl.ArchiveLocation.ArchiveLogs)
}

// TestVolumeAndVolumeMounts verifies the ability to carry forward volumes and volumeMounts from workflow.spec
func TestVolumeAndVolumeMounts(t *testing.T) {
volumes := []apiv1.Volume{
Expand Down Expand Up @@ -879,7 +904,7 @@ spec:
entrypoint: whalesay
templates:
- name: whalesay
podSpecPatch: '{"containers":[{"name":"main", "resources":{"limits":{"cpu": "800m"}}}]}'
podSpecPatch: '{"containers":[{"name":"main", "resources":{"limits":{"cpu": "800m"}}}]}'
container:
image: docker/whalesay:latest
command: [cowsay]
Expand Down