Skip to content

Commit

Permalink
e2e: refactor Consul configurations (#6559)
Browse files Browse the repository at this point in the history
Ensure that we're reusing the base configuration between client and
servers without the possibility of drift. Reduce the amount of `sed`
mangling of the configuration file, and make recommended changes from
`shellcheck` for this section of the provisioning script.

Fixes some rebase errors on the Nomad config as well.
  • Loading branch information
tgross authored Oct 28, 2019
1 parent 56bfcdd commit 4abb6b5
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 27 deletions.
4 changes: 2 additions & 2 deletions e2e/terraform/compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "aws_instance" "server" {
provisioner "remote-exec" {
inline = [
"chmod +x /ops/shared/config/provision-server.sh",
"/ops/shared/config/provision-server.sh aws ${var.server_count} '${var.retry_join}' '${var.nomad_sha}' '${var.indexed == false ? "server.hcl" : "indexed/server-${count.index}.hcl"}'",
"/ops/shared/config/provision-server.sh aws ${var.server_count} '${var.nomad_sha}' '${var.indexed == false ? "server.hcl" : "indexed/server-${count.index}.hcl"}'",
]

connection {
Expand Down Expand Up @@ -84,7 +84,7 @@ resource "aws_instance" "client" {
provisioner "remote-exec" {
inline = [
"chmod +x /ops/shared/config/provision-client.sh",
"/ops/shared/config/provision-client.sh aws '${var.retry_join}' '${var.nomad_sha}' '${var.indexed == false ? "client.hcl" : "indexed/client-${count.index}.hcl"}'",
"/ops/shared/config/provision-client.sh aws '${var.nomad_sha}' '${var.indexed == false ? "client.hcl" : "indexed/client-${count.index}.hcl"}'",
]

connection {
Expand Down
5 changes: 0 additions & 5 deletions e2e/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ variable "client_count" {
default = "4"
}

variable "retry_join" {
description = "Used by Consul to automatically form a cluster."
default = "provider=aws tag_key=ConsulAutoJoin tag_value=auto-join"
}

variable "nomad_sha" {
description = "The sha of Nomad to run"
}
Expand Down
2 changes: 0 additions & 2 deletions e2e/terraform/shared/config/README.md

This file was deleted.

18 changes: 10 additions & 8 deletions e2e/terraform/shared/config/provision-client.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -o nounset

CONFIGDIR=/ops/shared/config

CONSULCONFIGDIR=/etc/consul.d
HADOOP_VERSION=hadoop-2.7.7
HADOOPCONFIGDIR=/usr/local/$HADOOP_VERSION/etc/hadoop
HOME_DIR=ubuntu
Expand All @@ -14,14 +13,16 @@ IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetPrivateIP')
DOCKER_BRIDGE_IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetInterfaceIP "docker0"')

CLOUD="$1"
RETRY_JOIN="$2"
NOMAD_SHA="$3"
NOMAD_CONFIG="$4"
NOMAD_SHA="$2"
NOMAD_CONFIG="$3"

# Consul
sed -i "s/RETRY_JOIN/$RETRY_JOIN/g" $CONFIGDIR/consul_client.json
sudo cp $CONFIGDIR/consul_client.json $CONSULCONFIGDIR/consul.json
sudo cp $CONFIGDIR/consul_$CLOUD.service /etc/systemd/system/consul.service
CONSUL_SRC=/ops/shared/consul
CONSUL_DEST=/etc/consul.d

sudo cp "$CONSUL_SRC/base.json" "$CONSUL_DEST/"
sudo cp "$CONSUL_SRC/retry_$CLOUD.json" "$CONSUL_DEST/"
sudo cp "$CONSUL_SRC/consul_$CLOUD.service" /etc/systemd/system/consul.service

sudo systemctl enable consul.service
sudo systemctl start consul.service
Expand Down Expand Up @@ -54,6 +55,7 @@ echo "export PATH=$PATH:/usr/local/bin/spark/bin:/usr/local/$HADOOP_VERSION/bin"

NOMAD_SRC=/ops/shared/nomad
NOMAD_DEST=/etc/nomad.d
NOMAD_CONFIG_FILENAME=$(basename "$NOMAD_CONFIG")

# download
aws s3 cp "s3://nomad-team-test-binary/builds-oss/nomad_linux_amd64_${NOMAD_SHA}.tar.gz" nomad.tar.gz
Expand All @@ -64,7 +66,7 @@ sudo chmod 0755 /usr/local/bin/nomad
sudo chown root:root /usr/local/bin/nomad

sudo cp "$NOMAD_SRC/base.hcl" "$NOMAD_DEST/"
sudo cp "$NOMAD_SRC/$NOMAD_CONFIG" "$NOMAD_DEST/"
sudo cp "$NOMAD_SRC/$NOMAD_CONFIG" "$NOMAD_DEST/$NOMAD_CONFIG_FILENAME"

# Setup Host Volumes
sudo mkdir /tmp/data
Expand Down
24 changes: 14 additions & 10 deletions e2e/terraform/shared/config/provision-server.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -o nounset

CONFIGDIR=/ops/shared/config

CONSULCONFIGDIR=/etc/consul.d
HADOOP_VERSION=hadoop-2.7.7
HADOOPCONFIGDIR=/usr/local/$HADOOP_VERSION/etc/hadoop
HOME_DIR=ubuntu
Expand All @@ -15,15 +14,18 @@ DOCKER_BRIDGE_IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetInterfaceIP "docker0

CLOUD="$1"
SERVER_COUNT="$2"
RETRY_JOIN="$3"
NOMAD_SHA="$4"
NOMAD_CONFIG="$5"
NOMAD_SHA="$3"
NOMAD_CONFIG="$4"

# Consul
sed -i "s/SERVER_COUNT/$SERVER_COUNT/g" $CONFIGDIR/consul.json
sed -i "s/RETRY_JOIN/$RETRY_JOIN/g" $CONFIGDIR/consul.json
sudo cp $CONFIGDIR/consul.json $CONSULCONFIGDIR
sudo cp $CONFIGDIR/consul_$CLOUD.service /etc/systemd/system/consul.service
CONSUL_SRC=/ops/shared/consul
CONSUL_DEST=/etc/consul.d

sed "s/SERVER_COUNT/$SERVER_COUNT/g" "$CONSUL_SRC/server.json" > /tmp/server.json
sudo mv /tmp/server.json "$CONSUL_DEST/server.json"
sudo cp "$CONSUL_SRC/base.json" "$CONSUL_DEST/"
sudo cp "$CONSUL_SRC/retry_$CLOUD.json" "$CONSUL_DEST/"
sudo cp "$CONSUL_SRC/consul_$CLOUD.service" /etc/systemd/system/consul.service

sudo systemctl enable consul.service
sudo systemctl start consul.service
Expand Down Expand Up @@ -72,6 +74,7 @@ echo "export PATH=$PATH:/usr/local/bin/spark/bin:/usr/local/$HADOOP_VERSION/bin"

NOMAD_SRC=/ops/shared/nomad
NOMAD_DEST=/etc/nomad.d
NOMAD_CONFIG_FILENAME=$(basename "$NOMAD_CONFIG")

# download
aws s3 cp "s3://nomad-team-test-binary/builds-oss/nomad_linux_amd64_${NOMAD_SHA}.tar.gz" nomad.tar.gz
Expand All @@ -83,8 +86,9 @@ sudo chown root:root /usr/local/bin/nomad

sudo cp "$NOMAD_SRC/base.hcl" "$NOMAD_DEST/"

sed "s/3 # SERVER_COUNT/$SERVER_COUNT/g" "$NOMAD_SRC/$NOMAD_CONFIG" > "/tmp/$NOMAD_CONFIG"
sudo mv "/tmp/$NOMAD_CONFIG" "$NOMAD_DEST/$NOMAD_CONFIG"
sed "s/3 # SERVER_COUNT/$SERVER_COUNT/g" "$NOMAD_SRC/$NOMAD_CONFIG" \
> "/tmp/$NOMAD_CONFIG_FILENAME"
sudo mv "/tmp/$NOMAD_CONFIG_FILENAME" "$NOMAD_DEST/$NOMAD_CONFIG_FILENAME"

# enable as a systemd service
sudo cp "$NOMAD_SRC/nomad.service" /etc/systemd/system/nomad.service
Expand Down
13 changes: 13 additions & 0 deletions e2e/terraform/shared/consul/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"log_level": "INFO",
"data_dir": "/opt/consul/data",
"bind_addr": "0.0.0.0",
"client_addr": "0.0.0.0",
"advertise_addr": "{{ GetPrivateIP }}",
"connect": {
"enabled": true
},
"ports": {
"grpc": 8502
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions e2e/terraform/shared/consul/retry_aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"retry_join": ["provider=aws tag_key=ConsulAutoJoin tag_value=auto-join"]
}
3 changes: 3 additions & 0 deletions e2e/terraform/shared/consul/retry_azure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"retry_join": ["provider=azure tag_key=ConsulAutoJoin tag_value=auto-join"]
}
8 changes: 8 additions & 0 deletions e2e/terraform/shared/consul/server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": true,
"ui": true,
"bootstrap_expect": SERVER_COUNT,
"service": {
"name": "consul"
}
}
File renamed without changes.

0 comments on commit 4abb6b5

Please sign in to comment.