40 lines
708 B
Go
40 lines
708 B
Go
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
|
|
}
|
|
}
|
|
}
|