(dockerCLI command.Cli)
| 29 | } |
| 30 | |
| 31 | func newInitCommand(dockerCLI command.Cli) *cobra.Command { |
| 32 | opts := initOptions{ |
| 33 | listenAddr: NewListenAddrOption(), |
| 34 | } |
| 35 | |
| 36 | cmd := &cobra.Command{ |
| 37 | Use: "init [OPTIONS]", |
| 38 | Short: "Initialize a swarm", |
| 39 | Args: cli.NoArgs, |
| 40 | RunE: func(cmd *cobra.Command, args []string) error { |
| 41 | return runInit(cmd.Context(), dockerCLI, cmd.Flags(), opts) |
| 42 | }, |
| 43 | Annotations: map[string]string{ |
| 44 | "version": "1.24", |
| 45 | "swarm": "", // swarm init does not require swarm to be active, and is always available on API 1.24 and up |
| 46 | }, |
| 47 | ValidArgsFunction: cobra.NoFileCompletions, |
| 48 | DisableFlagsInUseLine: true, |
| 49 | } |
| 50 | |
| 51 | flags := cmd.Flags() |
| 52 | flags.Var(&opts.listenAddr, flagListenAddr, `Listen address (format: "<ip|interface>[:port]")`) |
| 53 | flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", `Advertised address (format: "<ip|interface>[:port]")`) |
| 54 | flags.StringVar(&opts.dataPathAddr, flagDataPathAddr, "", `Address or interface to use for data path traffic (format: "<ip|interface>")`) |
| 55 | _ = flags.SetAnnotation(flagDataPathAddr, "version", []string{"1.31"}) |
| 56 | flags.Uint32Var(&opts.dataPathPort, flagDataPathPort, 0, "Port number to use for data path traffic (1024 - 49151). If no value is set or is set to 0, the default port (4789) is used.") |
| 57 | _ = flags.SetAnnotation(flagDataPathPort, "version", []string{"1.40"}) |
| 58 | flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state") |
| 59 | flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)") |
| 60 | flags.StringVar(&opts.availability, flagAvailability, "active", `Availability of the node ("active", "pause", "drain")`) |
| 61 | flags.IPNetSliceVar(&opts.defaultAddrPools, flagDefaultAddrPool, []net.IPNet{}, "default address pool in CIDR format") |
| 62 | _ = flags.SetAnnotation(flagDefaultAddrPool, "version", []string{"1.39"}) |
| 63 | flags.Uint32Var(&opts.DefaultAddrPoolMaskLength, flagDefaultAddrPoolMaskLength, 24, "default address pool subnet mask length") |
| 64 | _ = flags.SetAnnotation(flagDefaultAddrPoolMaskLength, "version", []string{"1.39"}) |
| 65 | addSwarmFlags(flags, &opts.swarmOptions) |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | func runInit(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts initOptions) error { |
| 70 | apiClient := dockerCLI.Client() |
searching dependent graphs…