Skip to content

Commit

Permalink
fix: Changes to workflow semaphore does work #12194 (#12284)
Browse files Browse the repository at this point in the history
Signed-off-by: Son Bui <sonbv00@gmail.com>
  • Loading branch information
sonbui00 authored and sarabala1979 committed Jan 8, 2024
1 parent 8bcf646 commit c6702d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion workflow/controller/indexes/workflow_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func WorkflowSemaphoreKeysIndexFunc() cache.IndexFunc {
if !ok {
return nil, nil
}
if un.GetLabels()[common.LabelKeyCompleted] != "false" {
completed, ok := un.GetLabels()[common.LabelKeyCompleted]
if ok && completed != "false" {
return nil, nil
}
wf, err := util.FromUnstructured(un)
Expand Down
17 changes: 17 additions & 0 deletions workflow/controller/indexes/workflow_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ func TestWorkflowIndexValue(t *testing.T) {
}

func TestWorkflowSemaphoreKeysIndexFunc(t *testing.T) {
t.Run("Incomplete without label", func(t *testing.T) {
un, _ := util.ToUnstructured(&wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
},
Spec: wfv1.WorkflowSpec{
Synchronization: &wfv1.Synchronization{
Semaphore: &wfv1.SemaphoreRef{
ConfigMapKeyRef: &apiv1.ConfigMapKeySelector{},
},
},
},
})
result, err := WorkflowSemaphoreKeysIndexFunc()(un)
assert.NoError(t, err)
assert.Len(t, result, 1)
})
t.Run("Incomplete", func(t *testing.T) {
un, _ := util.ToUnstructured(&wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 3 additions & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,9 @@ func (woc *wfOperationCtx) markWorkflowPhase(ctx context.Context, phase wfv1.Wor
woc.wf.ObjectMeta.Labels = make(map[string]string)
}
woc.wf.ObjectMeta.Labels[common.LabelKeyPhase] = string(phase)
if _, ok := woc.wf.ObjectMeta.Labels[common.LabelKeyCompleted]; !ok {
woc.wf.ObjectMeta.Labels[common.LabelKeyCompleted] = "false"
}
switch phase {
case wfv1.WorkflowRunning:
woc.eventRecorder.Event(woc.wf, apiv1.EventTypeNormal, "WorkflowRunning", "Workflow Running")
Expand Down
3 changes: 3 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ spec:
woc := newWorkflowOperationCtx(wf, controller)
woc.operate(ctx)

assert.Equal(t, "false", woc.wf.Labels[common.LabelKeyCompleted])

makePodsPhase(ctx, woc, apiv1.PodSucceeded)
woc = newWorkflowOperationCtx(woc.wf, controller)
woc.operate(ctx)
Expand All @@ -261,6 +263,7 @@ spec:
assert.Equal(t, wfv1.Progress("1/1"), woc.wf.Status.Progress)
assert.Equal(t, wfv1.Progress("1/1"), woc.wf.Status.Nodes[woc.wf.Name].Progress)
assert.Equal(t, wfv1.Progress("1/1"), woc.wf.Status.Nodes.FindByDisplayName("pod").Progress)
assert.Equal(t, "true", woc.wf.Labels[common.LabelKeyCompleted])
}

func TestLoggedProgress(t *testing.T) {
Expand Down

0 comments on commit c6702d5

Please sign in to comment.