Adoption mode: a node in use is adopted before it is converged (hq ADR 0100–0103) #20
@@ -18,6 +18,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -239,6 +240,18 @@ func registryAgrees(set *flag.FlagSet, opts *bootstrap.Options) error {
|
|||||||
said := map[string]bool{}
|
said := map[string]bool{}
|
||||||
set.Visit(func(f *flag.Flag) { said[f.Name] = true })
|
set.Visit(func(f *flag.Flag) { said[f.Name] = true })
|
||||||
host, portText, err := net.SplitHostPort(opts.Registry)
|
host, portText, err := net.SplitHostPort(opts.Registry)
|
||||||
|
var missing *net.AddrError
|
||||||
|
if errors.As(err, &missing) && missing.Err == "missing port in address" {
|
||||||
|
// A host alone, as --registry took before its port became the node's: the registry's
|
||||||
|
// port — the one given, or the catalogue's — completes it.
|
||||||
|
port := opts.Ports.Registry
|
||||||
|
if port == 0 {
|
||||||
|
port = bootstrap.DefaultPorts().Registry
|
||||||
|
}
|
||||||
|
opts.Ports.Registry = port
|
||||||
|
opts.Registry = net.JoinHostPort(strings.Trim(opts.Registry, "[]"), strconv.Itoa(port))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("--registry %q is not host:port: %w", opts.Registry, err)
|
return fmt.Errorf("--registry %q is not host:port: %w", opts.Registry, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,3 +190,17 @@ func TestTheRegistrysPortAndAddressAgree(t *testing.T) {
|
|||||||
t.Error("two ports for one registry were accepted")
|
t.Error("two ports for one registry were accepted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestARegistryGivenAsAHostAloneTakesTheRegistrysPort(t *testing.T) {
|
||||||
|
_, opts, _, err := parseArgs([]string{"--registry", "192.0.2.10"})
|
||||||
|
if err != nil || opts.Registry != "192.0.2.10:5000" || opts.Ports.Registry != 5000 {
|
||||||
|
t.Errorf("--registry host alone: %s %d %v", opts.Registry, opts.Ports.Registry, err)
|
||||||
|
}
|
||||||
|
_, opts, _, err = parseArgs([]string{"--registry", "192.0.2.10", "--registry-port", "5100"})
|
||||||
|
if err != nil || opts.Registry != "192.0.2.10:5100" {
|
||||||
|
t.Errorf("--registry host with --registry-port: %s %v", opts.Registry, err)
|
||||||
|
}
|
||||||
|
if _, _, _, err := parseArgs([]string{"--registry", "192.0.2.10:notaport"}); err == nil {
|
||||||
|
t.Error("a registry with a port that is not a number was accepted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user