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

test: Add test for failed workflow artifact garbage collection. #12904

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,59 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() {
}
}

func (s *ArtifactsSuite) TestFailedWorkflow() {
Copy link
Member

Choose a reason for hiding this comment

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

The failed workflow is part of fixtures.ToBeCompleted
maybe we can include this in the

func (s *ArtifactsSuite) TestArtifactGC() {
instead?

c, err := minio.New("localhost:9000", &minio.Options{
Creds: credentials.NewStaticV4("admin", "password", ""),
})
assert.NoError(s.T(), err)

// Ensure the artifacts aren't in the bucket.
_, err = c.StatObject(context.Background(), "my-bucket-3", "on-deletion-wf-failed", minio.StatObjectOptions{})
if err == nil {
err = c.RemoveObject(context.Background(), "my-bucket-3", "on-deletion-wf-failed", minio.RemoveObjectOptions{})
assert.NoError(s.T(), err)
}

then := s.Given().
Workflow("@testdata/artifactgc/artgc-dag-wf-failed.yaml").
When().
Then()

// Assert the artifact doesn't exist
then.ExpectArtifactByKey("on-deletion-wf-failed", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) {
assert.NotNil(t, err)
})

then = then.When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeFailed).
Then()

// Assert artifact exists
then.ExpectArtifactByKey("on-deletion-wf-failed", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) {
assert.NoError(t, err)
})

when := then.When()

// Delete the workflow
when.
DeleteWorkflow().
WaitForWorkflowDeletion()

then = when.Then()

// Assert the artifacts don't exist.
then.ExpectArtifactByKey("on-deletion-wf-failed", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) {
assert.NotNil(t, err)
})

when = then.When()

// Remove the finalizers so the workflow gets deleted in case the test failed.
when.RemoveFinalizers(false)
}

func (s *ArtifactsSuite) TestDeleteWorkflow() {
when := s.Given().
Workflow("@testdata/artifactgc/artgc-dag-wf-self-delete.yaml").
Expand Down
74 changes: 74 additions & 0 deletions test/e2e/testdata/artifactgc/artgc-dag-wf-failed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artgc-dag-wf-failed-
spec:
workflowMetadata:
labels:
workflows.argoproj.io/test: "true"
workflows.argoproj.io/workflow: "artgc-dag-wf-failed"
podGC:
strategy: OnPodCompletion
artifactGC:
serviceAccountName: default
strategy: OnWorkflowDeletion
entrypoint: artgc-dag-wf-failed-main
serviceAccountName: argo
executor:
serviceAccountName: default
volumeClaimTemplates:
- metadata:
name: artifacts
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
templates:
- name: artgc-dag-wf-failed-main
dag:
tasks:
- name: create-artifact
template: artgc-dag-artifact-creator
- name: fail-workflow
template: artgc-dag-workflow-failer
dependencies: [create-artifact]
- name: artgc-dag-workflow-failer
container:
image: alpine:latest
command: [sh, -c]
args:
- |
echo "Failing workflow"
exit 1
- name: artgc-dag-artifact-creator
metadata:
labels:
template: "artgc-dag-artifact-creator"
container:
image: alpine:latest
volumeMounts:
- name: artifacts
mountPath: /mnt/vol
command: [sh, -c]
args:
- |
echo 'testing' > /mnt/vol/test.txt
echo "Artifact saved to /mnt/vol/test.txt"
outputs:
artifacts:
- name: on-deletion-wf-failed
path: /mnt/vol/test.txt
s3:
key: on-deletion-wf-failed
bucket: my-bucket-3
endpoint: minio:9000
insecure: true
accessKeySecret:
name: my-minio-cred
key: accesskey
secretKeySecret:
name: my-minio-cred
key: secretkey
artifactGC:
strategy: OnWorkflowDeletion