From ea76dbefeb1b006a383b82e8947976d4f3b107e7 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Fri, 3 Oct 2025 08:51:13 -0500 Subject: [PATCH] api/types/swarm: deprecate PortConfigProtocol Signed-off-by: Austin Vazquez --- api/types/swarm/network.go | 15 ++++++++++----- daemon/cluster/convert/network.go | 2 +- daemon/cluster/convert/task.go | 3 ++- .../bridge/iptablesdoc/iptablesdoc_linux_test.go | 2 +- integration/network/overlay/overlay_test.go | 2 +- integration/network/service_test.go | 2 +- .../moby/moby/api/types/swarm/network.go | 15 ++++++++++----- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/api/types/swarm/network.go b/api/types/swarm/network.go index 9f181fb00c..8f43b68209 100644 --- a/api/types/swarm/network.go +++ b/api/types/swarm/network.go @@ -32,7 +32,7 @@ const ( // PortConfig represents the config of a port. type PortConfig struct { Name string `json:",omitempty"` - Protocol PortConfigProtocol `json:",omitempty"` + Protocol network.IPProtocol `json:",omitempty"` // TargetPort is the port inside the container TargetPort uint32 `json:",omitempty"` // PublishedPort is the port on the swarm hosts @@ -55,17 +55,22 @@ const ( ) // PortConfigProtocol represents the protocol of a port. -type PortConfigProtocol string +// +// Deprecated: use [network.IPProtocol] instead. +type PortConfigProtocol = network.IPProtocol const ( // TODO(stevvooe): These should be used generally, not just for PortConfig. // PortConfigProtocolTCP TCP - PortConfigProtocolTCP PortConfigProtocol = "tcp" + // Deprecated: use [network.TCP] instead. + PortConfigProtocolTCP PortConfigProtocol = network.TCP // PortConfigProtocolUDP UDP - PortConfigProtocolUDP PortConfigProtocol = "udp" + // Deprecated: use [network.UDP] instead. + PortConfigProtocolUDP PortConfigProtocol = network.UDP // PortConfigProtocolSCTP SCTP - PortConfigProtocolSCTP PortConfigProtocol = "sctp" + // Deprecated: use [network.SCTP] instead. + PortConfigProtocolSCTP PortConfigProtocol = network.SCTP ) // EndpointVirtualIP represents the virtual ip of a port. diff --git a/daemon/cluster/convert/network.go b/daemon/cluster/convert/network.go index f4fa8563c3..269b54db59 100644 --- a/daemon/cluster/convert/network.go +++ b/daemon/cluster/convert/network.go @@ -144,7 +144,7 @@ func endpointFromGRPC(e *swarmapi.Endpoint) types.Endpoint { func swarmPortConfigToAPIPortConfig(portConfig *swarmapi.PortConfig) types.PortConfig { return types.PortConfig{ Name: portConfig.Name, - Protocol: types.PortConfigProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(portConfig.Protocol)])), + Protocol: network.IPProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(portConfig.Protocol)])), PublishMode: types.PortConfigPublishMode(strings.ToLower(swarmapi.PortConfig_PublishMode_name[int32(portConfig.PublishMode)])), TargetPort: portConfig.TargetPort, PublishedPort: portConfig.PublishedPort, diff --git a/daemon/cluster/convert/task.go b/daemon/cluster/convert/task.go index 03c43b4796..ded09dc9b4 100644 --- a/daemon/cluster/convert/task.go +++ b/daemon/cluster/convert/task.go @@ -4,6 +4,7 @@ import ( "strings" gogotypes "github.com/gogo/protobuf/types" + "github.com/moby/moby/api/types/network" types "github.com/moby/moby/api/types/swarm" swarmapi "github.com/moby/swarmkit/v2/api" ) @@ -75,7 +76,7 @@ func TaskFromGRPC(t swarmapi.Task) (types.Task, error) { for _, p := range t.Status.PortStatus.Ports { task.Status.PortStatus.Ports = append(task.Status.PortStatus.Ports, types.PortConfig{ Name: p.Name, - Protocol: types.PortConfigProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(p.Protocol)])), + Protocol: network.IPProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(p.Protocol)])), PublishMode: types.PortConfigPublishMode(strings.ToLower(swarmapi.PortConfig_PublishMode_name[int32(p.PublishMode)])), TargetPort: p.TargetPort, PublishedPort: p.PublishedPort, diff --git a/integration/network/bridge/iptablesdoc/iptablesdoc_linux_test.go b/integration/network/bridge/iptablesdoc/iptablesdoc_linux_test.go index 87a60a5d78..fafff64427 100644 --- a/integration/network/bridge/iptablesdoc/iptablesdoc_linux_test.go +++ b/integration/network/bridge/iptablesdoc/iptablesdoc_linux_test.go @@ -354,7 +354,7 @@ func createServices(ctx context.Context, t *testing.T, d *daemon.Daemon, section hp, err := strconv.Atoi(hostPort.HostPort) assert.NilError(t, err) portConfig = append(portConfig, swarmtypes.PortConfig{ - Protocol: swarmtypes.PortConfigProtocol(ctrPP.Proto()), + Protocol: ctrPP.Proto(), PublishedPort: uint32(hp), TargetPort: uint32(ctrPP.Num()), }) diff --git a/integration/network/overlay/overlay_test.go b/integration/network/overlay/overlay_test.go index 823dfc898d..9151bcb149 100644 --- a/integration/network/overlay/overlay_test.go +++ b/integration/network/overlay/overlay_test.go @@ -82,7 +82,7 @@ func TestHostPortMappings(t *testing.T) { swarm.ServiceWithNetwork(netName), swarm.ServiceWithEndpoint(&swarmtypes.EndpointSpec{ Ports: []swarmtypes.PortConfig{ - {Protocol: swarmtypes.PortConfigProtocolTCP, TargetPort: 80, PublishedPort: 80, PublishMode: swarmtypes.PortConfigPublishModeHost}, + {Protocol: networktypes.TCP, TargetPort: 80, PublishedPort: 80, PublishMode: swarmtypes.PortConfigPublishModeHost}, }, })) defer apiClient.ServiceRemove(ctx, svcID) diff --git a/integration/network/service_test.go b/integration/network/service_test.go index a6fb9ef164..5a591ee6b2 100644 --- a/integration/network/service_test.go +++ b/integration/network/service_test.go @@ -276,7 +276,7 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) { swarm.ServiceWithEndpoint(&swarmtypes.EndpointSpec{ Ports: []swarmtypes.PortConfig{ { - Protocol: swarmtypes.PortConfigProtocolTCP, + Protocol: networktypes.TCP, TargetPort: 80, PublishMode: swarmtypes.PortConfigPublishModeIngress, }, diff --git a/vendor/github.com/moby/moby/api/types/swarm/network.go b/vendor/github.com/moby/moby/api/types/swarm/network.go index 9f181fb00c..8f43b68209 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/network.go +++ b/vendor/github.com/moby/moby/api/types/swarm/network.go @@ -32,7 +32,7 @@ const ( // PortConfig represents the config of a port. type PortConfig struct { Name string `json:",omitempty"` - Protocol PortConfigProtocol `json:",omitempty"` + Protocol network.IPProtocol `json:",omitempty"` // TargetPort is the port inside the container TargetPort uint32 `json:",omitempty"` // PublishedPort is the port on the swarm hosts @@ -55,17 +55,22 @@ const ( ) // PortConfigProtocol represents the protocol of a port. -type PortConfigProtocol string +// +// Deprecated: use [network.IPProtocol] instead. +type PortConfigProtocol = network.IPProtocol const ( // TODO(stevvooe): These should be used generally, not just for PortConfig. // PortConfigProtocolTCP TCP - PortConfigProtocolTCP PortConfigProtocol = "tcp" + // Deprecated: use [network.TCP] instead. + PortConfigProtocolTCP PortConfigProtocol = network.TCP // PortConfigProtocolUDP UDP - PortConfigProtocolUDP PortConfigProtocol = "udp" + // Deprecated: use [network.UDP] instead. + PortConfigProtocolUDP PortConfigProtocol = network.UDP // PortConfigProtocolSCTP SCTP - PortConfigProtocolSCTP PortConfigProtocol = "sctp" + // Deprecated: use [network.SCTP] instead. + PortConfigProtocolSCTP PortConfigProtocol = network.SCTP ) // EndpointVirtualIP represents the virtual ip of a port.