Global Default Address Pool feature support
This feature brings new attribute/option for swarm init command. default-addr-pool will take string input which can be in below format. "CIDR,CIDR,CIDR...:SUBNET-SIZE". Signed-off-by: selansen <elango.siva@docker.com>
This commit is contained in:
@ -3,6 +3,7 @@ package swarm
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
@ -17,10 +18,12 @@ type initOptions struct {
|
||||
swarmOptions
|
||||
listenAddr NodeAddrOption
|
||||
// Not a NodeAddrOption because it has no default port.
|
||||
advertiseAddr string
|
||||
dataPathAddr string
|
||||
forceNewCluster bool
|
||||
availability string
|
||||
advertiseAddr string
|
||||
dataPathAddr string
|
||||
forceNewCluster bool
|
||||
availability string
|
||||
defaultAddrPools []net.IPNet
|
||||
DefaultAddrPoolMaskLength uint32
|
||||
}
|
||||
|
||||
func newInitCommand(dockerCli command.Cli) *cobra.Command {
|
||||
@ -45,21 +48,32 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command {
|
||||
flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state")
|
||||
flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)")
|
||||
flags.StringVar(&opts.availability, flagAvailability, "active", `Availability of the node ("active"|"pause"|"drain")`)
|
||||
flags.IPNetSliceVar(&opts.defaultAddrPools, flagDefaultAddrPool, []net.IPNet{}, "default address pool in CIDR format")
|
||||
flags.SetAnnotation(flagDefaultAddrPool, "version", []string{"1.39"})
|
||||
flags.Uint32Var(&opts.DefaultAddrPoolMaskLength, flagDefaultAddrPoolMaskLength, 24, "default address pool subnet mask length")
|
||||
flags.SetAnnotation(flagDefaultAddrPoolMaskLength, "version", []string{"1.39"})
|
||||
addSwarmFlags(flags, &opts.swarmOptions)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) error {
|
||||
var defaultAddrPool []string
|
||||
|
||||
client := dockerCli.Client()
|
||||
ctx := context.Background()
|
||||
|
||||
for _, p := range opts.defaultAddrPools {
|
||||
defaultAddrPool = append(defaultAddrPool, p.String())
|
||||
}
|
||||
req := swarm.InitRequest{
|
||||
ListenAddr: opts.listenAddr.String(),
|
||||
AdvertiseAddr: opts.advertiseAddr,
|
||||
DataPathAddr: opts.dataPathAddr,
|
||||
DefaultAddrPool: defaultAddrPool,
|
||||
ForceNewCluster: opts.forceNewCluster,
|
||||
Spec: opts.swarmOptions.ToSpec(flags),
|
||||
AutoLockManagers: opts.swarmOptions.autolock,
|
||||
SubnetSize: opts.DefaultAddrPoolMaskLength,
|
||||
}
|
||||
if flags.Changed(flagAvailability) {
|
||||
availability := swarm.NodeAvailability(strings.ToLower(opts.availability))
|
||||
|
||||
@ -17,22 +17,24 @@ import (
|
||||
const (
|
||||
defaultListenAddr = "0.0.0.0:2377"
|
||||
|
||||
flagCertExpiry = "cert-expiry"
|
||||
flagDispatcherHeartbeat = "dispatcher-heartbeat"
|
||||
flagListenAddr = "listen-addr"
|
||||
flagAdvertiseAddr = "advertise-addr"
|
||||
flagDataPathAddr = "data-path-addr"
|
||||
flagQuiet = "quiet"
|
||||
flagRotate = "rotate"
|
||||
flagToken = "token"
|
||||
flagTaskHistoryLimit = "task-history-limit"
|
||||
flagExternalCA = "external-ca"
|
||||
flagMaxSnapshots = "max-snapshots"
|
||||
flagSnapshotInterval = "snapshot-interval"
|
||||
flagAutolock = "autolock"
|
||||
flagAvailability = "availability"
|
||||
flagCACert = "ca-cert"
|
||||
flagCAKey = "ca-key"
|
||||
flagCertExpiry = "cert-expiry"
|
||||
flagDispatcherHeartbeat = "dispatcher-heartbeat"
|
||||
flagListenAddr = "listen-addr"
|
||||
flagAdvertiseAddr = "advertise-addr"
|
||||
flagDataPathAddr = "data-path-addr"
|
||||
flagDefaultAddrPool = "default-addr-pool"
|
||||
flagDefaultAddrPoolMaskLength = "default-addr-pool-mask-length"
|
||||
flagQuiet = "quiet"
|
||||
flagRotate = "rotate"
|
||||
flagToken = "token"
|
||||
flagTaskHistoryLimit = "task-history-limit"
|
||||
flagExternalCA = "external-ca"
|
||||
flagMaxSnapshots = "max-snapshots"
|
||||
flagSnapshotInterval = "snapshot-interval"
|
||||
flagAutolock = "autolock"
|
||||
flagAvailability = "availability"
|
||||
flagCACert = "ca-cert"
|
||||
flagCAKey = "ca-key"
|
||||
)
|
||||
|
||||
type swarmOptions struct {
|
||||
|
||||
@ -248,6 +248,7 @@ func prettyPrintInfo(dockerCli command.Cli, info types.Info) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// nolint: gocyclo
|
||||
func printSwarmInfo(dockerCli command.Cli, info types.Info) {
|
||||
if info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive || info.Swarm.LocalNodeState == swarm.LocalNodeStateLocked {
|
||||
return
|
||||
@ -261,7 +262,16 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
|
||||
fmt.Fprintln(dockerCli.Out(), " ClusterID:", info.Swarm.Cluster.ID)
|
||||
fmt.Fprintln(dockerCli.Out(), " Managers:", info.Swarm.Managers)
|
||||
fmt.Fprintln(dockerCli.Out(), " Nodes:", info.Swarm.Nodes)
|
||||
var strAddrPool strings.Builder
|
||||
if info.Swarm.Cluster.DefaultAddrPool != nil {
|
||||
for _, p := range info.Swarm.Cluster.DefaultAddrPool {
|
||||
strAddrPool.WriteString(p + " ")
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Out(), " Default Address Pool:", strAddrPool.String())
|
||||
fmt.Fprintln(dockerCli.Out(), " SubnetSize:", info.Swarm.Cluster.SubnetSize)
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Out(), " Orchestration:")
|
||||
|
||||
taskHistoryRetentionLimit := int64(0)
|
||||
if info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit != nil {
|
||||
taskHistoryRetentionLimit = *info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit
|
||||
|
||||
Reference in New Issue
Block a user