more fixes before final part
All checks were successful
Unit Tests / unit-tests (pull_request) Successful in 9m58s
Integration Tests / integration-tests (pull_request) Successful in 9m58s

This commit is contained in:
2025-05-18 11:35:22 -04:00
parent 8f90c1b16d
commit 92fb052594
5 changed files with 51 additions and 45 deletions

View File

@ -11,6 +11,7 @@ import (
"syscall"
"time"
"git.dws.rip/dubey/kat/internal/agent"
"git.dws.rip/dubey/kat/internal/api"
"git.dws.rip/dubey/kat/internal/cli"
"git.dws.rip/dubey/kat/internal/config"
@ -265,7 +266,7 @@ func runInit(cmd *cobra.Command, args []string) {
joinHandler := api.NewJoinHandler(etcdStore, caKeyPath, caCertPath)
apiServer.RegisterJoinHandler(joinHandler)
log.Printf("Registered join handler with CA key: %s, CA cert: %s", caKeyPath, caCertPath)
// Register the node status handler
nodeStatusHandler := api.NewNodeStatusHandler(etcdStore)
apiServer.RegisterNodeStatusHandler(nodeStatusHandler)
@ -343,11 +344,11 @@ func runJoin(cmd *cobra.Command, args []string) {
}
log.Printf("Successfully joined cluster. Node is ready.")
// Setup signal handling for graceful shutdown
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
// Create and start the agent with heartbeating
agent, err := agent.NewAgent(
joinResp.NodeName,
@ -360,19 +361,19 @@ func runJoin(cmd *cobra.Command, args []string) {
if err != nil {
log.Fatalf("Failed to create agent: %v", err)
}
// Setup mTLS client
if err := agent.SetupMTLSClient(); err != nil {
log.Fatalf("Failed to setup mTLS client: %v", err)
}
// Start heartbeating
if err := agent.StartHeartbeat(ctx); err != nil {
log.Fatalf("Failed to start heartbeat: %v", err)
}
log.Printf("Node %s is now running with heartbeat. Press Ctrl+C to exit.", nodeName)
// Wait for shutdown signal
<-ctx.Done()
log.Println("Received shutdown signal. Stopping heartbeat...")