-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update
workflowtaskresult
code have own reconciliation loop. (#…
…8135) Signed-off-by: Alex Collins <alex_collins@intuit.com>
- Loading branch information
Showing
8 changed files
with
77 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,65 @@ | ||
package controller | ||
|
||
import ( | ||
"reflect" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" | ||
"github.com/argoproj/argo-workflows/v3/pkg/client/informers/externalversions" | ||
wfextvv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/client/informers/externalversions/workflow/v1alpha1" | ||
"github.com/argoproj/argo-workflows/v3/workflow/common" | ||
"github.com/argoproj/argo-workflows/v3/workflow/util" | ||
"github.com/argoproj/argo-workflows/v3/workflow/controller/indexes" | ||
) | ||
|
||
func (wfc *WorkflowController) newWorkflowTaskResultInformer() wfextvv1alpha1.WorkflowTaskResultInformer { | ||
informer := externalversions.NewSharedInformerFactoryWithOptions( | ||
func (wfc *WorkflowController) newWorkflowTaskResultInformer() cache.SharedIndexInformer { | ||
labelSelector := labels.NewSelector(). | ||
Add(*workflowReq). | ||
Add(wfc.instanceIDReq()). | ||
String() | ||
log.WithField("labelSelector", labelSelector). | ||
Info("Watching task results") | ||
return wfextvv1alpha1.NewFilteredWorkflowTaskResultInformer( | ||
wfc.wfclientset, | ||
workflowTaskSetResyncPeriod, | ||
externalversions.WithNamespace(wfc.GetManagedNamespace()), | ||
externalversions.WithTweakListOptions(func(x *metav1.ListOptions) { | ||
r := util.InstanceIDRequirement(wfc.Config.InstanceID) | ||
x.LabelSelector = r.String() | ||
})).Argoproj().V1alpha1().WorkflowTaskResults() | ||
informer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(new interface{}) { | ||
result := new.(*wfv1.WorkflowTaskResult) | ||
workflow := result.Labels[common.LabelKeyWorkflow] | ||
wfc.wfQueue.AddRateLimited(result.Namespace + "/" + workflow) | ||
}, | ||
UpdateFunc: func(_, new interface{}) { | ||
result := new.(*wfv1.WorkflowTaskResult) | ||
workflow := result.Labels[common.LabelKeyWorkflow] | ||
wfc.wfQueue.AddRateLimited(result.Namespace + "/" + workflow) | ||
}, | ||
}) | ||
return informer | ||
wfc.GetManagedNamespace(), | ||
20*time.Minute, | ||
cache.Indexers{ | ||
indexes.WorkflowIndex: indexes.MetaWorkflowIndexFunc, | ||
}, | ||
func(options *metav1.ListOptions) { | ||
options.LabelSelector = labelSelector | ||
}, | ||
) | ||
} | ||
|
||
func (woc *wfOperationCtx) taskResultReconciliation() { | ||
objs, _ := woc.controller.taskResultInformer.GetIndexer().ByIndex(indexes.WorkflowIndex, woc.wf.Namespace+"/"+woc.wf.Name) | ||
woc.log.WithField("numObjs", len(objs)).Info("Task-result reconciliation") | ||
for _, obj := range objs { | ||
result := obj.(*wfv1.WorkflowTaskResult) | ||
nodeID := result.Name | ||
old := woc.wf.Status.Nodes[nodeID] | ||
new := old.DeepCopy() | ||
if result.Outputs.HasOutputs() { | ||
if new.Outputs == nil { | ||
new.Outputs = &wfv1.Outputs{} | ||
} | ||
result.Outputs.DeepCopyInto(new.Outputs) // preserve any existing values | ||
if old.Outputs != nil && new.Outputs.ExitCode == nil { // prevent overwriting of ExitCode | ||
new.Outputs.ExitCode = old.Outputs.ExitCode | ||
} | ||
} | ||
if result.Progress.IsValid() { | ||
new.Progress = result.Progress | ||
} | ||
if !reflect.DeepEqual(&old, new) { | ||
woc.log. | ||
WithField("nodeID", nodeID). | ||
Info("task-result changed") | ||
woc.wf.Status.Nodes[nodeID] = *new | ||
woc.updated = true | ||
} | ||
} | ||
} |