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

Makefile: add check-preflight #292

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export U7S_NODE_NAME:= $(NODE_NAME)
export U7S_NODE_SUBNET := $(NODE_SUBNET)

DOCKER ?= docker

export DOCKER := $(DOCKER)

COMPOSE := $(DOCKER) compose
NODE_SERVICE_NAME := node
NODE_SHELL := $(COMPOSE) exec \
Expand Down Expand Up @@ -49,8 +52,12 @@ help:
@echo 'make down-v'
@echo 'kubectl taint nodes --all node-role.kubernetes.io/control-plane-'

.PHONY: check-preflight
check-preflight:
./Makefile.d/check-preflight.sh

.PHONY: up
up:
up: check-preflight
$(COMPOSE) up --build -d

.PHONY: down
Expand Down
66 changes: 66 additions & 0 deletions Makefile.d/check-preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -eu

function WARNING() {
echo >&2 -e "\e[101m\e[97m[WARNING]\e[49m\e[39m $@"
}

function ERROR() {
echo >&2 -e "\e[101m\e[97m[ERROR]\e[49m\e[39m $@"
}

: "${DOCKER:=docker}"

# Check hard dependency commands
for f in make jq "${DOCKER}"; do
if ! command -v "${f}" >/dev/null 2>&1; then
ERROR "Command \"${f}\" is not installed"
exit 1
fi
done

# Check soft dependency commands
for f in kubectl; do
if ! command -v "${f}" >/dev/null 2>&1; then
WARNING "Command \"${f}\" is not installed"
fi
done

# Check if Docker is running in Rootless mode
# TODO: support Podman?
if "${DOCKER}" info --format '{{json .SecurityOptions}}' | grep -q "name=rootless"; then
# Check systemd lingering: https://rootlesscontaine.rs/getting-started/common/login/
if command -v loginctl >/dev/null 2>&1; then
if [ "$(loginctl list-users --output json | jq ".[] | select(.uid == "${UID}").linger")" != "true" ]; then
WARNING 'systemd lingering is not enabled. Run `sudo loginctl enable-linger $(whoami)` to enable it, otherwise Kubernetes will exit on logging out.'
fi
else
WARNING "systemd lingering is not enabled?"
fi

# Check cgroup config
if [[ ! -f /sys/fs/cgroup/cgroup.controllers ]]; then
ERROR "Needs cgroup v2, see https://rootlesscontaine.rs/getting-started/common/cgroup2/"
exit 1
else
f="/sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers"
if [[ ! -f $f ]]; then
ERROR "systemd not running? file not found: $f"
exit 1
fi
if ! grep -q cpu "${f}"; then
WARNING "cpu controller might not be enabled, you need to configure /etc/systemd/system/[email protected] , see https://rootlesscontaine.rs/getting-started/common/cgroup2/"
elif ! grep -q memory "${f}"; then
WARNING "memory controller might not be enabled, you need to configure /etc/systemd/system/[email protected] , see https://rootlesscontaine.rs/getting-started/common/cgroup2/"
fi
fi
else
WARNING "Docker does not seem running in Rootless mode"
fi

# Check kernel modules
for f in ip6_tables ip6table_nat ip_tables iptable_nat vxlan; do
if ! grep -qw "^$f" /proc/modules; then
WARNING "Kernel module \"${f}\" does not seem loaded? (negligible if built-in to the kernel)"
fi
done