mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 10:00:11 +00:00
* Refactor code to fix lint warning Signed-off-by: Jian Qiu <jqiu@redhat.com> * enable lint for testing files Signed-off-by: Jian Qiu <jqiu@redhat.com> --------- Signed-off-by: Jian Qiu <jqiu@redhat.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package scheduling
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
"k8s.io/client-go/tools/cache"
|
|
|
|
clusterapiv1 "open-cluster-management.io/api/cluster/v1"
|
|
)
|
|
|
|
type clusterEventHandler struct {
|
|
enqueuer *enqueuer
|
|
}
|
|
|
|
func (h *clusterEventHandler) OnAdd(obj interface{}, isInInitialList bool) {
|
|
h.enqueuer.enqueueCluster(obj)
|
|
}
|
|
|
|
func (h *clusterEventHandler) OnUpdate(oldObj, newObj interface{}) {
|
|
newCluster, ok := newObj.(*clusterapiv1.ManagedCluster)
|
|
if !ok {
|
|
return
|
|
}
|
|
h.enqueuer.enqueueCluster(newObj)
|
|
|
|
if oldObj == nil {
|
|
return
|
|
}
|
|
oldCluster, ok := oldObj.(*clusterapiv1.ManagedCluster)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
// if the cluster labels changes, process the original clusterset
|
|
if !reflect.DeepEqual(newCluster.Labels, oldCluster.Labels) {
|
|
h.enqueuer.enqueueCluster(oldCluster)
|
|
}
|
|
}
|
|
|
|
func (h *clusterEventHandler) OnDelete(obj interface{}) {
|
|
switch t := obj.(type) {
|
|
case *clusterapiv1.ManagedCluster:
|
|
h.enqueuer.enqueueCluster(obj)
|
|
case cache.DeletedFinalStateUnknown:
|
|
h.enqueuer.enqueueCluster(t.Obj)
|
|
default:
|
|
utilruntime.HandleError(fmt.Errorf("error decoding object, invalid type"))
|
|
}
|
|
}
|