Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Make address argument to weave dns-{add|remove} optional #1379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions site/weavedns.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,20 @@ If you want to give the container a name in DNS *other* than its
hostname, you can register it using the `dns-add` command. For example:

```bash
$ C=$(docker run -e WEAVE_CIDR=10.2.1.27/24 -ti ubuntu)
$ weave dns-add 10.2.1.27 $C -h pingme2.weave.local
$ C=$(docker run -ti ubuntu)
$ weave dns-add $C -h pingme2.weave.local
```

You can also use `dns-add` to add the container's configured hostname
and domain, simply by omitting `-h <fqdn>`.
and domain simply by omitting `-h <fqdn>`, or specify additional IP
addresses to be registered against the container's hostname e.g.
`weave dns-add 10.2.1.27 $C`.

The inverse operation can be carried out using the `dns-remove`
command:

```bash
$ weave dns-remove 10.2.1.27 $C
$ weave dns-remove $C
```

## <a name="resolve-weavedns-entries-from-host"></a>Resolve weaveDNS entries from host
Expand Down
6 changes: 5 additions & 1 deletion test/240_dns_add_name_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ weave_on $HOST1 dns-add $C2 c2 -h $NAME2
assert_dns_record $HOST1 c1 $NAME2 $C2

weave_on $HOST1 dns-add $C1 c1 -h $NAME1
weave_on $HOST1 dns-add $C1 c1 -h $NAME3
weave_on $HOST1 dns-add c1 -h $NAME3

assert_dns_a_record $HOST1 c1 $NAME1 $C1
assert_dns_a_record $HOST1 c1 $NAME3 $C1
Expand All @@ -30,4 +30,8 @@ weave_on $HOST1 dns-remove $C1 c1 -h $NAME1
assert_no_dns_record $HOST1 c1 $NAME1
assert_dns_a_record $HOST1 c1 $NAME3 $C1

weave_on $HOST1 dns-remove c1 -h $NAME3

assert_no_dns_record $HOST1 c1 $NAME3

end_suite
20 changes: 16 additions & 4 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ weave run [--with-dns | --without-dns] [<addr> ...]
weave start [<addr> ...] <container_id>
weave attach [<addr> ...] <container_id>
weave detach [<addr> ...] <container_id>
weave dns-add <ip_address> [<ip_address> ...] <container_id> [-h <fqdn>]
weave dns-remove <ip_address> [<ip_address> ...] <container_id> [-h <fqdn>]
weave dns-add [<ip_address> ...] <container_id> [-h <fqdn>]
weave dns-remove [<ip_address> ...] <container_id> [-h <fqdn>]
weave dns-lookup <unqualified_name>
weave expose [<addr> ...] [-h <fqdn>]
weave hide [<addr> ...]
Expand Down Expand Up @@ -735,6 +735,12 @@ echo_addresses() {
echo $1 $2 $3
}

echo_ips() {
for CIDR in $3; do
echo ${3%/*}
done
}

peer_args() {
res=''
sep=''
Expand Down Expand Up @@ -1502,9 +1508,12 @@ case "$COMMAND" in
dns-add)
collect_ip_args "$@"
shift $IP_COUNT
[ $IP_COUNT -gt 0 -a \( $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) \) ] || usage
[ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage
check_running $CONTAINER_NAME
CONTAINER=$(container_id $1)
if [ $IP_COUNT -eq 0 ] ; then
IP_ARGS=$(with_container_addresses echo_ips $CONTAINER)
fi
if [ $# -eq 1 ] ; then
with_container_fqdn $CONTAINER put_dns_fqdn $IP_ARGS
else
Expand All @@ -1514,9 +1523,12 @@ case "$COMMAND" in
dns-remove)
collect_ip_args "$@"
shift $IP_COUNT
[ $IP_COUNT -gt 0 -a \( $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) \) ] || usage
[ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage
check_running $CONTAINER_NAME
CONTAINER=$(container_id $1)
if [ $IP_COUNT -eq 0 ] ; then
IP_ARGS=$(with_container_addresses echo_ips $CONTAINER)
fi
if [ $# -eq 1 ] ; then
delete_dns $CONTAINER $IP_ARGS
else
Expand Down