1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

feat: enables swarm cluster to connect to external agents (#3394)

Co-authored-by: Mitch Brown <mitch@mitchbrown.ca>
This commit is contained in:
Amir Raminfar
2024-11-16 15:17:29 -08:00
committed by GitHub
parent 9a296ca504
commit 1144bdfbd2
9 changed files with 103 additions and 30 deletions

24
main.go
View File

@@ -126,6 +126,27 @@ func main() {
if _, err := os.Stdout.Write(buffer.Bytes()); err != nil {
log.Fatal().Err(err).Msg("Failed to write to stdout")
}
case *cli.AgentTestCmd:
certs, err := cli.ReadCertificates(certs)
if err != nil {
log.Fatal().Err(err).Msg("Could not read certificates")
}
log.Info().Str("endpoint", args.AgentTest.Address).Msg("Connecting to agent")
agent, err := agent.NewClient(args.AgentTest.Address, certs)
if err != nil {
log.Fatal().Err(err).Str("endpoint", args.AgentTest.Address).Msg("error connecting to agent")
}
ctx, cancel := context.WithTimeout(context.Background(), args.Timeout)
defer cancel()
host, err := agent.Host(ctx)
if err != nil {
log.Fatal().Err(err).Str("endpoint", args.AgentTest.Address).Msg("error fetching host info for agent")
}
log.Info().Str("endpoint", args.AgentTest.Address).Str("version", host.AgentVersion).Str("name", host.Name).Str("id", host.ID).Msg("Successfully connected to agent")
}
os.Exit(0)
@@ -157,7 +178,8 @@ func main() {
if err != nil {
log.Fatal().Err(err).Msg("Could not read certificates")
}
manager := docker_support.NewSwarmClientManager(localClient, certs, args.Timeout)
agentManager := docker_support.NewRetriableClientManager(args.RemoteAgent, args.Timeout, certs)
manager := docker_support.NewSwarmClientManager(localClient, certs, args.Timeout, agentManager)
multiHostService = docker_support.NewMultiHostService(manager, args.Timeout)
log.Info().Msg("Starting in swarm mode")
listener, err := net.Listen("tcp", ":7007")