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

fix(Artifact GC): modified SearchArtifact to return ArtifactSearchResults. Fixes #8543 #8557

Merged
merged 2 commits into from
Apr 30, 2022
Merged
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 pkg/apis/api-rules/violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ API rule violation: list_type_missing,github.com/argoproj/argo-workflows/v3/pkg/
API rule violation: list_type_missing,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,WorkflowSpec,Volumes
API rule violation: list_type_missing,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,WorkflowStatus,PersistentVolumeClaims
API rule violation: list_type_missing,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,WorkflowStep,WithItems
API rule violation: names_match,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,ArtifactSearchResult,Artifact
API rule violation: names_match,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,ArtifactSearchResult,NodeID
API rule violation: names_match,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,SubmitOpts,Entrypoint
API rule violation: names_match,github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1,WorkflowStatus,StoredWorkflowSpec
1,638 changes: 923 additions & 715 deletions pkg/apis/workflow/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions pkg/apis/workflow/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions pkg/apis/workflow/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,13 @@ type ArtifactSearchQuery struct {
NodeId string `json:"nodeId,omitempty" protobuf:"bytes,4,rep,name=nodeId"`
}

type ArtifactSearchResult struct {
Artifact `protobuf:"bytes,1,opt,name=artifact"`
NodeID string `protobuf:"bytes,2,opt,name=nodeID"`
}

type ArtifactSearchResults []ArtifactSearchResult

func NewArtifactSearchQuery() *ArtifactSearchQuery {
var q ArtifactSearchQuery
q.ArtifactGCStrategies = make(map[ArtifactGCStrategy]bool)
Expand All @@ -1272,9 +1279,9 @@ func (q *ArtifactSearchQuery) anyArtifactGCStrategy() bool {
return false
}

func (w *Workflow) SearchArtifacts(q *ArtifactSearchQuery) Artifacts {
func (w *Workflow) SearchArtifacts(q *ArtifactSearchQuery) ArtifactSearchResults {

var artifacts Artifacts
var results ArtifactSearchResults

for _, n := range w.Status.Nodes {
t := w.GetTemplateByName(n.TemplateName)
Expand All @@ -1301,11 +1308,11 @@ func (w *Workflow) SearchArtifacts(q *ArtifactSearchQuery) Artifacts {
match = false
}
if match == true {
artifacts = append(artifacts, a)
results = append(results, ArtifactSearchResult{Artifact: a, NodeID: n.ID})
rohankmr414 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return artifacts
return results
}

// Outputs hold parameters, artifacts, and results from a step
Expand Down
64 changes: 43 additions & 21 deletions pkg/apis/workflow/v1alpha1/workflow_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,51 +826,73 @@ func TestWorkflow_SearchArtifacts(t *testing.T) {
query := NewArtifactSearchQuery()

// no filters
queriedArtifacts := wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 3)
queriedArtifactSearchResults := wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 3)
assert.Equal(t, "artifact-foo", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "artifact-bar", queriedArtifactSearchResults[1].Artifact.Name)
assert.Equal(t, "artifact-foobar", queriedArtifactSearchResults[2].Artifact.Name)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[0].NodeID)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[1].NodeID)
assert.Equal(t, "node-bar", queriedArtifactSearchResults[2].NodeID)

// artifact GC strategy
query.ArtifactGCStrategies[ArtifactGCOnWorkflowCompletion] = true
queriedArtifacts = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 3)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 3)
assert.Equal(t, "artifact-foo", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "artifact-bar", queriedArtifactSearchResults[1].Artifact.Name)
assert.Equal(t, "artifact-foobar", queriedArtifactSearchResults[2].Artifact.Name)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[0].NodeID)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[1].NodeID)
assert.Equal(t, "node-bar", queriedArtifactSearchResults[2].NodeID)

// template name
query = NewArtifactSearchQuery()
query.TemplateName = "template-bar"
queriedArtifacts = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 1)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 1)
assert.Equal(t, "artifact-foobar", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "node-bar", queriedArtifactSearchResults[0].NodeID)

// artifact name
query = NewArtifactSearchQuery()
query.ArtifactName = "artifact-foo"
queriedArtifacts = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 1)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 1)
assert.Equal(t, "artifact-foo", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[0].NodeID)

// node id
query = NewArtifactSearchQuery()
query.NodeId = "node-foo"
queriedArtifacts = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 2)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 2)
assert.Equal(t, "artifact-foo", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "artifact-bar", queriedArtifactSearchResults[1].Artifact.Name)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[0].NodeID)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[1].NodeID)

// bad query
query = NewArtifactSearchQuery()
query.NodeId = "node-foobar"
queriedArtifacts = wf.SearchArtifacts(query)
assert.Nil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 0)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.Nil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 0)

// template and artifact name
query = NewArtifactSearchQuery()
query.TemplateName = "template-foo"
query.ArtifactName = "artifact-foo"
queriedArtifacts = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifacts)
assert.Len(t, queriedArtifacts, 1)
queriedArtifactSearchResults = wf.SearchArtifacts(query)
assert.NotNil(t, queriedArtifactSearchResults)
assert.Len(t, queriedArtifactSearchResults, 1)
assert.Equal(t, "artifact-foo", queriedArtifactSearchResults[0].Artifact.Name)
assert.Equal(t, "node-foo", queriedArtifactSearchResults[0].NodeID)
}

func TestWorkflowSpec_GetArtifactGC(t *testing.T) {
Expand Down
39 changes: 39 additions & 0 deletions pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.