Skip to content

Commit 73cb8d6

Browse files
committed
Lots more updates for TOML -> Env vars
1 parent e49a4bc commit 73cb8d6

File tree

9 files changed

+133
-131
lines changed

9 files changed

+133
-131
lines changed

README.md

+25-18
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,39 @@ out the values that were used. The environment variable are as follows.
158158
Defaults are in bold at the end of the line:
159159

160160
* `SIDECAR_LOGGING_LEVEL`: The logging level to use (debug, info, warn, error)
161-
*info**
161+
**info**
162162
* `SIDECAR_LOGGING_FORMAT`: Logging format to use (text, json) **text**
163163
* `SIDECAR_DISCOVERY`: Which discovery backends to use as a csv array
164-
(static, docker) *`[ docker ]`**
164+
(static, docker) **`[ docker ]`**
165+
* `SIDECAR_SEEDS`: csv array of IP addresses used to seed the cluster.
166+
* `SIDECAR_CLUSTER_NAME`: The name of the Sidecar cluster. Restricts membership
167+
to hosts with the same cluster name.
168+
* `SIDECAR_ADVERTISE_IP`: Manually override the IP address Sidecar uers for
169+
cluster membership.
165170
* `SIDECAR_EXCLUDE_IPS`: csv array of IPs to exclude from interface selection
166-
*`[ 192.168.168.168 ]`**
171+
**`[ 192.168.168.168 ]`**
167172
* `SIDECAR_STATS_ADDR`: An address to send performance stats to. **none**
168173
* `SIDECAR_PUSH_PULL_INTERVAL`: How long to wait between anti-entropy syncs.
169-
*20s**
174+
**20s**
170175
* `SIDECAR_GOSSIP_MESSAGES`: How many times to gather messages per round. **15**
171176
* `SIDECAR_DEFAULT_CHECK_ENDPOINT`: Default endpoint to health check services
172-
on *`/version`**
177+
on **`/version`**
173178

174179
* `SERVICES_NAMER`: Which method to use to extract service names. In both
175-
cases it will fall back to image name. (docker_label, regex) *`docker_label`**.
180+
cases it will fall back to image name. (`docker_label`, `regex`) **`docker_label`**.
176181
* `SERVICES_NAME_MATCH`: The regexp to use to extract the service name
177182
from the container name.
178183
* `SERVICES_NAME_LABEL`: The Docker label to use to identify service names
179184
`ServiceName`
180185

181186
* `DOCKER_URL`: How to connect to Docker if Docker discovery is enabled.
182-
*`unix:///var/run/docker.sock`**
187+
**`unix:///var/run/docker.sock`**
183188

184189
* `STATIC_CONFIG_FILE`: The config file to use if static discovery is enabled
185-
*`static.json`**
190+
**`static.json`**
186191

187-
* `LISTENER_URLS`: If we want to statically configure any even listeners, the
188-
URLs should go in a csv array here. See ***Listeners**** section below for more
192+
* `LISTENER_URLS`: If we want to statically configure any event listeners, the
193+
URLs should go in a csv array here. See **Listeners** section below for more
189194
on dynamic listeners.
190195

191196
* `HAPROXY_DISABLE`: Disable management of HAproxy entirely. This is useful if
@@ -196,23 +201,25 @@ Defaults are in bold at the end of the line:
196201
* `HAPROXY_VERIFY_COMMAND`: The verify command to use for HAproxy **sane defaults**
197202
* `HAPROXY_BIND_IP`: The IP that HAproxy should bind to on the host **192.168.168.168**
198203
* `HAPROXY_TEMPLATE_FILE`: The source template file to use when writing HAproxy
199-
configs. This is a Go text template. *`views/haproxy.cfg`**
204+
configs. This is a Go text template. **`views/haproxy.cfg`**
200205
* `HAPROXY_CONFIG_FILE`: The path where the `haproxy.cfg` file will be written. Note
201206
that if you change this you will need to update the verify and reload commands.
202-
*`/etc/haproxy.cfg`**
207+
**`/etc/haproxy.cfg`**
203208
* `HAPROXY_PID_FILE`: The path where HAproxy's PID file will be written. Note
204209
that if you change this you will need to update the verify and reload commands.
205-
*`/var/run/haproxy.pid`**
210+
**`/var/run/haproxy.pid`**
206211
* `HAPROXY_USER`: The Unix user under which HAproxy should run **haproxy**
207-
* `HAPROXY_GROUP`: The Unix group under which HAproxy shoudl run **haproxy**
212+
* `HAPROXY_GROUP`: The Unix group under which HAproxy should run **haproxy**
208213
* `HAPROXY_USE_HOSTNAMES`: Should we write hostnames in the HAproxy config instead
209-
of IP addresses? *false**
214+
of IP addresses? **`false`**
210215

211216
## Discovery
212217

213218
Sidecar supports both Docker-based discovery and a discovery mechanism where
214-
you publish services into a JSON file locally, called "static". These can then be advertised as running services just like they would be from a Docker host. These are configured with the `SIDECAR_DISCOVERY` environment variable. Using both would
215-
look like:
219+
you publish services into a JSON file locally, called "static". These can then
220+
be advertised as running services just like they would be from a Docker host.
221+
These are configured with the `SIDECAR_DISCOVERY` environment variable. Using
222+
both would look like:
216223

217224
```bash
218225
export SIDECAR_DISCOVERY=static,docker
@@ -227,7 +234,7 @@ Sidecar currently accepts a single option for Docker-based discovery, the URL
227234
to use to connect to Docker. Ideally this will be the same machine that Sidecar
228235
runs on because it makes assumptions about addresses. By default it will use
229236
the standard Docker Unix domain socket. You can change this with the
230-
`DOCKER_URL` env var. This needs to be a url that works with teh Docker client.
237+
`DOCKER_URL` env var. This needs to be a url that works with the Docker client.
231238

232239
Note that Sidecar only supports a *single* URL, unlike the Docker CLI tool.
233240

addresses.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func findPrivateAddresses() ([]*net.IP, error) {
7878
return result, err
7979
}
8080

81-
func getPublishedIP(excluded []string, advertise *string) (string, error) {
82-
if advertise != nil && *advertise != "" {
83-
return *advertise, nil
81+
func getPublishedIP(excluded []string, advertise string) (string, error) {
82+
if advertise != "" {
83+
return advertise, nil
8484
}
8585

8686
addresses, _ := findPrivateAddresses()

addresses_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ func Test_Addresses(t *testing.T) {
3636
ip := "10.10.10.10"
3737

3838
Convey("Returns the advertised IP if supplied", func() {
39-
result, err := getPublishedIP([]string{}, &ip)
39+
result, err := getPublishedIP([]string{}, ip)
4040
So(err, ShouldBeNil)
4141
So(result, ShouldEqual, ip)
4242
})
4343

4444
// See caveat for findPrivateAddresses() above
4545
Convey("Returns an address", func() {
4646
addresses, _ := findPrivateAddresses()
47-
result, err := getPublishedIP([]string{}, nil)
47+
result, err := getPublishedIP([]string{}, "")
4848

4949
So(err, ShouldBeNil)
5050
So(result, ShouldResemble, addresses[0].String())

cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func parseCommandLine() *CliOpts {
3030

3131
opts.AdvertiseIP = app.Flag("advertise-ip", "The address to advertise to the cluster").Short('a').String()
3232
opts.ClusterIPs = app.Flag("cluster-ip", "The cluster seed addresses").Required().Short('c').NoEnvar().Strings()
33-
opts.ClusterName = app.Flag("cluster-name", "The cluster we're part of").Short('n').Default("default").String()
33+
opts.ClusterName = app.Flag("cluster-name", "The cluster we're part of").Short('n').String()
3434
opts.CpuProfile = app.Flag("cpuprofile", "Enable CPU profiling").Short('p').Bool()
3535
opts.Discover = app.Flag("discover", "Method of discovery").Short('d').NoEnvar().Strings()
3636
opts.HAproxyDisable = app.Flag("haproxy-disable", "Disable managing HAproxy").Short('x').Bool()

config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type SidecarConfig struct {
3939
LoggingFormat string `envconfig:"LOGGING_FORMAT"`
4040
LoggingLevel string `envconfig:"LOGGING_LEVEL" default:"info"`
4141
DefaultCheckEndpoint string `envconfig:"DEFAULT_CHECK_ENDPOINT" default:"/version"`
42+
Seeds []string `envconfig:"SEEDS"`
43+
ClusterName string `envconfig:"CLUSTER_NAME" default:"default"`
44+
AdvertiseIP string `envconfig:"ADVERTISE_IP"`
4245
}
4346

4447
type DockerConfig struct {
@@ -58,7 +61,7 @@ type Config struct {
5861
Listeners ListenerUrlsConfig // LISTENERS_
5962
}
6063

61-
func parseConfig(path string) Config {
64+
func parseConfig() Config {
6265
var config Config
6366

6467
errs := []error{

docker/README.md

-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ binding.
3838
the seed. You'll want to set this to one or more IP addresses or hostnames
3939
of the cluster seed hosts.
4040

41-
```
42-
SIDECAR_SEEDS="seed1 host2 seed3" # Required
43-
ADVERTISE_IP="192.168.168.5" # Optional
44-
SIDECAR_LOGGING_LEVEL="debug" # Optional
45-
SIDECAR_CLUSTER_NAME="some-name" # Optional
46-
```
47-
48-
The seed hosts passed via `SIDECAR_SEEDS` are formatted as
49-
`--cluster-ip` arguments to Sidecar.
50-
5141
As mentioned above, the default configuration is all set up with the
5242
expectation that you will map `/var/run/docker.sock` into the container. This
5343
is where Docker usually writes its Unix socket. If you want to use TCP to

docker/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
IMAGE=$1
66
echo "Starting from $IMAGE"
7-
docker run -i -t -v /var/run/docker.sock:/var/run/docker.sock --label SidecarDiscover=false -e SIDECAR_LOGGING_LEVEL=debug -e SIDECAR_SEEDS="127.0.0.1" -e SIDECAR_HAPROXY_DISABLE=true --net=host --cap-add NET_ADMIN $IMAGE
7+
docker run -i -t -v /var/run/docker.sock:/var/run/docker.sock --label SidecarDiscover=false -e SIDECAR_LOGGING_LEVEL=debug -e SIDECAR_SEEDS="127.0.0.1" -e HAPROXY_DISABLE=true --net=host --cap-add NET_ADMIN $IMAGE

docker/s6/services/sidecar.svc/run

-27
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,6 @@ for entry in $SIDECAR_SEEDS; do
55
CLI="$CLI --cluster-ip $entry"
66
done
77

8-
if [[ -n "$SIDECAR_DISCOVERY" ]]; then
9-
for entry in $SIDECAR_DISCOVERY; do
10-
CLI="$CLI --discover $entry"
11-
done
12-
fi
13-
14-
# Only do some substitutions on the first run (sed creates .bak file)
15-
if [[ ! -f /sidecar/sidecar.toml.bak ]]; then
16-
# Allow adding a subscriber URL to the listeners
17-
if [[ -n "$SIDECAR_LISTENER" ]]; then
18-
# Use ~ rather than / since this is usually an URL
19-
sed -i.bak 's~^urls *= *\[~urls = \[ "'"$SIDECAR_LISTENER"'", ~' sidecar.toml
20-
fi
21-
22-
# Update the bind_ip if set as an env var to override the original
23-
if [[ -n "$BIND_IP" ]]; then
24-
sed -i.bak 's~^bind_ip *=.*$~bind_ip = "'"$BIND_IP"'"~' sidecar.toml
25-
fi
26-
27-
# If we're disabling IP addresses in the HAproxy configs
28-
if [[ -n "$USE_HOSTNAMES" ]]; then
29-
sed -i.bak 's~^use_hostnames *=.*$~use_hostnames = '$USE_HOSTNAMES'~' sidecar.toml
30-
fi
31-
fi
32-
33-
BIND_IP=`grep bind_ip sidecar.toml | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"`
34-
358
# If there's a BIND_IP and we don't already have it, add the
369
# address to the loopback interface.
3710
if [[ -n "$BIND_IP" ]] && [[ $BIND_IP != "0.0.0.0" ]]; then

0 commit comments

Comments
 (0)