fix(gitops/sources): fix the handling of the newer structure BE-12919 (#2931)
This commit is contained in:
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
gittypes "github.com/portainer/portainer/api/git/types"
|
||||
ce "github.com/portainer/portainer/api/gitops/workflows"
|
||||
"github.com/portainer/portainer/api/set"
|
||||
"github.com/portainer/portainer/api/slicesx"
|
||||
)
|
||||
|
||||
// FetchSourceWorkflows returns the workflows and stats for a single source.
|
||||
@@ -27,7 +27,18 @@ func FetchSourceWorkflows(tx dataservices.DataStoreTx, src *portainer.Source) ([
|
||||
return nil, ce.SourceStats{}, nil
|
||||
}
|
||||
|
||||
wfIDSet := set.ToSet(slicesx.Map(wfs, func(wf portainer.Workflow) portainer.WorkflowID { return wf.ID }))
|
||||
wfIDSet := make(map[portainer.WorkflowID]struct{}, len(wfs))
|
||||
artifactByStack := make(map[portainer.StackID]portainer.ArtifactFile)
|
||||
for _, wf := range wfs {
|
||||
wfIDSet[wf.ID] = struct{}{}
|
||||
for _, art := range wf.Artifacts {
|
||||
for _, f := range art.Files {
|
||||
if f.SourceID == src.ID {
|
||||
artifactByStack[art.StackID] = f
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stacks, err := tx.Stack().ReadAll(func(s portainer.Stack) bool {
|
||||
_, ok := wfIDSet[s.WorkflowID]
|
||||
@@ -41,16 +52,32 @@ func FetchSourceWorkflows(tx dataservices.DataStoreTx, src *portainer.Source) ([
|
||||
items := make([]ce.Workflow, 0, len(stacks))
|
||||
stats := ce.SourceStats{EndpointIDs: set.Set[portainer.EndpointID]{}}
|
||||
|
||||
for _, stacks := range stacks {
|
||||
items = append(items, ce.MapStackToWorkflow(stacks, src.Git, unknown, unknown))
|
||||
for _, s := range stacks {
|
||||
gitCfg := gitConfigForArtifact(src.Git, artifactByStack[s.ID])
|
||||
items = append(items, ce.MapStackToWorkflow(s, gitCfg, unknown, unknown))
|
||||
stats.WorkflowCount++
|
||||
if stacks.EndpointID != 0 {
|
||||
stats.EndpointIDs.Add(stacks.EndpointID)
|
||||
if s.EndpointID != 0 {
|
||||
stats.EndpointIDs.Add(s.EndpointID)
|
||||
}
|
||||
if lastSync := ce.StackLastSyncDate(stacks); lastSync > stats.LastSync {
|
||||
if lastSync := ce.StackLastSyncDate(s); lastSync > stats.LastSync {
|
||||
stats.LastSync = lastSync
|
||||
}
|
||||
}
|
||||
|
||||
return items, stats, nil
|
||||
}
|
||||
|
||||
func gitConfigForArtifact(src *gittypes.RepoConfig, af portainer.ArtifactFile) *gittypes.RepoConfig {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &gittypes.RepoConfig{
|
||||
URL: src.URL,
|
||||
Authentication: src.Authentication,
|
||||
TLSSkipVerify: src.TLSSkipVerify,
|
||||
ReferenceName: af.Ref,
|
||||
ConfigFilePath: af.Path,
|
||||
ConfigHash: af.Hash,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user