add webhook
This commit is contained in:
39
pkg/svc/handler.go
Normal file
39
pkg/svc/handler.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
var log = ctrl.Log.WithName("handler")
|
||||
|
||||
type EventHandler struct {
|
||||
update chan interface{}
|
||||
}
|
||||
|
||||
func NewHandler() *EventHandler {
|
||||
return &EventHandler{
|
||||
update: make(chan interface{}, 100),
|
||||
}
|
||||
}
|
||||
|
||||
func (ev *EventHandler) Default(ctx context.Context, obj runtime.Object) error {
|
||||
switch obj := obj.(type) {
|
||||
case *corev1.Pod:
|
||||
log.Info("pod create", "namespace", obj.Namespace, "spec", obj.Spec)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ev *EventHandler) Start(ctx context.Context) error {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Info("EventHandler exit")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user