Skip to content

Commit

Permalink
fix(controller): Adds ALL_POD_CHANGES_SIGNIFICANT (#3689)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Aug 6, 2020
1 parent 819bfdb commit dca3b6c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
wfextvv1alpha1 "github.com/argoproj/argo/pkg/client/informers/externalversions/workflow/v1alpha1"
authutil "github.com/argoproj/argo/util/auth"
"github.com/argoproj/argo/workflow/common"
controllercache "github.com/argoproj/argo/workflow/controller/cache"
"github.com/argoproj/argo/workflow/controller/pod"
"github.com/argoproj/argo/workflow/cron"
"github.com/argoproj/argo/workflow/hydrator"
Expand Down Expand Up @@ -658,6 +659,7 @@ func (wfc *WorkflowController) newPodInformer() cache.SharedIndexInformer {
}
if !pod.SignificantPodChange(oldPod, newPod) {
log.WithField("key", key).Info("insignificant pod change")
pod.LogChanges(oldPod, newPod)
return
}
wfc.podQueue.Add(key)
Expand Down
16 changes: 16 additions & 0 deletions workflow/controller/pod/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pod

import (
"encoding/json"

log "github.com/sirupsen/logrus"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/strategicpatch"
)

func LogChanges(oldPod *apiv1.Pod, newPod *apiv1.Pod) {
a, _ := json.Marshal(oldPod)
b, _ := json.Marshal(newPod)
patch, _ := strategicpatch.CreateTwoWayMergePatch(a, b, &apiv1.Pod{})
log.Debugln(string(patch))
}
5 changes: 4 additions & 1 deletion workflow/controller/pod/significant.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package pod

import (
"os"

apiv1 "k8s.io/api/core/v1"
)

func SignificantPodChange(from *apiv1.Pod, to *apiv1.Pod) bool {
return from.Spec.NodeName != to.Spec.NodeName ||
return os.Getenv("ALL_POD_CHANGES_SIGNIFICANT") == "true" ||
from.Spec.NodeName != to.Spec.NodeName ||
from.Status.Phase != to.Status.Phase ||
from.Status.Message != to.Status.Message ||
from.Status.PodIP != to.Status.PodIP ||
Expand Down
11 changes: 9 additions & 2 deletions workflow/controller/pod/significant_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pod

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -9,8 +10,14 @@ import (
)

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

t.Run("NoChange", func(t *testing.T) {
assert.False(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{}))
})
t.Run("ALL_POD_CHANGES_SIGNIFICANT", func(t *testing.T) {
_ = os.Setenv("ALL_POD_CHANGES_SIGNIFICANT", "true")
defer func() { _ = os.Unsetenv("ALL_POD_CHANGES_SIGNIFICANT") }()
assert.True(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{}))
})
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")
Expand Down

0 comments on commit dca3b6c

Please sign in to comment.