mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-22 04:50:23 +00:00
b1a4590967
There is no release for sigs.k8s.io/controller-runtime that supports Kubernetes v1.27. The main branch has all the required modifications, so we can use that for the time being. Signed-off-by: Niels de Vos <ndevos@ibm.com>
93 lines
3.2 KiB
Go
93 lines
3.2 KiB
Go
/*
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package handler
|
|
|
|
import (
|
|
"context"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"k8s.io/client-go/util/workqueue"
|
|
"sigs.k8s.io/controller-runtime/pkg/event"
|
|
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
|
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
|
)
|
|
|
|
var enqueueLog = logf.RuntimeLog.WithName("eventhandler").WithName("EnqueueRequestForObject")
|
|
|
|
type empty struct{}
|
|
|
|
var _ EventHandler = &EnqueueRequestForObject{}
|
|
|
|
// EnqueueRequestForObject enqueues a Request containing the Name and Namespace of the object that is the source of the Event.
|
|
// (e.g. the created / deleted / updated objects Name and Namespace). handler.EnqueueRequestForObject is used by almost all
|
|
// Controllers that have associated Resources (e.g. CRDs) to reconcile the associated Resource.
|
|
type EnqueueRequestForObject struct{}
|
|
|
|
// Create implements EventHandler.
|
|
func (e *EnqueueRequestForObject) Create(ctx context.Context, evt event.CreateEvent, q workqueue.RateLimitingInterface) {
|
|
if evt.Object == nil {
|
|
enqueueLog.Error(nil, "CreateEvent received with no metadata", "event", evt)
|
|
return
|
|
}
|
|
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
|
|
Name: evt.Object.GetName(),
|
|
Namespace: evt.Object.GetNamespace(),
|
|
}})
|
|
}
|
|
|
|
// Update implements EventHandler.
|
|
func (e *EnqueueRequestForObject) Update(ctx context.Context, evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
|
|
switch {
|
|
case evt.ObjectNew != nil:
|
|
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
|
|
Name: evt.ObjectNew.GetName(),
|
|
Namespace: evt.ObjectNew.GetNamespace(),
|
|
}})
|
|
case evt.ObjectOld != nil:
|
|
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
|
|
Name: evt.ObjectOld.GetName(),
|
|
Namespace: evt.ObjectOld.GetNamespace(),
|
|
}})
|
|
default:
|
|
enqueueLog.Error(nil, "UpdateEvent received with no metadata", "event", evt)
|
|
}
|
|
}
|
|
|
|
// Delete implements EventHandler.
|
|
func (e *EnqueueRequestForObject) Delete(ctx context.Context, evt event.DeleteEvent, q workqueue.RateLimitingInterface) {
|
|
if evt.Object == nil {
|
|
enqueueLog.Error(nil, "DeleteEvent received with no metadata", "event", evt)
|
|
return
|
|
}
|
|
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
|
|
Name: evt.Object.GetName(),
|
|
Namespace: evt.Object.GetNamespace(),
|
|
}})
|
|
}
|
|
|
|
// Generic implements EventHandler.
|
|
func (e *EnqueueRequestForObject) Generic(ctx context.Context, evt event.GenericEvent, q workqueue.RateLimitingInterface) {
|
|
if evt.Object == nil {
|
|
enqueueLog.Error(nil, "GenericEvent received with no metadata", "event", evt)
|
|
return
|
|
}
|
|
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
|
|
Name: evt.Object.GetName(),
|
|
Namespace: evt.Object.GetNamespace(),
|
|
}})
|
|
}
|