Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
Avoid queuing an item that has no relevant changes (#31)
Browse files Browse the repository at this point in the history
* Avoid queuing an item that has no relevant changes

* Minor review

* Fix syntax
  • Loading branch information
andresmgot authored Jun 7, 2018
1 parent 48b8bda commit 7e4b584
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"google.golang.org/grpc"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -66,7 +67,13 @@ func NewController(clientset helmClientset.Interface, kubeClient kubernetes.Inte
UpdateFunc: func(oldObj, newObj interface{}) {
key, err := cache.MetaNamespaceKeyFunc(newObj)
if err == nil {
queue.Add(key)
newReleaseObj := newObj.(*helmCrdV1.HelmRelease)
oldReleaseObj := oldObj.(*helmCrdV1.HelmRelease)
if releaseObjChanged(oldReleaseObj, newReleaseObj) {
queue.Add(key)
} else {
log.Printf("Ignoring update event on unchanged object %v", newReleaseObj)
}
}
},
DeleteFunc: func(obj interface{}) {
Expand Down Expand Up @@ -194,6 +201,14 @@ func removeIndex(i int, s []string) []string {
return s[:lastIdx]
}

func releaseObjChanged(old, new *helmCrdV1.HelmRelease) bool {
// If the object deletion timestamp is set, then process
if old.DeletionTimestamp != new.DeletionTimestamp {
return true
}
return !apiequality.Semantic.DeepEqual(old.Spec, new.Spec)
}

// remove item from slice without keeping order
func remove(item string, s []string) ([]string, error) {
index := findIndex(item, s)
Expand Down

0 comments on commit 7e4b584

Please sign in to comment.