feat: implement serviceadapter informer to watch CRDs in cluster
Build and push / Build and push image (push) Failing after 15s
Build / Build and push image (push) Failing after 15s
CI / Test, vet, build (push) Failing after 28s

This commit is contained in:
Admin Bot
2026-08-26 14:08:39 -07:00
parent 0cdfae2a93
commit 99ca7da1bf
4 changed files with 395 additions and 54 deletions
+27
View File
@@ -9,6 +9,9 @@ import (
"os/signal"
"syscall"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/config"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/proxy"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/server"
@@ -56,6 +59,25 @@ func main() {
registry := serviceadapter.NewRegistry(nil) // nil uses default logger
dispatcher := serviceadapter.NewDispatcher(registry)
// Start ServiceAdapter informer to watch CRDs (8.1 integration)
var informerMgr *serviceadapter.InformerManager
if kubeConfig, err := rest.InClusterConfig(); err == nil {
if dynamicClient, err := dynamic.NewForConfig(kubeConfig); err == nil {
if informer, err := serviceadapter.NewInformerManager(dynamicClient, registry, "api"); err == nil {
informerMgr = informer
if err := informer.Start(context.Background()); err != nil {
log.Printf("warning: failed to start ServiceAdapter informer: %v", err)
}
} else {
log.Printf("warning: failed to create ServiceAdapter informer: %v", err)
}
} else {
log.Printf("warning: failed to create dynamic client: %v", err)
}
} else {
log.Printf("warning: not running in cluster, ServiceAdapter CRDs won't be watched")
}
// Create router that handles health endpoints, X-Service (ServiceAdapter) routing,
// temporal endpoints, and passes others to upstream handler
router := server.NewRouter(healthChecker, dispatcher, temporalHandler, upstreamHandler)
@@ -79,6 +101,11 @@ func main() {
sig := <-sigChan
log.Printf("received signal: %v", sig)
// Stop informer if running
if informerMgr != nil {
informerMgr.Stop()
}
// Gracefully shutdown the server
if err := srv.Shutdown(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, "shutdown error: %v\n", err)