Skip to content

Commit

Permalink
fix(docker): use version negotiation for the Docker client EE-5797
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-portainer committed Jul 25, 2023
1 parent 2a4e90a commit b9f4916
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
2 changes: 0 additions & 2 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ const (
DefaultEdgeSleepInterval = "5m"
// DefaultConfigCheckInterval is the default interval used to check if node config changed
DefaultConfigCheckInterval = "5s"
// SupportedDockerAPIVersion is the minimum Docker API version supported by the agent.
SupportedDockerAPIVersion = "1.24"
// DefaultClusterProbeTimeout is the default member list ping probe timeout.
DefaultClusterProbeTimeout = "500ms"
// DefaultClusterProbeInterval is the interval for repeating failed node checks.
Expand Down
2 changes: 1 addition & 1 deletion docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func getSwarmConfiguration(config *agent.RuntimeConfiguration, dockerInfo types.
}

func NewClient() (*client.Client, error) {
return client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
return client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
}

func withCli(callback func(cli *client.Client) error) error {
Expand Down
3 changes: 1 addition & 2 deletions docker/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/portainer/agent"
)

func ImageDelete(name string, opts types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions docker/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/portainer/agent"
)

func GetContainersWithLabel(value string) ([]types.Container, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}
Expand All @@ -28,7 +27,7 @@ func GetContainersWithLabel(value string) ([]types.Container, error) {
}

func GetContainerLogs(containerName string, tail string) ([]byte, []byte, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions docker/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"
"time"

"github.com/portainer/agent"
portainer "github.com/portainer/portainer/api"

"github.com/docker/docker/api/types"
Expand All @@ -15,7 +14,7 @@ import (
)

func CreateSnapshot() (*portainer.DockerSnapshot, error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions internals/updates/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/portainer/agent"
)

type DockerUpdaterCleaner struct {
Expand All @@ -22,7 +21,7 @@ func NewDockerUpdaterCleaner(updateID int) *DockerUpdaterCleaner {
}

func (du *DockerUpdaterCleaner) Clean(ctx context.Context) error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(agent.SupportedDockerAPIVersion))
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}
Expand Down

0 comments on commit b9f4916

Please sign in to comment.