Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network configuration using netplan for Ubuntu versions greater than 16.04 #141

Closed
wants to merge 1 commit into from

Conversation

gauravgahlot
Copy link
Contributor

Signed-off-by: Gaurav Gahlot [email protected]

@gauravgahlot gauravgahlot added kind/feature Categorizes issue or PR as related to a new feature. area/setup Issue related to tinkerbell setup labels May 29, 2020
@gauravgahlot gauravgahlot requested a review from grahamc May 29, 2020 10:19
@gauravgahlot gauravgahlot self-assigned this May 29, 2020
@gauravgahlot gauravgahlot linked an issue May 29, 2020 that may be closed by this pull request
Copy link
Contributor

@grahamc grahamc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about moving the netplan-specific code in to two helper functions:

  1. is_netplan
  2. setup_networking_netplan

the setup_networking function is quite large, and I'm a bit afraid of letting it grow too much more.

Comment on lines +243 to +254
cat >/etc/netplan/${TINKERBELL_NETWORK_INTERFACE}.yaml <<EOF
---
network:
version: 2
renderer: networkd
ethernets:
$TINKERBELL_NETWORK_INTERFACE:
addresses:
- $TINKERBELL_HOST_IP/$cidr
- $TINKERBELL_NGINX_IP/$cidr
EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generating YAML on the fly with bash feels a bit scary. In particular, magic values can turn in to other things like "no" being a bool, and 1.10 being just 1.1. What would you think about using (and installing if it isn't yet available) jq for this? Using jq guarantees the output will be correct and that we didn't make an error in indentation, whitespace, and also makes sure that all of the values are properly quoted.

Here is an example of what that would look like:

TINKERBELL_NETWORK_INTERFACE=10.5.3.1
TINKERBELL_HOST_IP=10.5.3.2
TINKERBELL_NGINX_IP=10.5.3.3
cidr=24

jq -n \
   --arg interface "$TINKERBELL_NETWORK_INTERFACE" \
   --arg cidr "$cidr" \
   --arg host_ip "$TINKERBELL_HOST_IP" \
   --arg nginx_ip "$TINKERBELL_NGINX_IP" \
   '{
  network: "hi",
  renderer: "networkd",
  ethernets: {
    ($interface): {
      addresses: [
        "\($host_ip)/\($cidr)",
        "\($nginx_ip)/\($cidr)"
      ]
    }
  }
}'

This prints:

{
  "network": "hi",
  "renderer": "networkd",
  "ethernets": {
    "10.5.3.1": {
      "addresses": [
        "10.5.3.2/24",
        "10.5.3.3/24"
      ]
    }
  }
}

since JSON is valid YAML, this output works directly with netplan.

Comment on lines +235 to +239
v16=16.04
version=$(. /etc/os-release && echo "$VERSION_ID")
if (( $(echo "$version > $v16" | bc -l) )); then
echo "$INFO found Ubuntu $version, using 'netplan' for network configuration"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like 17.10 is the first release to use netplan by default. Maybe we should change this to >= 17.10?

ip link set $TINKERBELL_NETWORK_INTERFACE nomaster
netplan apply
echo "$INFO waiting for the network configuration to be applied by systemd-networkd"
sleep 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if netplan creates a systemd unit we could wait for, like this:

while ! systemctl is-active netplan-something-or-other; do
  sleep 1
done

@grahamc
Copy link
Contributor

grahamc commented Jun 1, 2020

Oops, I meant to also say -- looks pretty good!

@grahamc
Copy link
Contributor

grahamc commented Jun 16, 2020

These commits were included in #147

@grahamc grahamc closed this Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/setup Issue related to tinkerbell setup kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setup.sh: configure the network using netplan in Ubuntu 18.04+
2 participants