Skip to content

Commit

Permalink
fix(controller): node message should be updated when lock msg changed (
Browse files Browse the repository at this point in the history
…#13648)

Signed-off-by: joey <zchengjoey@gmail.com>
Co-authored-by: Alan Clucas <alan@clucas.org>
  • Loading branch information
chengjoey and Joibel authored Oct 11, 2024
1 parent f1347b6 commit 7007cba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 7 additions & 3 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1981,11 +1981,11 @@ func (woc *wfOperationCtx) executeTemplate(ctx context.Context, nodeName string,
node = woc.initializeExecutableNode(nodeName, wfutil.GetNodeType(processedTmpl), templateScope, processedTmpl, orgTmpl, opts.boundaryID, wfv1.NodePending, opts.nodeFlag, msg)
}
woc.log.Infof("Could not acquire lock named: %s", failedLockName)
return woc.markNodeWaitingForLock(node.Name, failedLockName)
return woc.markNodeWaitingForLock(node.Name, failedLockName, msg)
} else {
woc.log.Infof("Node %s acquired synchronization lock", nodeName)
if node != nil {
node, err = woc.markNodeWaitingForLock(node.Name, "")
node, err = woc.markNodeWaitingForLock(node.Name, "", "")
if err != nil {
woc.log.WithField("node.Name", node.Name).WithField("lockName", "").Error("markNodeWaitingForLock returned err")
return nil, err
Expand Down Expand Up @@ -2740,7 +2740,7 @@ func (woc *wfOperationCtx) markNodePending(nodeName string, err error) *wfv1.Nod
}

// markNodeWaitingForLock is a convenience method to mark that a node is waiting for a lock
func (woc *wfOperationCtx) markNodeWaitingForLock(nodeName string, lockName string) (*wfv1.NodeStatus, error) {
func (woc *wfOperationCtx) markNodeWaitingForLock(nodeName string, lockName string, message string) (*wfv1.NodeStatus, error) {
node, err := woc.wf.GetNodeByName(nodeName)
if err != nil {
return node, err
Expand All @@ -2758,6 +2758,10 @@ func (woc *wfOperationCtx) markNodeWaitingForLock(nodeName string, lockName stri
node.SynchronizationStatus.Waiting = lockName
}

if len(message) > 0 {
node.Message = message
}

woc.wf.Status.Nodes.Set(node.ID, *node)
woc.updated = true
return node, nil
Expand Down
14 changes: 12 additions & 2 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8491,6 +8491,10 @@ metadata:
namespace: argo
spec:
entrypoint: whalesay
arguments:
parameters:
- name: derived-mutex-name
value: welcome
templates:
- container:
args:
Expand All @@ -8501,7 +8505,7 @@ spec:
name: whalesay
synchronization:
mutex:
name: welcome
name: "{{ workflow.parameters.derived-mutex-name }}"
ttlStrategy:
secondsAfterCompletion: 600
status:
Expand All @@ -8510,7 +8514,6 @@ status:
displayName: hello-world-mpdht
finishedAt: null
id: hello-world-mpdht
message: 'Waiting for argo/Mutex/welcome lock. Lock status: 0/1 '
name: hello-world-mpdht
phase: Pending
progress: 0/1
Expand All @@ -8537,13 +8540,20 @@ func TestMutexWfPendingWithNoPod(t *testing.T) {
ctx := context.Background()
controller.syncManager = sync.NewLockManager(GetSyncLimitFunc(ctx, controller.kubeclientset), func(key string) {
}, workflowExistenceFunc)

// preempt lock
_, _, _, _, err := controller.syncManager.TryAcquire(wf, "test", &wfv1.Synchronization{Mutex: &wfv1.Mutex{Name: "welcome"}})
require.NoError(t, err)
woc := newWorkflowOperationCtx(wf, controller)

woc.operate(ctx)
assert.Equal(t, wfv1.WorkflowRunning, woc.wf.Status.Phase)
assert.Equal(t, wfv1.NodePending, woc.wf.Status.Nodes.FindByDisplayName("hello-world-mpdht").Phase)
assert.Equal(t, "Waiting for argo/Mutex/welcome lock. Lock status: 0/1", woc.wf.Status.Nodes.FindByDisplayName("hello-world-mpdht").Message)

woc.controller.syncManager.Release(wf, "test", &wfv1.Synchronization{Mutex: &wfv1.Mutex{Name: "welcome"}})
woc.operate(ctx)
assert.Equal(t, "", woc.wf.Status.Nodes.FindByDisplayName("hello-world-mpdht").Message)
}

var wfGlobalArtifactNil = `apiVersion: argoproj.io/v1alpha1
Expand Down

0 comments on commit 7007cba

Please sign in to comment.