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:
@@ -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.
|
||||
|
||||
@@ -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
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-3
@@ -37,7 +37,8 @@ so:
|
||||
docker build -t git.stinnesbeck.com/nils/allmende:<tag> . && docker push git.stinnesbeck.com/nils/allmende:<tag>
|
||||
```
|
||||
2. **Name.** Edit `base/config.env` (`PUBLIC_HOST`, and `PUBLIC_PORT` if the
|
||||
router cannot forward 4001 to 4001).
|
||||
router cannot forward 4001 to 4001; `REGION` if the node should keep
|
||||
listings for a region).
|
||||
3. **Apply.**
|
||||
```
|
||||
kubectl apply -k k8s/base # with a LoadBalancer (MetalLB, kube-vip, ...)
|
||||
@@ -85,8 +86,21 @@ so:
|
||||
that file). The same port serves the owner API, which the admin token
|
||||
protects. To keep it private, comment the file out in `base/kustomization.yaml`
|
||||
and use `kubectl -n allmende port-forward svc/allmende-http 8080:8080`.
|
||||
- **Regions.** A bootstrap node follows none. To make it also keep listings,
|
||||
open the UI through the port-forward, sign in and choose regions.
|
||||
- **Regions.** A bootstrap node follows none by default. To make it also keep
|
||||
listings, either set `REGION` in `base/config.env` (a place name or a
|
||||
3-character geohash, several separated by commas: `REGION=mechernich`) and
|
||||
apply again, or open the UI through the port-forward, sign in and choose
|
||||
regions there. A choice made in the browser is kept on the volume and wins
|
||||
over `REGION` from then on; delete `/data/regions.json` to use `REGION`
|
||||
again. Do not edit the `args` script in `statefulset.yaml` for this: a missing
|
||||
trailing `\` there silently drops `--announce` (see below).
|
||||
- **"--public, but this node has no public address" in the log** means the node
|
||||
runs without `--announce`, so it only knows the pod's private address and
|
||||
advertises that. Check that the live StatefulSet's `args` still contain both
|
||||
`--announce` lines and that every line of the `set --` command but the last
|
||||
ends in `\` (`kubectl -n allmende get statefulset allmende -o yaml`). The
|
||||
warning says which case it is: no `--announce` at all, or one that is not
|
||||
publicly reachable. An empty `PUBLIC_HOST` stops the pod with an error instead.
|
||||
- **More than one bootstrap node** on different networks makes the network
|
||||
independent of any single one. Run this on a second cluster or a VPS and add
|
||||
its records next to the first.
|
||||
|
||||
@@ -6,3 +6,12 @@ PUBLIC_HOST=bootstrap.allmende.stinnesbeck.com
|
||||
# The port your router forwards to the cluster, as seen from the internet
|
||||
# (TCP and UDP). Keep it 4001 unless the router cannot forward it.
|
||||
PUBLIC_PORT=4001
|
||||
|
||||
# The regions this node keeps listings for: a place name or a 3-character
|
||||
# geohash, several separated by commas (REGION=mechernich or REGION=u1h,u0u).
|
||||
# Empty (the default) follows none: it then only helps others connect.
|
||||
# It is the starting value: once the owner chooses regions in the browser, those
|
||||
# are kept on the volume and win over this (delete /data/regions.json to use
|
||||
# this again). Changing this file restarts the pod, because the ConfigMap name
|
||||
# changes with its content.
|
||||
REGION=
|
||||
|
||||
@@ -34,13 +34,19 @@ spec:
|
||||
# bootstrap node has nothing to recover; its identity is its peer ID,
|
||||
# which lives on the volume). Then run as a bootstrap node: --public
|
||||
# serves the DHT and relays for nodes behind a NAT, --announce names
|
||||
# the address the router forwards.
|
||||
# the address the router forwards, and REGION (config.env) the regions
|
||||
# to keep listings for, if any.
|
||||
#
|
||||
# When you edit this script: every line of the `set --` command but
|
||||
# the last ends in a backslash. A missing one cuts the command short
|
||||
# and silently drops the flags below it (--announce above all); the
|
||||
# node then logs "--public, but this node has no public address".
|
||||
command: ["/bin/sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
: "${PUBLIC_HOST:?set PUBLIC_HOST in k8s/base/config.env}"
|
||||
[ -f /data/admin.token ] || allmende init --no-phrase
|
||||
exec allmende run \
|
||||
--public \
|
||||
set -- --public \
|
||||
--no-default-bootstrap \
|
||||
--no-mdns \
|
||||
--no-login-link \
|
||||
@@ -49,6 +55,12 @@ spec:
|
||||
--listen /ip4/0.0.0.0/udp/4001/quic-v1 \
|
||||
--announce "/dns4/${PUBLIC_HOST}/tcp/${PUBLIC_PORT}" \
|
||||
--announce "/dns4/${PUBLIC_HOST}/udp/${PUBLIC_PORT}/quic-v1"
|
||||
if [ -n "${REGION}" ]; then
|
||||
set -f; IFS=,
|
||||
for r in ${REGION}; do set -- "$@" --region "$r"; done
|
||||
unset IFS; set +f
|
||||
fi
|
||||
exec allmende run "$@"
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: allmende-config
|
||||
|
||||
Reference in New Issue
Block a user