Skip to content

Commit

Permalink
fix: Global Artifact Passing. Fixes #12554 (#12559)
Browse files Browse the repository at this point in the history
Signed-off-by: Garett MacGowan <garettsoftware@gmail.com>
  • Loading branch information
Garett-MacGowan committed Jan 23, 2024
1 parent baef485 commit c46986e
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 7 deletions.
12 changes: 10 additions & 2 deletions test/e2e/argo_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,21 @@ func (s *ArgoServerSuite) TestArtifactServerArchivedStoppedWorkflow() {
nodeID = status.Nodes.FindByDisplayName("create-artifact").ID
})

s.Run("GetArtifactByNodeID", func() {
s.e().GET("/artifact-files/argo/archived-workflows/{uid}/{nodeID}/outputs/artifact-creator", uid, nodeID).
s.Run("GetLocalArtifactByNodeID", func() {
s.e().GET("/artifact-files/argo/archived-workflows/{uid}/{nodeID}/outputs/local-artifact", uid, nodeID).
Expect().
Status(200).
Body().
Contains("testing")
})

s.Run("GetGlobalArtifactByNodeID", func() {
s.e().GET("/artifact-files/argo/archived-workflows/{uid}/{nodeID}/outputs/global-artifact", uid, nodeID).
Expect().
Status(200).
Body().
Contains("testing global")
})
}

// make sure we can download an artifact
Expand Down
87 changes: 87 additions & 0 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package e2e

import (
"bytes"
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -60,6 +62,71 @@ func (s *ArtifactsSuite) TestArtifactPassing() {
WaitForWorkflow(fixtures.ToBeSucceeded)
}

type expectedArtifact struct {
key string
bucketName string
value string
}

func (s *ArtifactsSuite) TestGlobalArtifactPassing() {
for _, tt := range []struct {
workflowFile string
expectedArtifact expectedArtifact
}{
{
workflowFile: "@testdata/global-artifact-passing.yaml",
expectedArtifact: expectedArtifact{
key: "globalArtifact",
bucketName: "my-bucket-3",
value: "01",
},
},
{
workflowFile: "@testdata/complex-global-artifact-passing.yaml",
expectedArtifact: expectedArtifact{
key: "finalTestUpdate",
bucketName: "my-bucket-3",
value: "Updated testUpdate",
},
},
} {
then := s.Given().
Workflow(tt.workflowFile).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded, time.Minute*2).
Then().
ExpectWorkflow(func(t *testing.T, objectMeta *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
// Check the global artifact value and see if it equals the expected value.
c, err := minio.New("localhost:9000", &minio.Options{
Creds: credentials.NewStaticV4("admin", "password", ""),
})

if err != nil {
t.Error(err)
}

object, err := c.GetObject(context.Background(), tt.expectedArtifact.bucketName, tt.expectedArtifact.key, minio.GetObjectOptions{})
if err != nil {
t.Error(err)
}

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(object)
if err != nil {
t.Error(err)
}
value := buf.String()

assert.Equal(t, tt.expectedArtifact.value, value)
})

then.
When().
RemoveFinalizers(false)
}
}

type artifactState struct {
key string
bucketName string
Expand Down Expand Up @@ -157,6 +224,26 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() {
}
}

func (s *ArtifactsSuite) TestDeleteWorkflow() {
when := s.Given().
Workflow("@testdata/artifactgc/artgc-dag-wf-self-delete.yaml").
When().
SubmitWorkflow()

then := when.
WaitForWorkflow(fixtures.ToBeCompleted).
Then().
ExpectWorkflow(func(t *testing.T, objectMeta *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Contains(t, objectMeta.Finalizers, common.FinalizerArtifactGC)
})

when = then.When()

when.WaitForWorkflowDeletion()

when.RemoveFinalizers(false)
}

func (s *ArtifactsSuite) TestArtifactGC() {

s.Given().
Expand Down
23 changes: 20 additions & 3 deletions test/e2e/testdata/artifact-workflow-stopped.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
while [ $x -le 60 ]
do
sleep 1
if [ -f "/mnt/vol/test.txt" ]; then
if [ -f "/mnt/vol/test.txt" ] && [ -f "/mnt/vol/globaltest.txt" ]; then
echo "Artifact found in shared volume"
break
fi
Expand Down Expand Up @@ -73,6 +73,7 @@ spec:
args:
- |
echo 'testing' > /mnt/vol/test.txt
echo 'testing global' > /mnt/vol/globaltest.txt
echo "Artifact saved to /mnt/vol/test.txt"
echo "Pretending to continue to do work."
ls /mnt
Expand All @@ -82,10 +83,26 @@ spec:
done
outputs:
artifacts:
- name: artifact-creator
- name: local-artifact
path: /mnt/vol/test.txt
s3:
key: artifact-creator
key: local-artifact
bucket: my-bucket-3
endpoint: minio:9000
insecure: true
accessKeySecret:
name: my-minio-cred
key: accesskey
secretKeySecret:
name: my-minio-cred
key: secretkey
archive:
none: {}
- name: global-artifact
globalName: global-artifact-global-name
path: /mnt/vol/globaltest.txt
s3:
key: global-artifact
bucket: my-bucket-3
endpoint: minio:9000
insecure: true
Expand Down
99 changes: 99 additions & 0 deletions test/e2e/testdata/artifactgc/artgc-dag-wf-self-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artgc-dag-wf-self-delete-
spec:
workflowMetadata:
labels:
workflows.argoproj.io/test: "true"
workflows.argoproj.io/workflow: "artgc-dag-wf-self-delete"
podGC:
strategy: OnPodCompletion
artifactGC:
serviceAccountName: default
strategy: OnWorkflowDeletion
entrypoint: artgc-dag-wf-self-delete-main
serviceAccountName: argo
executor:
serviceAccountName: default
volumeClaimTemplates:
- metadata:
name: artifacts
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
templates:
- name: artgc-dag-wf-self-delete-main
dag:
tasks:
- name: create-artifact
template: artgc-dag-artifact-creator
- name: delay-delete-workflow
template: artgc-dag-delay-delete
dependencies: [create-artifact]
- name: delete-workflow
template: artgc-dag-workflow-deleter
dependencies: [delay-delete-workflow]
- name: artgc-dag-delay-delete
container:
image: alpine:latest
volumeMounts:
- name: artifacts
mountPath: /mnt/vol
command: [sh, -c]
args:
- |
echo "Delaying workflow delete"
ls /mnt
x=0
while [ $x -le 60 ]
do
sleep 1
if [ -f "/mnt/vol/test.txt" ]; then
echo "Artifacts found in shared volume"
break
fi
x=$(( $x + 1 ))
done
- name: artgc-dag-workflow-deleter
container:
image: argoproj/argocli:latest
args:
- delete
- -l
- workflows.argoproj.io/workflow=artgc-dag-wf-self-delete
- --namespace=argo
- --loglevel=debug
- 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: artifact
path: /mnt/vol/test.txt
s3:
key: artifact
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

0 comments on commit c46986e

Please sign in to comment.