Use same IP address for both boots and nginx (#43)

Signed-off-by: Michael Richard <michael.richard.ing@gmail.com>

## Description

This configures NGINX to listen on port 8080 and lets go the need to configure a second IP address on the host dedicated to NGINX.

## Why is this needed

Setting up a second IP address to host NGINX on the same host is not always easy, especially when running tinkerbell on network devices like switches. The second IP address adds a useless level of complexity. In the future, all the code required to identify the host operating system and configure the IP address could even be removed and left as a prerequisite, since the host is likely to have an IP address already configured.

## How Has This Been Tested?

The untouched vagrant_test.go test ran sucessfully.

## How are existing users impacted? What migration steps/scripts do we need?

Simply re-applying the docker-compose.yml should be sufficient (untested).
Additional firewall rules to allow traffic on port 8080 could be required depending on user's network configuration.

## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
This commit is contained in:
mergify[bot] 2021-01-27 10:39:13 +00:00 committed by GitHub
commit 3d387cd26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 33 deletions

View File

@ -124,7 +124,7 @@ services:
PACKET_VERSION: ${PACKET_VERSION:-ignored} PACKET_VERSION: ${PACKET_VERSION:-ignored}
ROLLBAR_TOKEN: ${ROLLBAR_TOKEN:-ignored} ROLLBAR_TOKEN: ${ROLLBAR_TOKEN:-ignored}
ROLLBAR_DISABLE: ${ROLLBAR_DISABLE:-1} ROLLBAR_DISABLE: ${ROLLBAR_DISABLE:-1}
MIRROR_HOST: ${TINKERBELL_NGINX_IP:-127.0.0.1} MIRROR_HOST: ${TINKERBELL_HOST_IP:-127.0.0.1}:8080
DNS_SERVERS: 8.8.8.8 DNS_SERVERS: 8.8.8.8
PUBLIC_IP: $TINKERBELL_HOST_IP PUBLIC_IP: $TINKERBELL_HOST_IP
BOOTP_BIND: $TINKERBELL_HOST_IP:67 BOOTP_BIND: $TINKERBELL_HOST_IP:67
@ -151,7 +151,7 @@ services:
restart: unless-stopped restart: unless-stopped
tty: true tty: true
ports: ports:
- $TINKERBELL_NGINX_IP:80:80/tcp - $TINKERBELL_HOST_IP:8080:80/tcp
volumes: volumes:
- ./state/webroot:/usr/share/nginx/html/ - ./state/webroot:/usr/share/nginx/html/

View File

@ -78,9 +78,6 @@ export TINKERBELL_CIDR=29
# should be the second address. # should be the second address.
export TINKERBELL_HOST_IP=192.168.1.1 export TINKERBELL_HOST_IP=192.168.1.1
# NGINX IP is used by provisioner to serve files required for iPXE boot
export TINKERBELL_NGINX_IP=192.168.1.2
# Tink server username and password # Tink server username and password
export TINKERBELL_TINK_USERNAME=admin export TINKERBELL_TINK_USERNAME=admin
export TINKERBELL_TINK_PASSWORD="$tink_password" export TINKERBELL_TINK_PASSWORD="$tink_password"

View File

@ -59,17 +59,12 @@ get_distro_version() (
) )
is_network_configured() ( is_network_configured() (
# Require the provisioner interface have both the host and nginx IP # Require the provisioner interface have the host IP
if ! ip addr show "$TINKERBELL_NETWORK_INTERFACE" | if ! ip addr show "$TINKERBELL_NETWORK_INTERFACE" |
grep -q "$TINKERBELL_HOST_IP"; then grep -q "$TINKERBELL_HOST_IP"; then
return 1 return 1
fi fi
if ! ip addr show "$TINKERBELL_NETWORK_INTERFACE" |
grep -q "$TINKERBELL_NGINX_IP"; then
return 1
fi
return 0 return 0
) )
@ -144,15 +139,13 @@ setup_networking_netplan() (
--arg interface "$TINKERBELL_NETWORK_INTERFACE" \ --arg interface "$TINKERBELL_NETWORK_INTERFACE" \
--arg cidr "$TINKERBELL_CIDR" \ --arg cidr "$TINKERBELL_CIDR" \
--arg host_ip "$TINKERBELL_HOST_IP" \ --arg host_ip "$TINKERBELL_HOST_IP" \
--arg nginx_ip "$TINKERBELL_NGINX_IP" \
'{ '{
network: { network: {
renderer: "networkd", renderer: "networkd",
ethernets: { ethernets: {
($interface): { ($interface): {
addresses: [ addresses: [
"\($host_ip)/\($cidr)", "\($host_ip)/\($cidr)"
"\($nginx_ip)/\($cidr)"
] ]
} }
} }
@ -179,33 +172,24 @@ setup_networking_ubuntu_legacy() (
echo "" echo ""
echo "$BLANK Then run the following commands:" echo "$BLANK Then run the following commands:"
echo "$BLANK ip link set $TINKERBELL_NETWORK_INTERFACE nomaster" echo "$BLANK ip link set $TINKERBELL_NETWORK_INTERFACE nomaster"
echo "$BLANK ifdown $TINKERBELL_NETWORK_INTERFACE:0" echo "$BLANK ifdown $TINKERBELL_NETWORK_INTERFACE"
echo "$BLANK ifdown $TINKERBELL_NETWORK_INTERFACE:1" echo "$BLANK ifup $TINKERBELL_NETWORK_INTERFACE"
echo "$BLANK ifup $TINKERBELL_NETWORK_INTERFACE:0"
echo "$BLANK ifup $TINKERBELL_NETWORK_INTERFACE:1"
exit 1 exit 1
else else
generate_iface_config >>/etc/network/interfaces generate_iface_config >>/etc/network/interfaces
ip link set "$TINKERBELL_NETWORK_INTERFACE" nomaster ip link set "$TINKERBELL_NETWORK_INTERFACE" nomaster
ifdown "$TINKERBELL_NETWORK_INTERFACE:0" ifdown "$TINKERBELL_NETWORK_INTERFACE"
ifdown "$TINKERBELL_NETWORK_INTERFACE:1" ifup "$TINKERBELL_NETWORK_INTERFACE"
ifup "$TINKERBELL_NETWORK_INTERFACE:0"
ifup "$TINKERBELL_NETWORK_INTERFACE:1"
fi fi
) )
generate_iface_config() ( generate_iface_config() (
cat <<EOF cat <<EOF
auto $TINKERBELL_NETWORK_INTERFACE:0 auto $TINKERBELL_NETWORK_INTERFACE
iface $TINKERBELL_NETWORK_INTERFACE:0 inet static iface $TINKERBELL_NETWORK_INTERFACE inet static
address $TINKERBELL_HOST_IP/$TINKERBELL_CIDR address $TINKERBELL_HOST_IP/$TINKERBELL_CIDR
pre-up sleep 4 pre-up sleep 4
auto $TINKERBELL_NETWORK_INTERFACE:1
iface $TINKERBELL_NETWORK_INTERFACE:1 inet static
address $TINKERBELL_NGINX_IP/$TINKERBELL_CIDR
pre-up sleep 4
EOF EOF
) )
@ -221,10 +205,8 @@ ONBOOT=yes
HWADDR=$HWADDRESS HWADDR=$HWADDRESS
BOOTPROTO=static BOOTPROTO=static
IPADDR0=$TINKERBELL_HOST_IP IPADDR=$TINKERBELL_HOST_IP
PREFIX0=$TINKERBELL_CIDR PREFIX=$TINKERBELL_CIDR
IPADDR1=$TINKERBELL_NGINX_IP
PREFIX1=$TINKERBELL_CIDR
EOF EOF
) )