beta contoller implanted

This commit is contained in:
2026-04-09 17:50:12 +02:00
parent 29c4e5d674
commit 7bb0698f77
9 changed files with 133 additions and 45 deletions

View File

@@ -17,6 +17,28 @@ import (
"helmet/app/logger"
)
type Proxy interface {
CreateOrUpdateForwarder(ctx context.Context, proto string, lport, dport uint32, addrs ...string) error
DeleteForwarder(ctx context.Context, proto string, lport uint32) error
}
type Dummyproxy struct {
log *logger.Logger
}
func NewDummyproxy() Proxy {
return &Dummyproxy{
log: logger.NewLogger("dummyproxy"),
}
}
func (prox *Dummyproxy) CreateOrUpdateForwarder(ctx context.Context, proto string, lport, dport uint32, addrs ...string) error {
return nil
}
func (prox *Dummyproxy) DeleteForwarder(ctx context.Context, proto string, lport uint32) error {
return nil
}
type Controller struct {
lbaddr string
clientset k8client.Interface
@@ -24,11 +46,13 @@ type Controller struct {
ctx context.Context
cancel context.CancelFunc
log *logger.Logger
proxy Proxy
}
func NewController(clientset k8client.Interface, lbaddr string) *Controller {
func NewController(proxy Proxy, clientset k8client.Interface, lbaddr string) *Controller {
ctx, cancel := context.WithCancel(context.Background())
cont := &Controller{
proxy: proxy,
clientset: clientset,
ctx: ctx,
cancel: cancel,
@@ -40,7 +64,7 @@ func NewController(clientset k8client.Interface, lbaddr string) *Controller {
func (cont *Controller) Run() {
cont.log.Debugf("Start controller")
factory := k8inform.NewSharedInformerFactory(cont.clientset, time.Minute*10)
factory := k8inform.NewSharedInformerFactory(cont.clientset, 10*time.Second)
defer factory.Shutdown()
serviceInformer := factory.Core().V1().Services().Informer()
@@ -57,6 +81,7 @@ func (cont *Controller) Run() {
synced := factory.WaitForCacheSync(ctx.Done())
for _, sync := range synced {
if !sync {
cont.log.Errorf("Cannot sync controller")
return
}
}