api/types/network: use netip types as appropriate

And generate the ServiceInfo struct from the Swagger spec.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider
2025-09-10 12:38:57 -04:00
committed by Sebastiaan van Stijn
parent ef31514a9f
commit a90adb6dc1
61 changed files with 782 additions and 503 deletions

View File

@@ -2455,6 +2455,10 @@ definitions:
VIP:
type: "string"
x-omitempty: false
x-go-type:
type: Addr
import:
package: net/netip
Ports:
type: "array"
x-omitempty: false
@@ -2464,6 +2468,8 @@ definitions:
type: "integer"
format: "int"
x-omitempty: false
x-go-type:
type: int
Tasks:
type: "array"
x-omitempty: false
@@ -2487,6 +2493,10 @@ definitions:
EndpointIP:
type: "string"
x-omitempty: false
x-go-type:
type: Addr
import:
package: net/netip
Info:
type: "object"
x-omitempty: false
@@ -2617,10 +2627,18 @@ definitions:
type: "string"
x-omitempty: false
example: "172.19.0.2/16"
x-go-type:
type: Prefix
import:
package: net/netip
IPv6Address:
type: "string"
x-omitempty: false
example: ""
x-go-type:
type: Prefix
import:
package: net/netip
PeerInfo:
description: >
@@ -2640,6 +2658,10 @@ definitions:
type: "string"
x-omitempty: false
example: "10.133.77.91"
x-go-type:
type: Addr
import:
package: net/netip
NetworkCreateResponse:
description: "OK response to NetworkCreate operation"
@@ -2910,6 +2932,10 @@ definitions:
IPv4 address.
type: "string"
example: "172.17.0.4"
x-go-type:
type: Addr
import:
package: net/netip
IPPrefixLen:
description: |
Mask length of the IPv4 address.
@@ -2920,11 +2946,19 @@ definitions:
IPv6 gateway address.
type: "string"
example: "2001:db8:2::100"
x-go-type:
type: Addr
import:
package: net/netip
GlobalIPv6Address:
description: |
Global IPv6 address.
type: "string"
example: "2001:db8::5689"
x-go-type:
type: Addr
import:
package: net/netip
GlobalIPv6PrefixLen:
description: |
Mask length of the global IPv6 address.
@@ -2956,13 +2990,25 @@ definitions:
IPv4Address:
type: "string"
example: "172.20.30.33"
x-go-type:
type: Addr
import:
package: net/netip
IPv6Address:
type: "string"
example: "2001:db8:abcd::3033"
x-go-type:
type: Addr
import:
package: net/netip
LinkLocalIPs:
type: "array"
items:
type: "string"
x-go-type:
type: Addr
import:
package: net/netip
example:
- "169.254.34.68"
- "fe80::3468"

View File

@@ -2,6 +2,7 @@ package network
import (
"maps"
"net/netip"
"slices"
)
@@ -25,11 +26,11 @@ type EndpointSettings struct {
// Operational data
NetworkID string
EndpointID string
Gateway string
IPAddress string
Gateway netip.Addr
IPAddress netip.Addr
IPPrefixLen int
IPv6Gateway string
GlobalIPv6Address string
IPv6Gateway netip.Addr
GlobalIPv6Address netip.Addr
GlobalIPv6PrefixLen int
// DNSNames holds all the (non fully qualified) DNS names associated to this endpoint. First entry is used to
// generate PTR records.
@@ -54,9 +55,9 @@ func (es *EndpointSettings) Copy() *EndpointSettings {
// EndpointIPAMConfig represents IPAM configurations for the endpoint
type EndpointIPAMConfig struct {
IPv4Address string `json:",omitempty"`
IPv6Address string `json:",omitempty"`
LinkLocalIPs []string `json:",omitempty"`
IPv4Address netip.Addr `json:",omitempty"`
IPv6Address netip.Addr `json:",omitempty"`
LinkLocalIPs []netip.Addr `json:",omitempty"`
}
// Copy makes a copy of the endpoint ipam config

View File

@@ -5,6 +5,10 @@ package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/netip"
)
// EndpointResource contains network resources allocated and used for a container in a network.
//
// swagger:model EndpointResource
@@ -24,8 +28,8 @@ type EndpointResource struct {
// IPv4 address
// Example: 172.19.0.2/16
IPv4Address string `json:"IPv4Address"`
IPv4Address netip.Prefix `json:"IPv4Address"`
// IPv6 address
IPv6Address string `json:"IPv6Address"`
IPv6Address netip.Prefix `json:"IPv6Address"`
}

View File

@@ -13,10 +13,10 @@ type IPAM struct {
// IPAMConfig represents IPAM configurations
type IPAMConfig struct {
Subnet string `json:",omitempty"`
IPRange string `json:",omitempty"`
Gateway string `json:",omitempty"`
AuxAddress map[string]string `json:"AuxiliaryAddresses,omitempty"`
Subnet netip.Prefix `json:",omitempty"`
IPRange netip.Prefix `json:",omitempty"`
Gateway netip.Addr `json:",omitempty"`
AuxAddress map[string]netip.Addr `json:"AuxiliaryAddresses,omitempty"`
}
type SubnetStatuses = map[netip.Prefix]SubnetStatus

View File

@@ -30,14 +30,6 @@ type CreateRequest struct {
Labels map[string]string // Labels holds metadata specific to the network being created.
}
// ServiceInfo represents service parameters with the list of service's tasks
type ServiceInfo struct {
VIP string
Ports []string
LocalLBIndex int
Tasks []Task
}
// NetworkingConfig represents the container's networking configuration for each of its interfaces
// Carries the networking configs specified in the `docker run` and `docker network connect` commands
type NetworkingConfig struct {

View File

@@ -5,6 +5,10 @@ package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/netip"
)
// PeerInfo represents one peer of an overlay network.
//
// swagger:model PeerInfo
@@ -16,5 +20,5 @@ type PeerInfo struct {
// IP-address of the peer-node in the Swarm cluster.
// Example: 10.133.77.91
IP string `json:"IP"`
IP netip.Addr `json:"IP"`
}

View File

@@ -0,0 +1,28 @@
// Code generated by go-swagger; DO NOT EDIT.
package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/netip"
)
// ServiceInfo represents service parameters with the list of service's tasks
//
// swagger:model ServiceInfo
type ServiceInfo struct {
// v IP
VIP netip.Addr `json:"VIP"`
// ports
Ports []string `json:"Ports"`
// local l b index
LocalLBIndex int `json:"LocalLBIndex"`
// tasks
Tasks []Task `json:"Tasks"`
}

View File

@@ -5,6 +5,10 @@ package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/netip"
)
// Task carries the information about one backend task
//
// swagger:model Task
@@ -17,7 +21,7 @@ type Task struct {
EndpointID string `json:"EndpointID"`
// endpoint IP
EndpointIP string `json:"EndpointIP"`
EndpointIP netip.Addr `json:"EndpointIP"`
// info
Info map[string]string `json:"Info"`