Based on the changes, I'll generate a concise commit message that captures the essence of the modifications:

feat: add node registration verification and idle loop for joined nodes
This commit is contained in:
2025-05-17 13:19:16 -04:00
parent 8bdccdc8c7
commit e4a19a6bb8
2 changed files with 107 additions and 2 deletions

View File

@ -46,6 +46,14 @@ and obtains the necessary credentials to participate in the cluster.`,
Run: runJoin,
}
verifyCmd = &cobra.Command{
Use: "verify",
Short: "Verifies node registration in etcd.",
Long: `Connects to etcd and verifies that a node is properly registered.
This is useful for testing and debugging.`,
Run: runVerify,
}
// Global flags / config paths
clusterConfigPath string
nodeName string
@ -55,6 +63,9 @@ and obtains the necessary credentials to participate in the cluster.`,
advertiseAddr string
leaderCACert string
etcdPeer bool
// Verify command flags
etcdEndpoint string
)
const (
@ -84,8 +95,13 @@ func init() {
joinCmd.MarkFlagRequired("leader-api")
joinCmd.MarkFlagRequired("advertise-address")
// Verify command flags
verifyCmd.Flags().StringVar(&etcdEndpoint, "etcd-endpoint", "http://localhost:2379", "Etcd endpoint to connect to")
verifyCmd.Flags().StringVar(&nodeName, "node-name", defaultHostName, "Name of the node to verify")
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(joinCmd)
rootCmd.AddCommand(verifyCmd)
}
func runInit(cmd *cobra.Command, args []string) {
@ -322,8 +338,44 @@ func runJoin(cmd *cobra.Command, args []string) {
}
log.Printf("Successfully joined cluster. Node is ready.")
// In a real implementation, we would start the agent's main loop here
// For now, we'll just exit successfully
// Setup signal handling for graceful shutdown
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
// Stay up in an idle loop until interrupted
log.Printf("Node %s is now running. Press Ctrl+C to exit.", nodeName)
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
log.Println("Received shutdown signal. Exiting...")
return
case <-ticker.C:
log.Printf("Node %s is still running...", nodeName)
}
}
}
func runVerify(cmd *cobra.Command, args []string) {
log.Printf("Verifying node registration for node: %s", nodeName)
log.Printf("Connecting to etcd at: %s", etcdEndpoint)
// Create etcd client
etcdStore, err := store.NewEtcdStore([]string{etcdEndpoint}, nil)
if err != nil {
log.Fatalf("Failed to create etcd store client: %v", err)
}
defer etcdStore.Close()
// Verify node registration
if err := cli.VerifyNodeRegistration(etcdStore, nodeName); err != nil {
log.Fatalf("Failed to verify node registration: %v", err)
}
log.Printf("Node registration verification complete.")
}
func main() {