Bump github.com/docker/docker to v28.3.3
This commit is contained in:
parent
fc5359b6f6
commit
5cc2a8344c
8 changed files with 239 additions and 169 deletions
|
|
@ -1,22 +1,21 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
dockertypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
dockercontainertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
|
||||
func containerJSON(ops ...func(*dockertypes.ContainerJSON)) dockertypes.ContainerJSON {
|
||||
c := &dockertypes.ContainerJSON{
|
||||
ContainerJSONBase: &dockertypes.ContainerJSONBase{
|
||||
func containerJSON(ops ...func(*dockercontainertypes.InspectResponse)) dockercontainertypes.InspectResponse {
|
||||
c := &dockercontainertypes.InspectResponse{
|
||||
ContainerJSONBase: &dockercontainertypes.ContainerJSONBase{
|
||||
Name: "fake",
|
||||
HostConfig: &container.HostConfig{},
|
||||
HostConfig: &dockercontainertypes.HostConfig{},
|
||||
},
|
||||
Config: &container.Config{},
|
||||
NetworkSettings: &dockertypes.NetworkSettings{
|
||||
NetworkSettingsBase: dockertypes.NetworkSettingsBase{},
|
||||
Config: &dockercontainertypes.Config{},
|
||||
NetworkSettings: &dockercontainertypes.NetworkSettings{
|
||||
NetworkSettingsBase: dockercontainertypes.NetworkSettingsBase{},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -27,34 +26,26 @@ func containerJSON(ops ...func(*dockertypes.ContainerJSON)) dockertypes.Containe
|
|||
return *c
|
||||
}
|
||||
|
||||
func name(name string) func(*dockertypes.ContainerJSON) {
|
||||
return func(c *dockertypes.ContainerJSON) {
|
||||
func name(name string) func(*dockercontainertypes.InspectResponse) {
|
||||
return func(c *dockercontainertypes.InspectResponse) {
|
||||
c.ContainerJSONBase.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
func networkMode(mode string) func(*dockertypes.ContainerJSON) {
|
||||
return func(c *dockertypes.ContainerJSON) {
|
||||
c.ContainerJSONBase.HostConfig.NetworkMode = container.NetworkMode(mode)
|
||||
func networkMode(mode string) func(*dockercontainertypes.InspectResponse) {
|
||||
return func(c *dockercontainertypes.InspectResponse) {
|
||||
c.ContainerJSONBase.HostConfig.NetworkMode = dockercontainertypes.NetworkMode(mode)
|
||||
}
|
||||
}
|
||||
|
||||
func nodeIP(ip string) func(*dockertypes.ContainerJSON) {
|
||||
return func(c *dockertypes.ContainerJSON) {
|
||||
c.ContainerJSONBase.Node = &dockertypes.ContainerNode{
|
||||
IPAddress: ip,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ports(portMap nat.PortMap) func(*dockertypes.ContainerJSON) {
|
||||
return func(c *dockertypes.ContainerJSON) {
|
||||
func ports(portMap nat.PortMap) func(*dockercontainertypes.InspectResponse) {
|
||||
return func(c *dockercontainertypes.InspectResponse) {
|
||||
c.NetworkSettings.NetworkSettingsBase.Ports = portMap
|
||||
}
|
||||
}
|
||||
|
||||
func withNetwork(name string, ops ...func(*network.EndpointSettings)) func(*dockertypes.ContainerJSON) {
|
||||
return func(c *dockertypes.ContainerJSON) {
|
||||
func withNetwork(name string, ops ...func(*network.EndpointSettings)) func(*dockercontainertypes.InspectResponse) {
|
||||
return func(c *dockercontainertypes.InspectResponse) {
|
||||
if c.NetworkSettings.Networks == nil {
|
||||
c.NetworkSettings.Networks = map[string]*network.EndpointSettings{}
|
||||
}
|
||||
|
|
@ -95,6 +86,12 @@ func taskSlot(slot int) func(*swarm.Task) {
|
|||
}
|
||||
}
|
||||
|
||||
func taskNodeID(id string) func(*swarm.Task) {
|
||||
return func(task *swarm.Task) {
|
||||
task.NodeID = id
|
||||
}
|
||||
}
|
||||
|
||||
func taskNetworkAttachment(id, name, driver string, addresses []string) func(*swarm.Task) {
|
||||
return func(task *swarm.Task) {
|
||||
task.NetworksAttachments = append(task.NetworksAttachments, swarm.NetworkAttachment{
|
||||
|
|
|
|||
|
|
@ -325,8 +325,8 @@ func (p *Provider) getIPAddress(ctx context.Context, container dockerData) strin
|
|||
}
|
||||
|
||||
if container.NetworkSettings.NetworkMode.IsHost() {
|
||||
if container.Node != nil && container.Node.IPAddress != "" {
|
||||
return container.Node.IPAddress
|
||||
if container.NodeIP != "" {
|
||||
return container.NodeIP
|
||||
}
|
||||
if host, err := net.LookupHost("host.docker.internal"); err == nil {
|
||||
return host[0]
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import (
|
|||
"testing"
|
||||
|
||||
docker "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
dockercontainertypes "github.com/docker/docker/api/types/container"
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -3519,7 +3520,7 @@ func TestDockerGetIPPort(t *testing.T) {
|
|||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
container docker.ContainerJSON
|
||||
container dockercontainertypes.InspectResponse
|
||||
serverPort string
|
||||
expected expected
|
||||
}{
|
||||
|
|
@ -3690,7 +3691,7 @@ func TestDockerGetIPPort(t *testing.T) {
|
|||
func TestDockerGetPort(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
container docker.ContainerJSON
|
||||
container dockercontainertypes.InspectResponse
|
||||
serverPort string
|
||||
expected string
|
||||
}{
|
||||
|
|
@ -3755,8 +3756,9 @@ func TestDockerGetPort(t *testing.T) {
|
|||
func TestDockerGetIPAddress(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
container docker.ContainerJSON
|
||||
container dockercontainertypes.InspectResponse
|
||||
network string
|
||||
nodeIP string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
|
|
@ -3832,10 +3834,10 @@ func TestDockerGetIPAddress(t *testing.T) {
|
|||
expected: "127.0.0.1",
|
||||
},
|
||||
{
|
||||
desc: "no network, no network label, mode host, node IP",
|
||||
desc: "no network, no network label, mode host, node IP",
|
||||
nodeIP: "10.0.0.5",
|
||||
container: containerJSON(
|
||||
networkMode("host"),
|
||||
nodeIP("10.0.0.5"),
|
||||
),
|
||||
expected: "10.0.0.5",
|
||||
},
|
||||
|
|
@ -3850,9 +3852,12 @@ func TestDockerGetIPAddress(t *testing.T) {
|
|||
}
|
||||
|
||||
dData := parseContainer(test.container)
|
||||
if test.nodeIP != "" {
|
||||
dData.NodeIP = test.nodeIP
|
||||
}
|
||||
|
||||
dData.ExtraConf.Docker.Network = provider.Network
|
||||
if len(test.network) > 0 {
|
||||
if test.network != "" {
|
||||
dData.ExtraConf.Docker.Network = test.network
|
||||
}
|
||||
|
||||
|
|
@ -3864,14 +3869,14 @@ func TestDockerGetIPAddress(t *testing.T) {
|
|||
|
||||
func TestSwarmGetIPAddress(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
service swarmtypes.Service
|
||||
expected string
|
||||
networks map[string]*network.Summary
|
||||
networks map[string]*networktypes.Summary
|
||||
}{
|
||||
{
|
||||
service: swarmService(withEndpointSpec(modeDNSRR)),
|
||||
expected: "",
|
||||
networks: map[string]*network.Summary{},
|
||||
networks: map[string]*networktypes.Summary{},
|
||||
},
|
||||
{
|
||||
service: swarmService(
|
||||
|
|
@ -3879,7 +3884,7 @@ func TestSwarmGetIPAddress(t *testing.T) {
|
|||
withEndpoint(virtualIP("1", "10.11.12.13/24")),
|
||||
),
|
||||
expected: "10.11.12.13",
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foo",
|
||||
},
|
||||
|
|
@ -3897,7 +3902,7 @@ func TestSwarmGetIPAddress(t *testing.T) {
|
|||
),
|
||||
),
|
||||
expected: "10.11.12.99",
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foonet",
|
||||
},
|
||||
|
|
@ -3927,16 +3932,16 @@ func TestSwarmGetIPAddress(t *testing.T) {
|
|||
|
||||
func TestSwarmGetPort(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
service swarmtypes.Service
|
||||
serverPort string
|
||||
networks map[string]*network.Summary
|
||||
networks map[string]*networktypes.Summary
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
service: swarmService(
|
||||
withEndpointSpec(modeDNSRR),
|
||||
),
|
||||
networks: map[string]*network.Summary{},
|
||||
networks: map[string]*networktypes.Summary{},
|
||||
serverPort: "8080",
|
||||
expected: "8080",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/docker/cli/cli/connhelper"
|
||||
dockertypes "github.com/docker/docker/api/types"
|
||||
dockercontainertypes "github.com/docker/docker/api/types/container"
|
||||
eventtypes "github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
|
@ -93,7 +92,7 @@ type dockerData struct {
|
|||
Labels map[string]string // List of labels set to container or service
|
||||
NetworkSettings networkSettings
|
||||
Health string
|
||||
Node *dockertypes.ContainerNode
|
||||
NodeIP string // Only filled in Swarm mode.
|
||||
ExtraConf configuration
|
||||
}
|
||||
|
||||
|
|
@ -381,7 +380,7 @@ func inspectContainers(ctx context.Context, dockerClient client.ContainerAPIClie
|
|||
return dockerData{}
|
||||
}
|
||||
|
||||
func parseContainer(container dockertypes.ContainerJSON) dockerData {
|
||||
func parseContainer(container dockercontainertypes.InspectResponse) dockerData {
|
||||
dData := dockerData{
|
||||
NetworkSettings: networkSettings{},
|
||||
}
|
||||
|
|
@ -390,7 +389,6 @@ func parseContainer(container dockertypes.ContainerJSON) dockerData {
|
|||
dData.ID = container.ContainerJSONBase.ID
|
||||
dData.Name = container.ContainerJSONBase.Name
|
||||
dData.ServiceName = dData.Name // Default ServiceName to be the container's Name.
|
||||
dData.Node = container.ContainerJSONBase.Node
|
||||
|
||||
if container.ContainerJSONBase.HostConfig != nil {
|
||||
dData.NetworkSettings.NetworkMode = container.ContainerJSONBase.HostConfig.NetworkMode
|
||||
|
|
@ -431,7 +429,7 @@ func parseContainer(container dockertypes.ContainerJSON) dockerData {
|
|||
func (p *Provider) listServices(ctx context.Context, dockerClient client.APIClient) ([]dockerData, error) {
|
||||
logger := log.FromContext(ctx)
|
||||
|
||||
serviceList, err := dockerClient.ServiceList(ctx, dockertypes.ServiceListOptions{})
|
||||
serviceList, err := dockerClient.ServiceList(ctx, swarmtypes.ServiceListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -542,7 +540,7 @@ func listTasks(ctx context.Context, dockerClient client.APIClient, serviceID str
|
|||
serviceIDFilter.Add("service", serviceID)
|
||||
serviceIDFilter.Add("desired-state", "running")
|
||||
|
||||
taskList, err := dockerClient.TaskList(ctx, dockertypes.TaskListOptions{Filters: serviceIDFilter})
|
||||
taskList, err := dockerClient.TaskList(ctx, swarmtypes.TaskListOptions{Filters: serviceIDFilter})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -552,7 +550,13 @@ func listTasks(ctx context.Context, dockerClient client.APIClient, serviceID str
|
|||
if task.Status.State != swarmtypes.TaskStateRunning {
|
||||
continue
|
||||
}
|
||||
dData := parseTasks(ctx, task, serviceDockerData, networkMap, isGlobalSvc)
|
||||
|
||||
dData, err := parseTasks(ctx, dockerClient, task, serviceDockerData, networkMap, isGlobalSvc)
|
||||
if err != nil {
|
||||
log.FromContext(ctx).Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(dData.NetworkSettings.Networks) > 0 {
|
||||
dockerDataList = append(dockerDataList, dData)
|
||||
}
|
||||
|
|
@ -560,9 +564,9 @@ func listTasks(ctx context.Context, dockerClient client.APIClient, serviceID str
|
|||
return dockerDataList, err
|
||||
}
|
||||
|
||||
func parseTasks(ctx context.Context, task swarmtypes.Task, serviceDockerData dockerData,
|
||||
func parseTasks(ctx context.Context, dockerClient client.APIClient, task swarmtypes.Task, serviceDockerData dockerData,
|
||||
networkMap map[string]*networktypes.Summary, isGlobalSvc bool,
|
||||
) dockerData {
|
||||
) (dockerData, error) {
|
||||
dData := dockerData{
|
||||
ID: task.ID,
|
||||
ServiceName: serviceDockerData.Name,
|
||||
|
|
@ -576,6 +580,14 @@ func parseTasks(ctx context.Context, task swarmtypes.Task, serviceDockerData doc
|
|||
dData.Name = serviceDockerData.Name + "." + task.ID
|
||||
}
|
||||
|
||||
if task.NodeID != "" {
|
||||
node, _, err := dockerClient.NodeInspectWithRaw(ctx, task.NodeID)
|
||||
if err != nil {
|
||||
return dockerData{}, fmt.Errorf("inspecting node %s: %w", task.NodeID, err)
|
||||
}
|
||||
dData.NodeIP = node.Status.Addr
|
||||
}
|
||||
|
||||
if task.NetworksAttachments != nil {
|
||||
dData.NetworkSettings.Networks = make(map[string]*networkData)
|
||||
for _, virtualIP := range task.NetworksAttachments {
|
||||
|
|
@ -597,5 +609,5 @@ func parseTasks(ctx context.Context, task swarmtypes.Task, serviceDockerData doc
|
|||
}
|
||||
}
|
||||
}
|
||||
return dData
|
||||
return dData, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import (
|
|||
"time"
|
||||
|
||||
dockertypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
dockercontainertypes "github.com/docker/docker/api/types/container"
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -16,39 +17,39 @@ import (
|
|||
|
||||
type fakeTasksClient struct {
|
||||
dockerclient.APIClient
|
||||
tasks []swarm.Task
|
||||
container dockertypes.ContainerJSON
|
||||
tasks []swarmtypes.Task
|
||||
container dockercontainertypes.InspectResponse
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *fakeTasksClient) TaskList(ctx context.Context, options dockertypes.TaskListOptions) ([]swarm.Task, error) {
|
||||
func (c *fakeTasksClient) TaskList(ctx context.Context, options swarmtypes.TaskListOptions) ([]swarmtypes.Task, error) {
|
||||
return c.tasks, c.err
|
||||
}
|
||||
|
||||
func (c *fakeTasksClient) ContainerInspect(ctx context.Context, container string) (dockertypes.ContainerJSON, error) {
|
||||
func (c *fakeTasksClient) ContainerInspect(ctx context.Context, container string) (dockercontainertypes.InspectResponse, error) {
|
||||
return c.container, c.err
|
||||
}
|
||||
|
||||
func TestListTasks(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
tasks []swarm.Task
|
||||
service swarmtypes.Service
|
||||
tasks []swarmtypes.Task
|
||||
isGlobalSVC bool
|
||||
expectedTasks []string
|
||||
networks map[string]*network.Summary
|
||||
networks map[string]*networktypes.Summary
|
||||
}{
|
||||
{
|
||||
service: swarmService(serviceName("container")),
|
||||
tasks: []swarm.Task{
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask("id1",
|
||||
taskSlot(1),
|
||||
taskNetworkAttachment("1", "network1", "overlay", []string{"127.0.0.1"}),
|
||||
taskStatus(taskState(swarm.TaskStateRunning)),
|
||||
taskStatus(taskState(swarmtypes.TaskStateRunning)),
|
||||
),
|
||||
swarmTask("id2",
|
||||
taskSlot(2),
|
||||
taskNetworkAttachment("1", "network1", "overlay", []string{"127.0.0.2"}),
|
||||
taskStatus(taskState(swarm.TaskStatePending)),
|
||||
taskStatus(taskState(swarmtypes.TaskStatePending)),
|
||||
),
|
||||
swarmTask("id3",
|
||||
taskSlot(3),
|
||||
|
|
@ -57,12 +58,12 @@ func TestListTasks(t *testing.T) {
|
|||
swarmTask("id4",
|
||||
taskSlot(4),
|
||||
taskNetworkAttachment("1", "network1", "overlay", []string{"127.0.0.4"}),
|
||||
taskStatus(taskState(swarm.TaskStateRunning)),
|
||||
taskStatus(taskState(swarmtypes.TaskStateRunning)),
|
||||
),
|
||||
swarmTask("id5",
|
||||
taskSlot(5),
|
||||
taskNetworkAttachment("1", "network1", "overlay", []string{"127.0.0.5"}),
|
||||
taskStatus(taskState(swarm.TaskStateFailed)),
|
||||
taskStatus(taskState(swarmtypes.TaskStateFailed)),
|
||||
),
|
||||
},
|
||||
isGlobalSVC: false,
|
||||
|
|
@ -70,7 +71,7 @@ func TestListTasks(t *testing.T) {
|
|||
"container.1",
|
||||
"container.4",
|
||||
},
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foo",
|
||||
},
|
||||
|
|
@ -105,13 +106,23 @@ func TestListTasks(t *testing.T) {
|
|||
type fakeServicesClient struct {
|
||||
dockerclient.APIClient
|
||||
dockerVersion string
|
||||
networks []network.Summary
|
||||
services []swarm.Service
|
||||
tasks []swarm.Task
|
||||
networks []networktypes.Summary
|
||||
nodes []swarmtypes.Node
|
||||
services []swarmtypes.Service
|
||||
tasks []swarmtypes.Task
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *fakeServicesClient) ServiceList(ctx context.Context, options dockertypes.ServiceListOptions) ([]swarm.Service, error) {
|
||||
func (c *fakeServicesClient) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarmtypes.Node, []byte, error) {
|
||||
for _, node := range c.nodes {
|
||||
if node.ID == nodeID {
|
||||
return node, nil, nil
|
||||
}
|
||||
}
|
||||
return swarmtypes.Node{}, nil, c.err
|
||||
}
|
||||
|
||||
func (c *fakeServicesClient) ServiceList(ctx context.Context, options swarmtypes.ServiceListOptions) ([]swarmtypes.Service, error) {
|
||||
return c.services, c.err
|
||||
}
|
||||
|
||||
|
|
@ -119,26 +130,26 @@ func (c *fakeServicesClient) ServerVersion(ctx context.Context) (dockertypes.Ver
|
|||
return dockertypes.Version{APIVersion: c.dockerVersion}, c.err
|
||||
}
|
||||
|
||||
func (c *fakeServicesClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
||||
func (c *fakeServicesClient) NetworkList(ctx context.Context, options networktypes.ListOptions) ([]networktypes.Summary, error) {
|
||||
return c.networks, c.err
|
||||
}
|
||||
|
||||
func (c *fakeServicesClient) TaskList(ctx context.Context, options dockertypes.TaskListOptions) ([]swarm.Task, error) {
|
||||
func (c *fakeServicesClient) TaskList(ctx context.Context, options swarmtypes.TaskListOptions) ([]swarmtypes.Task, error) {
|
||||
return c.tasks, c.err
|
||||
}
|
||||
|
||||
func TestListServices(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
services []swarm.Service
|
||||
tasks []swarm.Task
|
||||
services []swarmtypes.Service
|
||||
tasks []swarmtypes.Task
|
||||
dockerVersion string
|
||||
networks []network.Summary
|
||||
networks []networktypes.Summary
|
||||
expectedServices []string
|
||||
}{
|
||||
{
|
||||
desc: "Should return no service due to no networks defined",
|
||||
services: []swarm.Service{
|
||||
services: []swarmtypes.Service{
|
||||
swarmService(
|
||||
serviceName("service1"),
|
||||
serviceLabels(map[string]string{
|
||||
|
|
@ -159,12 +170,12 @@ func TestListServices(t *testing.T) {
|
|||
withEndpointSpec(modeDNSRR)),
|
||||
},
|
||||
dockerVersion: "1.30",
|
||||
networks: []network.Summary{},
|
||||
networks: []networktypes.Summary{},
|
||||
expectedServices: []string{},
|
||||
},
|
||||
{
|
||||
desc: "Should return only service1",
|
||||
services: []swarm.Service{
|
||||
services: []swarmtypes.Service{
|
||||
swarmService(
|
||||
serviceName("service1"),
|
||||
serviceLabels(map[string]string{
|
||||
|
|
@ -185,7 +196,7 @@ func TestListServices(t *testing.T) {
|
|||
withEndpointSpec(modeDNSRR)),
|
||||
},
|
||||
dockerVersion: "1.30",
|
||||
networks: []network.Summary{
|
||||
networks: []networktypes.Summary{
|
||||
{
|
||||
Name: "network_name",
|
||||
ID: "yk6l57rfwizjzxxzftn4amaot",
|
||||
|
|
@ -197,8 +208,8 @@ func TestListServices(t *testing.T) {
|
|||
Ingress: false,
|
||||
ConfigOnly: false,
|
||||
Options: map[string]string{
|
||||
"com.docker.network.driver.overlay.vxlanid_list": "4098",
|
||||
"com.docker.network.enable_ipv6": "false",
|
||||
"com.docker.networktypes.driver.overlay.vxlanid_list": "4098",
|
||||
"com.docker.networktypes.enable_ipv6": "false",
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"com.docker.stack.namespace": "test",
|
||||
|
|
@ -211,7 +222,7 @@ func TestListServices(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Should return service1 and service2",
|
||||
services: []swarm.Service{
|
||||
services: []swarmtypes.Service{
|
||||
swarmService(
|
||||
serviceName("service1"),
|
||||
serviceLabels(map[string]string{
|
||||
|
|
@ -229,18 +240,18 @@ func TestListServices(t *testing.T) {
|
|||
}),
|
||||
withEndpointSpec(modeDNSRR)),
|
||||
},
|
||||
tasks: []swarm.Task{
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask("id1",
|
||||
taskNetworkAttachment("yk6l57rfwizjzxxzftn4amaot", "network_name", "overlay", []string{"127.0.0.1"}),
|
||||
taskStatus(taskState(swarm.TaskStateRunning)),
|
||||
taskStatus(taskState(swarmtypes.TaskStateRunning)),
|
||||
),
|
||||
swarmTask("id2",
|
||||
taskNetworkAttachment("yk6l57rfwizjzxxzftn4amaot", "network_name", "overlay", []string{"127.0.0.1"}),
|
||||
taskStatus(taskState(swarm.TaskStateRunning)),
|
||||
taskStatus(taskState(swarmtypes.TaskStateRunning)),
|
||||
),
|
||||
},
|
||||
dockerVersion: "1.30",
|
||||
networks: []network.Summary{
|
||||
networks: []networktypes.Summary{
|
||||
{
|
||||
Name: "network_name",
|
||||
ID: "yk6l57rfwizjzxxzftn4amaot",
|
||||
|
|
@ -252,8 +263,8 @@ func TestListServices(t *testing.T) {
|
|||
Ingress: false,
|
||||
ConfigOnly: false,
|
||||
Options: map[string]string{
|
||||
"com.docker.network.driver.overlay.vxlanid_list": "4098",
|
||||
"com.docker.network.enable_ipv6": "false",
|
||||
"com.docker.networktypes.driver.overlay.vxlanid_list": "4098",
|
||||
"com.docker.networktypes.enable_ipv6": "false",
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"com.docker.stack.namespace": "test",
|
||||
|
|
@ -293,15 +304,16 @@ func TestListServices(t *testing.T) {
|
|||
|
||||
func TestSwarmTaskParsing(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
tasks []swarm.Task
|
||||
service swarmtypes.Service
|
||||
tasks []swarmtypes.Task
|
||||
nodes []swarmtypes.Node
|
||||
isGlobalSVC bool
|
||||
expected map[string]dockerData
|
||||
networks map[string]*network.Summary
|
||||
networks map[string]*networktypes.Summary
|
||||
}{
|
||||
{
|
||||
service: swarmService(serviceName("container")),
|
||||
tasks: []swarm.Task{
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask("id1", taskSlot(1)),
|
||||
swarmTask("id2", taskSlot(2)),
|
||||
swarmTask("id3", taskSlot(3)),
|
||||
|
|
@ -318,7 +330,7 @@ func TestSwarmTaskParsing(t *testing.T) {
|
|||
Name: "container.3",
|
||||
},
|
||||
},
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foo",
|
||||
},
|
||||
|
|
@ -326,7 +338,7 @@ func TestSwarmTaskParsing(t *testing.T) {
|
|||
},
|
||||
{
|
||||
service: swarmService(serviceName("container")),
|
||||
tasks: []swarm.Task{
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask("id1"),
|
||||
swarmTask("id2"),
|
||||
swarmTask("id3"),
|
||||
|
|
@ -343,7 +355,7 @@ func TestSwarmTaskParsing(t *testing.T) {
|
|||
Name: "container.id3",
|
||||
},
|
||||
},
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foo",
|
||||
},
|
||||
|
|
@ -357,12 +369,12 @@ func TestSwarmTaskParsing(t *testing.T) {
|
|||
virtualIP("1", ""),
|
||||
),
|
||||
),
|
||||
tasks: []swarm.Task{
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask(
|
||||
"id1",
|
||||
taskNetworkAttachment("1", "vlan", "macvlan", []string{"127.0.0.1"}),
|
||||
taskStatus(
|
||||
taskState(swarm.TaskStateRunning),
|
||||
taskState(swarmtypes.TaskStateRunning),
|
||||
taskContainerStatus("c1"),
|
||||
),
|
||||
),
|
||||
|
|
@ -381,25 +393,56 @@ func TestSwarmTaskParsing(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
networks: map[string]*network.Summary{
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "vlan",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceName("container")),
|
||||
tasks: []swarmtypes.Task{
|
||||
swarmTask("id1",
|
||||
taskSlot(1),
|
||||
taskNodeID("id1"),
|
||||
),
|
||||
},
|
||||
nodes: []swarmtypes.Node{
|
||||
{
|
||||
Status: swarmtypes.NodeStatus{
|
||||
Addr: "10.11.12.13",
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: map[string]dockerData{
|
||||
"id1": {
|
||||
Name: "container.1",
|
||||
NodeIP: "10.11.12.13",
|
||||
},
|
||||
},
|
||||
networks: map[string]*networktypes.Summary{
|
||||
"1": {
|
||||
Name: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for caseID, test := range testCases {
|
||||
t.Run(strconv.Itoa(caseID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
p := Provider{}
|
||||
var p Provider
|
||||
|
||||
dData, err := p.parseService(t.Context(), test.service, test.networks)
|
||||
require.NoError(t, err)
|
||||
|
||||
dockerClient := &fakeServicesClient{tasks: test.tasks}
|
||||
|
||||
for _, task := range test.tasks {
|
||||
taskDockerData := parseTasks(t.Context(), task, dData, test.networks, test.isGlobalSVC)
|
||||
taskDockerData, err := parseTasks(t.Context(), dockerClient, task, dData, test.networks, test.isGlobalSVC)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := test.expected[task.ID]
|
||||
assert.Equal(t, expected.Name, taskDockerData.Name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue