Remove unused k3s-join script and service
Superseded by k3s-agent.service with static env file approach.
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
# K3s agent join script for netboot nodes
|
||||
# Fetches token from server and starts k3s agent
|
||||
#
|
||||
# Runs at boot via k3s-join.service
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
K3S_SERVER="192.168.100.1"
|
||||
K3S_URL="https://${K3S_SERVER}:6443"
|
||||
TOKEN_URL="http://${K3S_SERVER}:8800/k3s-token"
|
||||
MAX_RETRIES=30
|
||||
RETRY_DELAY=10
|
||||
|
||||
# Colors for console output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() { echo -e "${GREEN}[k3s-join]${NC} $*"; logger -t k3s-join "$*"; }
|
||||
warn() { echo -e "${YELLOW}[k3s-join]${NC} $*"; logger -t k3s-join -p warning "$*"; }
|
||||
error() { echo -e "${RED}[k3s-join]${NC} $*"; logger -t k3s-join -p err "$*"; }
|
||||
|
||||
# Wait for network to be ready
|
||||
wait_for_network() {
|
||||
local count=0
|
||||
while ! ping -c1 -W1 "$K3S_SERVER" &>/dev/null; do
|
||||
count=$((count + 1))
|
||||
if [ $count -ge $MAX_RETRIES ]; then
|
||||
error "Network not available after $MAX_RETRIES attempts"
|
||||
return 1
|
||||
fi
|
||||
warn "Waiting for network... ($count/$MAX_RETRIES)"
|
||||
sleep $RETRY_DELAY
|
||||
done
|
||||
log "Network is up"
|
||||
}
|
||||
|
||||
# Fetch join token from server
|
||||
fetch_token() {
|
||||
local count=0
|
||||
local token=""
|
||||
|
||||
while [ -z "$token" ]; do
|
||||
token=$(curl -sf "$TOKEN_URL" 2>/dev/null || true)
|
||||
if [ -z "$token" ]; then
|
||||
count=$((count + 1))
|
||||
if [ $count -ge $MAX_RETRIES ]; then
|
||||
error "Failed to fetch token after $MAX_RETRIES attempts"
|
||||
return 1
|
||||
fi
|
||||
warn "Waiting for token... ($count/$MAX_RETRIES)"
|
||||
sleep $RETRY_DELAY
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$token"
|
||||
}
|
||||
|
||||
# Main
|
||||
log "Starting K3s agent join process"
|
||||
|
||||
wait_for_network
|
||||
|
||||
log "Fetching join token from $TOKEN_URL"
|
||||
K3S_TOKEN=$(fetch_token)
|
||||
if [ -z "$K3S_TOKEN" ]; then
|
||||
error "Failed to get token, exiting"
|
||||
exit 1
|
||||
fi
|
||||
log "Token acquired"
|
||||
|
||||
log "Starting K3s agent (server: $K3S_URL)"
|
||||
exec /usr/local/bin/k3s agent \
|
||||
--server="$K3S_URL" \
|
||||
--token="$K3S_TOKEN" \
|
||||
--node-name="$(hostname)"
|
||||
@@ -1,26 +0,0 @@
|
||||
[Unit]
|
||||
Description=K3s Agent Join Service
|
||||
Documentation=file:///usr/local/bin/k3s-join
|
||||
|
||||
# Run after network and storage are ready
|
||||
After=network-online.target setup-node-storage.service
|
||||
Wants=network-online.target
|
||||
Requires=containerd.service
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
ExecStart=/usr/local/bin/k3s-join
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
|
||||
# Environment
|
||||
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
# Hardening
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=infinity
|
||||
LimitCORE=infinity
|
||||
TasksMax=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user