Skip to content

Commit

Permalink
fix(controller): Take labels change into account in SignificantPodCha…
Browse files Browse the repository at this point in the history
…nge() (#5253)

Signed-off-by: terrytangyuan <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Mar 2, 2021
1 parent c4bcabd commit 07283cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions workflow/controller/pod/significant.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ func SignificantPodChange(from *apiv1.Pod, to *apiv1.Pod) bool {
from.Status.Message != to.Status.Message ||
from.Status.PodIP != to.Status.PodIP ||
from.GetDeletionTimestamp() != to.GetDeletionTimestamp() ||
significantAnnotationChange(from.Annotations, to.Annotations) ||
significantMetadataChange(from.Annotations, to.Annotations) ||
significantMetadataChange(from.Labels, to.Labels) ||
significantContainerStatusesChange(from.Status.ContainerStatuses, to.Status.ContainerStatuses) ||
significantContainerStatusesChange(from.Status.InitContainerStatuses, to.Status.InitContainerStatuses) ||
significantConditionsChange(from.Status.Conditions, to.Status.Conditions)
}

func significantAnnotationChange(from map[string]string, to map[string]string) bool {
func significantMetadataChange(from map[string]string, to map[string]string) bool {
if len(from) != len(to) {
return true
}
Expand Down
5 changes: 5 additions & 0 deletions workflow/controller/pod/significant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func Test_SgnificantPodChange(t *testing.T) {
assert.True(t, SignificantPodChange(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"foo": "bar"}}}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"foo": "baz"}}}), "changed annotation")
assert.True(t, SignificantPodChange(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"foo": "bar"}}}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}), "deleted annotation")
})
t.Run("Labels", func(t *testing.T) {
assert.True(t, SignificantPodChange(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{}}}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "bar"}}}), "new label")
assert.True(t, SignificantPodChange(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "bar"}}}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "baz"}}}), "changed label")
assert.True(t, SignificantPodChange(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "bar"}}}, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{}}}), "deleted label")
})
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

0 comments on commit 07283cd

Please sign in to comment.