Skip to content

Commit 6c15305

Browse files
committed
fix: fixes broken host info for remote hosts. fixes #3103
1 parent c5e3fbc commit 6c15305

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

internal/docker/client.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,20 @@ type httpClient struct {
8282
}
8383

8484
func NewClient(cli DockerCLI, filters filters.Args, host Host) Client {
85-
client := &httpClient{
86-
cli: cli,
87-
filters: filters,
88-
host: host,
89-
}
90-
var err error
91-
client.info, err = cli.Info(context.Background())
85+
86+
info, err := cli.Info(context.Background())
9287
if err != nil {
9388
log.Errorf("unable to get docker info: %v", err)
9489
}
9590

96-
if host.MemTotal == 0 || host.NCPU == 0 {
97-
host.NCPU = client.info.NCPU
98-
host.MemTotal = client.info.MemTotal
99-
}
100-
101-
log.Debugf("Creating a client with host: %+v", host)
91+
host.NCPU = info.NCPU
92+
host.MemTotal = info.MemTotal
10293

103-
return client
94+
return &httpClient{
95+
cli: cli,
96+
filters: filters,
97+
host: host,
98+
}
10499
}
105100

106101
// NewClientWithFilters creates a new instance of Client with docker filters

internal/docker/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Host struct {
2424
}
2525

2626
func (h Host) String() string {
27-
return fmt.Sprintf("ID: %s, Endpoint: %s", h.ID, h.Endpoint)
27+
return fmt.Sprintf("ID: %s, Endpoint: %s, nCPU: %d, memTotal: %d", h.ID, h.Endpoint, h.NCPU, h.MemTotal)
2828
}
2929

3030
func ParseConnection(connection string) (Host, error) {

internal/support/docker/multi_host_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func NewMultiHostService(clients []ClientService) *MultiHostService {
3838
if _, ok := m.clients[client.Host().ID]; ok {
3939
log.Warnf("duplicate host %s found, skipping", client.Host())
4040
continue
41+
} else {
42+
log.Debugf("found a new host %s", client.Host())
4143
}
4244
m.clients[client.Host().ID] = client
4345
}

0 commit comments

Comments
 (0)