refactor, fix reload error when using agents, and other small improvements

This commit is contained in:
yusing
2025-02-11 12:15:51 +08:00
parent b1f72620dc
commit 429a77de8e
10 changed files with 139 additions and 105 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"runtime/debug"
"sync"
"github.com/docker/cli/cli/connhelper"
@@ -11,6 +12,7 @@ import (
"github.com/rs/zerolog"
"github.com/yusing/go-proxy/agent/pkg/agent"
"github.com/yusing/go-proxy/internal/common"
config "github.com/yusing/go-proxy/internal/config/types"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/task"
U "github.com/yusing/go-proxy/internal/utils"
@@ -84,9 +86,9 @@ func ConnectClient(host string) (*SharedClient, error) {
var opt []client.Opt
if agent.IsDockerHostAgent(host) {
cfg, ok := agent.GetAgentFromDockerHost(host)
cfg, ok := config.GetInstance().GetAgent(host)
if !ok {
return nil, fmt.Errorf("agent not found for host: %s", host)
return nil, fmt.Errorf("agent %q not found\n%s", host, debug.Stack())
}
opt = []client.Opt{
client.WithHost(agent.DockerHost),

View File

@@ -7,6 +7,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/yusing/go-proxy/agent/pkg/agent"
config "github.com/yusing/go-proxy/internal/config/types"
"github.com/yusing/go-proxy/internal/logging"
U "github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/utils/strutils"
@@ -82,7 +83,11 @@ func FromDocker(c *types.Container, dockerHost string) (res *Container) {
}
if agent.IsDockerHostAgent(dockerHost) {
res.Agent, _ = agent.GetAgentFromDockerHost(dockerHost)
var ok bool
res.Agent, ok = config.GetInstance().GetAgent(dockerHost)
if !ok {
logging.Error().Msgf("agent %q not found", dockerHost)
}
}
res.setPrivateHostname(helper)