#!/sbin/openrc-run # K3s agent (worker node). Env vars K3S_URL + K3S_TOKEN come from cloud-init # user-data — the orchestrator embeds them at RunInstances time per the # Nodegroup bootstrap flow (eks-v1.md Q14). # # K3S_URL points at the cluster's NLB endpoint (https://{cluster}.{account} # .eks.{region}.{suffix}:443) so the agent join path stays stable across the # v2 HA migration (single-VM v1 → 3-node etcd quorum v2). No AMI rebuild # needed when the control plane expands. description="K3s Kubernetes agent (Mulga EKS worker)" command="/usr/local/bin/k3s" command_args="agent" command_background="yes" pidfile="/run/k3s-agent.pid" output_log="/var/log/k3s-agent.log" error_log="/var/log/k3s-agent.log" start_stop_daemon_args="--wait 5000" depend() { need net cgroups after firewall } start_pre() { # Cloud-init drops these into /etc/spinifex-eks/agent.env. We source them # here (in addition to k3s-agent-prestart sourcing its own copy below) so # OpenRC exports them into k3s' environment when it spawns the daemon — # unlike systemd's EnvironmentFile=, OpenRC has no mechanism to inject an # env file into the daemon independent of what start_pre itself exports. if [ -f /etc/spinifex-eks/agent.env ]; then # shellcheck disable=SC1091 . /etc/spinifex-eks/agent.env export K3S_URL K3S_TOKEN K3S_NODE_NAME fi # k3s-agent-prestart reproduces the K3S_URL/K3S_TOKEN guard + IMDS # provider-id resolution this start_pre used to run inline, shared with # the systemd unit that will eventually replace this runscript. It writes # the resolved extra args to a /run env file for command_args below. if ! /usr/local/sbin/k3s-agent-prestart; then return 1 fi # shellcheck disable=SC1091 . /run/k3s-agent-extra-args.env 2>/dev/null || true command_args="agent ${K3S_AGENT_EXTRA_ARGS:-}" }