k8s: REGION in config.env; the no-public-address warning names --announce

REGION (place names or geohashes, comma separated) is passed to the node by the StatefulSet script, which now builds its arguments with set -- so a region is optional and PUBLIC_HOST must be set. The warning for a --public node without a public address now says which case it is (no --announce, or one that is not reachable) and the flag that fixes it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 23:37:55 +01:00
co-authored by Claude Sonnet 5.5
parent 4e7cbd3dbd
commit 803202e94e
6 changed files with 80 additions and 8 deletions
+17
View File
@@ -5,6 +5,23 @@ import (
manet "github.com/multiformats/go-multiaddr/net"
)
// noPublicAddressWarning explains why a --public node has no records to
// publish, and the flag that fixes it. A node behind a router or in a
// container only sees its own private address, so it must be told the one
// others can dial; without --announce that is the usual reason, and a mistyped
// or private --announce address the other.
func noPublicAddressWarning(announced bool) string {
const fix = "say which address others should dial with --announce, e.g. " +
"--announce /dns4/<your public name>/tcp/<port> --announce /dns4/<your public name>/udp/<port>/quic-v1; " +
"the node then prints the DNS records to publish"
if !announced {
return "--public, but this node has no public address: it only knows its own private ones (it sits behind a router or in a container?). " +
"A bootstrap node needs one: " + fix
}
return "--public, but none of the --announce addresses is publicly reachable (a private or loopback IP, or a name such as localhost?). " +
"Others cannot dial it, so " + fix
}
// bootstrapRecords turns a node's addresses into the DNS TXT values that make
// it a bootstrap node, one per publicly routable address. Loopback and private
// addresses are left out: nobody else could use them.
+20
View File
@@ -2,6 +2,7 @@ package main
import (
"reflect"
"strings"
"testing"
)
@@ -28,6 +29,25 @@ func TestBootstrapRecordsKeepOnlyPublicAddresses(t *testing.T) {
}
}
func TestTheNoPublicAddressWarningNamesTheFlagThatFixesIt(t *testing.T) {
without := noPublicAddressWarning(false)
for _, want := range []string{"--announce /dns4/", "/udp/<port>/quic-v1", "behind a router or in a container", "DNS records"} {
if !strings.Contains(without, want) {
t.Errorf("without --announce the warning must mention %q:\n%s", want, without)
}
}
with := noPublicAddressWarning(true)
if !strings.Contains(with, "none of the --announce addresses is publicly reachable") || !strings.Contains(with, "localhost") {
t.Errorf("with an unusable --announce the warning must say so:\n%s", with)
}
if strings.Contains(with, "it only knows its own private ones") {
t.Errorf("it must not claim --announce is missing when it was given:\n%s", with)
}
if without == with {
t.Error("the two situations need different advice")
}
}
func TestAHostnameAddressIsPublishedAsItIs(t *testing.T) {
const id = "12D3KooWQYhTNQdmr3ArTeUHRYzFg94BKyTkoWBDWez9kSCVe2Xo"
got := bootstrapRecords([]string{
+2 -2
View File
@@ -220,8 +220,8 @@ func cmdRun(args []string) error {
}
fmt.Fprintln(os.Stderr)
} else {
log.Warn("--public, but this node has no public address; a bootstrap node needs one (a server, or a forwarded port): publish dnsaddr=/ip4/<public ip>/tcp/<port>/p2p/<peer id>",
"peer_id", node.ID().String())
log.Warn(noPublicAddressWarning(len(announceAddrs) > 0),
"peer_id", node.ID().String(), "announce", []string(announceAddrs))
}
}