fix(dependenciesdistributor): reduce update trigger
Signed-off-by: chang.qiangqiang <chang.qiangqiang@immomo.com>
This commit is contained in:
parent
2b88a74123
commit
bfd88d2507
|
@ -22,6 +22,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/equality"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -151,7 +152,9 @@ func (d *DependenciesDistributor) OnUpdate(oldObj, newObj interface{}) {
|
|||
klog.V(4).Infof("Ignore update event of object (%s, kind=%s, %s) as specification no change", unstructuredOldObj.GetAPIVersion(), unstructuredOldObj.GetKind(), names.NamespacedKey(unstructuredOldObj.GetNamespace(), unstructuredOldObj.GetName()))
|
||||
return
|
||||
}
|
||||
if !equality.Semantic.DeepEqual(unstructuredOldObj.GetLabels(), unstructuredNewObj.GetLabels()) {
|
||||
d.OnAdd(oldObj)
|
||||
}
|
||||
d.OnAdd(newObj)
|
||||
}
|
||||
|
||||
|
@ -214,7 +217,6 @@ func matchesWithBindingDependencies(resourceTemplateKey *LabelsKey, independentB
|
|||
independentBinding.Namespace, independentBinding.Name, dependencies, err)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(dependenciesSlice) == 0 {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ func Test_OnUpdate(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
wantQueueSize: 2,
|
||||
wantQueueSize: 1,
|
||||
},
|
||||
{
|
||||
name: "do not update the object, no specification changed",
|
||||
|
@ -140,6 +140,130 @@ func Test_OnUpdate(t *testing.T) {
|
|||
},
|
||||
wantQueueSize: 0,
|
||||
},
|
||||
{
|
||||
name: "no specification changed, labels changed",
|
||||
args: args{
|
||||
oldObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Labels: map[string]string{
|
||||
"app": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Labels: map[string]string{
|
||||
"app": "new-test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantQueueSize: 2,
|
||||
},
|
||||
{
|
||||
name: "specification changed, labels not changed",
|
||||
args: args{
|
||||
oldObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Labels: map[string]string{
|
||||
"app": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"app": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantQueueSize: 1,
|
||||
},
|
||||
{
|
||||
name: "specification changed, more than two elements in labels and not changed",
|
||||
args: args{
|
||||
oldObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Labels: map[string]string{
|
||||
"app": "test",
|
||||
"online": "svc",
|
||||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"online": "svc",
|
||||
"app": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantQueueSize: 1,
|
||||
},
|
||||
{
|
||||
name: "specification changed, more than two elements in labels and changed",
|
||||
args: args{
|
||||
oldObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Labels: map[string]string{
|
||||
"app": "test",
|
||||
"online": "svc",
|
||||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Node{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Node",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Labels: map[string]string{
|
||||
"online": "svc1",
|
||||
"app": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantQueueSize: 2,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue