1
0

add webhook

This commit is contained in:
2023-09-06 17:52:39 +08:00
parent 586abdfd7b
commit b2972195cb
12 changed files with 882 additions and 12 deletions

39
pkg/svc/handler.go Normal file
View 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
}
}
}