Files
open-cluster-management/pkg/placement/controllers/scheduling/cluster_event_handler.go
Jian Zhu 7332a585c0 🌱 add a verify rule for golang files import order (#177)
* 🌱 add a verify rule for golang files import order

This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order:
1. standard library modules
2. 3rd party modules
3. modules in OCM org, like the `open-cluster-management.io/api`
4. current project `open-cluster-management.io/ocm` modules

developers can use the `make fmt-imports` to format the import automatically and the `make verify-fmt-imports` to check for any violation.

Signed-off-by: zhujian <jiazhu@redhat.com>

* 🌱 format the go files import

Signed-off-by: zhujian <jiazhu@redhat.com>

---------

Signed-off-by: zhujian <jiazhu@redhat.com>
2023-06-12 10:23:04 -04:00

52 lines
1.1 KiB
Go

package scheduling
import (
"fmt"
"reflect"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
cache "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"))
}
}