Skip to content

Commit

Permalink
Rename compareSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
pleshakov committed May 17, 2021
1 parent fda21d7 commit e6cd9fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions internal/k8s/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ func createIngressLinkHandlers(lbc *LoadBalancerController) cache.ResourceEventH
UpdateFunc: func(old, cur interface{}) {
oldLink := old.(*unstructured.Unstructured)
curLink := cur.(*unstructured.Unstructured)
updated, err := compareSpecs(oldLink, curLink)
different, err := areResourcesDifferent(oldLink, curLink)
if err != nil {
glog.V(3).Infof("Error when comparing IngressLinks: %v", err)
lbc.AddSyncQueue(curLink)
}
if updated {
if different {
glog.V(3).Infof("IngressLink %v changed, syncing", oldLink.GetName())
lbc.AddSyncQueue(curLink)
}
Expand All @@ -506,12 +506,12 @@ func createAppProtectPolicyHandlers(lbc *LoadBalancerController) cache.ResourceE
UpdateFunc: func(oldObj, obj interface{}) {
oldPol := oldObj.(*unstructured.Unstructured)
newPol := obj.(*unstructured.Unstructured)
updated, err := compareSpecs(oldPol, newPol)
different, err := areResourcesDifferent(oldPol, newPol)
if err != nil {
glog.V(3).Infof("Error when comparing policy %v", err)
lbc.AddSyncQueue(newPol)
}
if updated {
if different {
glog.V(3).Infof("ApPolicy %v changed, syncing", oldPol.GetName())
lbc.AddSyncQueue(newPol)
}
Expand All @@ -523,8 +523,8 @@ func createAppProtectPolicyHandlers(lbc *LoadBalancerController) cache.ResourceE
return handlers
}

// compareSpecs returns true if the resources are different.
func compareSpecs(oldresource, resource *unstructured.Unstructured) (bool, error) {
// areResourcesDifferent returns true if the resources are different based on their spec.
func areResourcesDifferent(oldresource, resource *unstructured.Unstructured) (bool, error) {
oldSpec, found, err := unstructured.NestedMap(oldresource.Object, "spec")
if !found {
glog.V(3).Infof("Warning, oldspec has unexpected format")
Expand Down Expand Up @@ -556,12 +556,12 @@ func createAppProtectLogConfHandlers(lbc *LoadBalancerController) cache.Resource
UpdateFunc: func(oldObj, obj interface{}) {
oldConf := oldObj.(*unstructured.Unstructured)
newConf := obj.(*unstructured.Unstructured)
updated, err := compareSpecs(oldConf, newConf)
different, err := areResourcesDifferent(oldConf, newConf)
if err != nil {
glog.V(3).Infof("Error when comparing LogConfs %v", err)
lbc.AddSyncQueue(newConf)
}
if updated {
if different {
glog.V(3).Infof("ApLogConf %v changed, syncing", oldConf.GetName())
lbc.AddSyncQueue(newConf)
}
Expand All @@ -583,12 +583,12 @@ func createAppProtectUserSigHandlers(lbc *LoadBalancerController) cache.Resource
UpdateFunc: func(oldObj, obj interface{}) {
oldSig := oldObj.(*unstructured.Unstructured)
newSig := obj.(*unstructured.Unstructured)
updated, err := compareSpecs(oldSig, newSig)
different, err := areResourcesDifferent(oldSig, newSig)
if err != nil {
glog.V(3).Infof("Error when comparing UserSigs %v", err)
lbc.AddSyncQueue(newSig)
}
if updated {
if different {
glog.V(3).Infof("ApUserSig %v changed, syncing", oldSig.GetName())
lbc.AddSyncQueue(newSig)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/k8s/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestHasServicePortChanges(t *testing.T) {
}
}

func TestCompareSpecs(t *testing.T) {
func TestAreResourcesDifferent(t *testing.T) {
tests := []struct {
oldR, newR *unstructured.Unstructured
expected, expectErr bool
Expand Down Expand Up @@ -261,15 +261,15 @@ func TestCompareSpecs(t *testing.T) {
}

for _, test := range tests {
result, err := compareSpecs(test.oldR, test.newR)
result, err := areResourcesDifferent(test.oldR, test.newR)
if result != test.expected {
t.Errorf("compareSpecs() returned %v but expected %v for the case of %s", result, test.expected, test.msg)
t.Errorf("areResourcesDifferent() returned %v but expected %v for the case of %s", result, test.expected, test.msg)
}
if test.expectErr && err == nil {
t.Errorf("compareSpecs() returned no error for the case of %s", test.msg)
t.Errorf("areResourcesDifferent() returned no error for the case of %s", test.msg)
}
if !test.expectErr && err != nil {
t.Errorf("compareSpecs() returned unexpected error %v for the case of %s", err, test.msg)
t.Errorf("areResourcesDifferent() returned unexpected error %v for the case of %s", err, test.msg)
}
}
}

0 comments on commit e6cd9fa

Please sign in to comment.