Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): Fail workflow when pod is deleted with --force. Fixes #3097 #3469

Merged
merged 1 commit into from Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions workflow/controller/controller.go
Expand Up @@ -726,30 +726,34 @@ func (wfc *WorkflowController) newPodInformer() cache.SharedIndexInformer {
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
key, err := cache.MetaNamespaceKeyFunc(obj)
if err == nil {
wfc.podQueue.Add(key)
if err != nil {
return
}
wfc.podQueue.Add(key)
},
UpdateFunc: func(old, new interface{}) {
key, err := cache.MetaNamespaceKeyFunc(new)
if err != nil {
return
}
oldPod, newPod := old.(*apiv1.Pod), new.(*apiv1.Pod)
if oldPod.ResourceVersion == newPod.ResourceVersion {
return
}
if !pod.SignificantPodChange(oldPod, newPod) {
log.WithField("key", key).Info("insignificant pod change")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be more aware when we ignore changes.

return
}
key, err := cache.MetaNamespaceKeyFunc(new)
if err == nil {
wfc.podQueue.Add(key)
}
wfc.podQueue.Add(key)
},
DeleteFunc: func(obj interface{}) {
// IndexerInformer uses a delta queue, therefore for deletes we have to use this
// key function.
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err == nil {
wfc.podQueue.Add(key)
if err != nil {
return
}
wfc.podQueue.Add(key)
},
},
)
Expand Down
1 change: 1 addition & 0 deletions workflow/controller/pod/significant.go
Expand Up @@ -9,6 +9,7 @@ func SignificantPodChange(from *apiv1.Pod, to *apiv1.Pod) bool {
from.Status.Phase != to.Status.Phase ||
from.Status.Message != to.Status.Message ||
from.Status.PodIP != to.Status.PodIP ||
from.GetDeletionTimestamp() != to.GetDeletionTimestamp() ||
significantContainerStatusesChange(from.Status.ContainerStatuses, to.Status.ContainerStatuses) ||
significantContainerStatusesChange(from.Status.InitContainerStatuses, to.Status.InitContainerStatuses)
}
Expand Down
6 changes: 6 additions & 0 deletions workflow/controller/pod/significant_test.go
Expand Up @@ -5,10 +5,16 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_SgnificantPodChange(t *testing.T) {
assert.False(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{}), "No change")

t.Run("DeletionTimestamp", func(t *testing.T) {
now := metav1.Now()
assert.True(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{DeletionTimestamp: &now}}), "deletion timestamp change")
})
t.Run("Spec", func(t *testing.T) {
assert.True(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{Spec: corev1.PodSpec{NodeName: "from"}}), "Node name change")

Expand Down