Upgrade go-sockaddr/template to latest version + upgrade CHANGELOG

This commit is contained in:
Jonathan Ballet 2017-06-25 20:55:40 +02:00
parent 0a85733f7e
commit 3ffb39ea2b
5 changed files with 116 additions and 20 deletions

View file

@ -1,6 +1,8 @@
## 0.6.0 (Unreleased)
IMPROVEMENTS:
* agent/config: Late binding to IP addresses using go-sockaddr/template syntax
[GH-2399]
* core: Rolling updates based on allocation health [GH-2621, GH-2634]
* core: Default advertise to private IP address if bind is 0.0.0.0 [GH-2399]
* core: Track multiple job versions and add a stopped state for jobs [GH-2566]

View file

@ -53,23 +53,22 @@ Example:
{{ GetDefaultInterfaces }}
`GetPrivateInterfaces` - Returns one IfAddr for every forwardable IP address
that is included in RFC 6890, is attached to the interface with the default
route, and whose interface is marked as up. NOTE: RFC 6890 is a more exhaustive
version of RFC1918 because it spans IPv4 and IPv6, however it does permit the
that is included in RFC 6890 and whose interface is marked as up. NOTE: RFC 6890 is a more exhaustive
version of RFC1918 because it spans IPv4 and IPv6, however, RFC6890 does permit the
inclusion of likely undesired addresses such as multicast, therefore our version
of "private" also filters out non-forwardable addresses.
Example:
{{ GetPrivateInterfaces | include "flags" "up" }}
{{ GetPrivateInterfaces | sort "default" | join "address" " " }}
`GetPublicInterfaces` - Returns a list of IfAddr that do not match RFC 6890, is
attached to the default route, and whose interface is marked as up.
`GetPublicInterfaces` - Returns a list of IfAddr structs whos IPs are
forwardable, do not match RFC 6890, and whose interface is marked up.
Example:
{{ GetPublicInterfaces | include "flags" "up" }}
{{ GetPublicInterfaces | sort "default" | join "name" " " }}
`GetPrivateIP` - Helper function that returns a string of the first IP address
@ -80,6 +79,14 @@ Example:
{{ GetPrivateIP }}
`GetPrivateIPs` - Helper function that returns a string of the all private IP
addresses on the host.
Example:
{{ GetPrivateIPs }}
`GetPublicIP` - Helper function that returns a string of the first IP from
GetPublicInterfaces.
@ -87,12 +94,29 @@ Example:
{{ GetPublicIP }}
`GetPublicIPs` - Helper function that returns a space-delimited string of the
all public IP addresses on the host.
Example:
{{ GetPrivateIPs }}
`GetInterfaceIP` - Helper function that returns a string of the first IP from
the named interface.
Example:
{{ GetInterfaceIP }}
{{ GetInterfaceIP "en0" }}
`GetInterfaceIPs` - Helper function that returns a space-delimited list of all
IPs on a given interface.
Example:
{{ GetInterfaceIPs "en0" }}
`sort` - Sorts the IfAddrs result based on its arguments. `sort` takes one
@ -100,6 +124,8 @@ argument, a list of ways to sort its IfAddrs argument. The list of sort
criteria is comma separated (`,`):
- `address`, `+address`: Ascending sort of IfAddrs by Address
- `-address`: Descending sort of IfAddrs by Address
- `default`, `+default`: Ascending sort of IfAddrs, IfAddr with a default route first
- `-default`: Descending sort of IfAddrs, IfAttr with default route last
- `name`, `+name`: Ascending sort of IfAddrs by lexical ordering of interface name
- `-name`: Descending sort of IfAddrs by lexical ordering of interface name
- `port`, `+port`: Ascending sort of IfAddrs by port number
@ -116,7 +142,7 @@ criteria is comma separated (`,`):
Example:
{{ GetPrivateInterfaces | sort "type,size,address" }}
{{ GetPrivateInterfaces | sort "default,-type,size,+address" }}
`exclude` and `include`: Filters IfAddrs based on the selector criteria and its
@ -142,7 +168,7 @@ available filtering criteria is:
Example:
{{ GetPrivateInterfaces | exclude "type" "IPv6" | include "flag" "up|forwardable" }}
{{ GetPrivateInterfaces | exclude "type" "IPv6" }}
`unique`: Removes duplicate entries from the IfAddrs list, assuming the list has
@ -152,14 +178,14 @@ already been sorted. `unique` only takes one argument:
Example:
{{ GetPrivateInterfaces | sort "type,address" | unique "name" }}
{{ GetAllInterfaces | sort "default,-type,address" | unique "name" }}
`limit`: Reduces the size of the list to the specified value.
Example:
{{ GetPrivateInterfaces | include "flags" "forwardable|up" | limit 1 }}
{{ GetPrivateInterfaces | limit 1 }}
`offset`: Seeks into the list by the specified value. A negative value can be
@ -167,7 +193,33 @@ used to seek from the end of the list.
Example:
{{ GetPrivateInterfaces | include "flags" "forwardable|up" | offset "-2" | limit 1 }}
{{ GetPrivateInterfaces | offset "-2" | limit 1 }}
`math`: Perform a "math" operation on each member of the list and return new
values. `math` takes two arguments, the attribute to operate on and the
operation's value.
Supported operations include:
- `address`: Adds the value, a positive or negative value expressed as a
decimal string, to the address. The sign is required. This value is
allowed to over or underflow networks (e.g. 127.255.255.255 `"address" "+1"`
will return "128.0.0.0"). Addresses will wrap at IPv4 or IPv6 boundaries.
- `network`: Add the value, a positive or negative value expressed as a
decimal string, to the network address. The sign is required. Positive
values are added to the network address. Negative values are subtracted
from the network's broadcast address (e.g. 127.0.0.1 `"network" "-1"` will
return "127.255.255.255"). Values that overflow the network size will
safely wrap.
Example:
{{ GetPrivateInterfaces | include "type" "IP" | math "address" "+256" | attr "address" }}
{{ GetPrivateInterfaces | include "type" "IP" | math "address" "-256" | attr "address" }}
{{ GetPrivateInterfaces | include "type" "IP" | math "network" "+2" | attr "address" }}
{{ GetPrivateInterfaces | include "type" "IP" | math "network" "-2" | attr "address" }}
{{ GetPrivateInterfaces | include "flags" "forwardable|up" | include "type" "IPv4" | math "network" "+2" | attr "address" }}
`attr`: Extracts a single attribute of the first member of the list and returns
@ -177,7 +229,19 @@ supported attributes.
Example:
{{ GetPrivateInterfaces | include "flags" "forwardable|up" | attr "address" }}
{{ GetAllInterfaces | exclude "flags" "up" | attr "address" }}
`Attr`: Extracts a single attribute from an `IfAttr` and in every other way
performs the same as the `attr`.
Example:
{{ with $ifAddrs := GetAllInterfaces | include "type" "IP" | sort "+type,+address" -}}
{{- range $ifAddrs -}}
{{- Attr "address" . }} -- {{ Attr "network" . }}/{{ Attr "size" . -}}
{{- end -}}
{{- end }}
`join`: Similar to `attr`, `join` extracts all matching attributes of the list
@ -187,7 +251,7 @@ and returns them as a string joined by the separator, the second argument to
Example:
{{ GetPrivateInterfaces | include "flags" "forwardable|up" | join "address" " " }}
{{ GetAllInterfaces | include "flags" "forwardable" | join "address" " " }}
`exclude` and `include` flags:
@ -205,7 +269,7 @@ Example:
- `up`: Is the interface up?
Attributes for `attr` and `join`:
Attributes for `attr`, `Attr`, and `join`:
SockAddr Type:
- `string`

View file

@ -64,23 +64,53 @@ func init() {
HelperFuncs = template.FuncMap{
// Misc functions that operate on IfAddrs inputs
"attr": sockaddr.IfAttr,
"attr": Attr,
"join": sockaddr.JoinIfAddrs,
"limit": sockaddr.LimitIfAddrs,
"offset": sockaddr.OffsetIfAddrs,
"unique": sockaddr.UniqueIfAddrsBy,
// Misc math functions that operate on a single IfAddr input
"math": sockaddr.IfAddrsMath,
// Return a Private RFC 6890 IP address string that is attached
// to the default route and a forwardable address.
"GetPrivateIP": sockaddr.GetPrivateIP,
// Return all Private RFC 6890 IP addresses as a space-delimited string of
// IP addresses. Addresses returned do not have to be on the interface with
// a default route.
"GetPrivateIPs": sockaddr.GetPrivateIPs,
// Return a Public RFC 6890 IP address string that is attached
// to the default route and a forwardable address.
"GetPublicIP": sockaddr.GetPublicIP,
// Return allPublic RFC 6890 IP addresses as a space-delimited string of IP
// addresses. Addresses returned do not have to be on the interface with a
// default route.
"GetPublicIPs": sockaddr.GetPublicIPs,
// Return the first IP address of the named interface, sorted by
// the largest network size.
"GetInterfaceIP": sockaddr.GetInterfaceIP,
// Return all IP addresses on the named interface, sorted by the largest
// network size.
"GetInterfaceIPs": sockaddr.GetInterfaceIPs,
}
}
// Attr returns the attribute from the ifAddrRaw argument. If the argument is
// an IfAddrs, only the first element will be evaluated for resolution.
func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) {
switch v := ifAddrsRaw.(type) {
case sockaddr.IfAddr:
return sockaddr.IfAttr(selectorName, v)
case sockaddr.IfAddrs:
return sockaddr.IfAttrs(selectorName, v)
default:
return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)", selectorName, ifAddrsRaw, ifAddrsRaw)
}
}

6
vendor/vendor.json vendored
View file

@ -745,10 +745,10 @@
"revisionTime": "2017-06-22T20:44:38Z"
},
{
"checksumSHA1": "lPzwetgfMBtpHqdTPolgejMctVQ=",
"checksumSHA1": "mIUCMmRHslN2bxQZ0uObMnXxk9E=",
"path": "github.com/hashicorp/go-sockaddr/template",
"revision": "f910dd83c2052566cad78352c33af714358d1372",
"revisionTime": "2017-02-08T07:30:35Z"
"revision": "e12d9401a74f025fe672cd1a84b2081c773990d3",
"revisionTime": "2017-06-22T20:44:38Z"
},
{
"path": "github.com/hashicorp/go-syslog",