Skip to content

Commit

Permalink
fix: Panic on releaseAllWorkflowLocks if Object is not Unstructured t…
Browse files Browse the repository at this point in the history
…ype (argoproj#3504)
  • Loading branch information
sarabala1979 committed Jul 17, 2020
1 parent 1b68a5a commit 7d45ff7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,16 @@ func (wfc *WorkflowController) releaseAllWorkflowLocks(obj interface{}) {
un, ok := obj.(*unstructured.Unstructured)
if !ok {
log.Warnf("Key '%s' in index is not an unstructured", obj)
return
}
wf, err := util.FromUnstructured(un)
if err != nil {
log.Warnf("Invalid workflow object: %v", obj)
return
}
if wf.Status.Synchronization != nil {
wfc.syncManager.ReleaseAll(wf)
}
wfc.syncManager.ReleaseAll(wf)
}

func (wfc *WorkflowController) isArchivable(wf *wfv1.Workflow) bool {
Expand Down
17 changes: 17 additions & 0 deletions workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/record"

Expand Down Expand Up @@ -424,3 +425,19 @@ func TestIsArchivable(t *testing.T) {
assert.True(t, controller.isArchivable(workflow))
})
}

func TestReleaseAllWorkflowLocks(t *testing.T) {
cancel, controller := newController()
defer cancel()
t.Run("nilObject", func(t *testing.T) {
controller.releaseAllWorkflowLocks(nil)
})
t.Run("unStructuredObject", func(t *testing.T) {
un := &unstructured.Unstructured{}
controller.releaseAllWorkflowLocks(un)
})
t.Run("otherObject", func(t *testing.T) {
un := &wfv1.Workflow{}
controller.releaseAllWorkflowLocks(un)
})
}

0 comments on commit 7d45ff7

Please sign in to comment.