rig major updates
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
# Shared config loading: how the config layers compose. Sourced, never executed.
|
||||
# Precedence, weakest first: defaults < versions.env < env.d/<profile> < .env < caller's env.
|
||||
# Precedence, weakest first:
|
||||
# defaults < versions.env < env.d/<profile> < <overlay>/rig.env < .env < caller's env.
|
||||
# Run from ctrl/.
|
||||
# Notes: docs/notes/config.md
|
||||
|
||||
# Per-invocation overrides: restored after the files are read, so the caller wins.
|
||||
# NODES is deliberately not here (read from the kind config).
|
||||
CONFIG_OVERRIDABLE="PROFILE CLUSTER K8S_VERSION KIND_CONFIG ADDONS
|
||||
CONFIG_OVERRIDABLE="PROFILE OVERLAY CLUSTER K8S_VERSION KIND_CONFIG ADDONS
|
||||
REGISTRY_MODE INGRESS_MODE DNS_MODE TILT_PORT
|
||||
SOURCE ARCH DEPS_SOURCE HTTP_PORT HTTPS_PORT
|
||||
REGISTRY_PORT MANIFESTS_DIR"
|
||||
|
||||
# The repo folder's name, reduced to a DNS label kind accepts as a cluster name.
|
||||
# rig's own example, used when no overlay is named (relative to rig's root).
|
||||
DEFAULT_OVERLAY=examples/starter
|
||||
|
||||
# A rig-root-relative path as seen from ctrl/; absolute paths pass through.
|
||||
_from_ctrl() { case "$1" in /*) echo "$1" ;; *) echo "../$1" ;; esac; }
|
||||
|
||||
# The same, absolute. Empty if it does not exist.
|
||||
_abs_from_ctrl() { (cd "$(_from_ctrl "$1")" 2>/dev/null && pwd); }
|
||||
|
||||
# The environment's folder — the overlay's when one is named, else rig's —
|
||||
# reduced to a DNS label kind accepts as a cluster name.
|
||||
default_cluster_name() {
|
||||
local n
|
||||
n=$(basename "$(cd .. && pwd)")
|
||||
if [ -n "${OVERLAY:-}" ]; then
|
||||
n=$(basename "$(_abs_from_ctrl "$OVERLAY_DIR")")
|
||||
else
|
||||
n=$(basename "$(cd .. && pwd)")
|
||||
fi
|
||||
n=$(echo "$n" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9-' '-')
|
||||
n=$(echo "$n" | sed 's/^-*//; s/-*$//')
|
||||
echo "${n:-rig}"
|
||||
@@ -45,15 +60,59 @@ load_config() {
|
||||
_config_restore "$saved"
|
||||
|
||||
# A profile is optional; naming one that does not exist is an error.
|
||||
local profile="${PROFILE:-}"
|
||||
local profile="${PROFILE:-}" layered=""
|
||||
if [ -n "$profile" ] && [ "$profile" != default ]; then
|
||||
if [ ! -f "./env.d/${profile}.env" ]; then
|
||||
echo "no such profile: env.d/${profile}.env" >&2
|
||||
if [ -d "../examples/${profile}" ]; then
|
||||
echo " it is an example overlay now: OVERLAY=examples/${profile}" >&2
|
||||
fi
|
||||
echo "available: $(config_profiles | tr '\n' ' ')" >&2
|
||||
exit 1
|
||||
fi
|
||||
set -a
|
||||
source "./env.d/${profile}.env"
|
||||
set +a
|
||||
layered=1
|
||||
fi
|
||||
|
||||
# The overlay: one folder, outside rig, holding a use case (docs/notes/overlay.md).
|
||||
# Named ones must exist; with none named, rig's own example is used if present.
|
||||
OVERLAY_DIR=""
|
||||
if [ -n "${OVERLAY:-}" ]; then
|
||||
OVERLAY_DIR="${OVERLAY%/}"
|
||||
if [ ! -d "$(_from_ctrl "$OVERLAY_DIR")" ]; then
|
||||
echo "no overlay at OVERLAY=${OVERLAY} (relative to rig's folder, or absolute)" >&2
|
||||
exit 1
|
||||
fi
|
||||
elif [ -d "../${DEFAULT_OVERLAY}" ]; then
|
||||
OVERLAY_DIR="$DEFAULT_OVERLAY"
|
||||
fi
|
||||
# Its rig.env may not choose the profile or the overlay (both are chosen before
|
||||
# it loads), and the paths it sets are relative to the overlay.
|
||||
local ov_env="" m_before k_before
|
||||
if [ -n "$OVERLAY_DIR" ]; then ov_env="$(_from_ctrl "$OVERLAY_DIR")/rig.env"; fi
|
||||
if [ -n "$ov_env" ] && [ -f "$ov_env" ]; then
|
||||
if grep -qE '^[[:space:]]*(export[[:space:]]+)?(PROFILE|OVERLAY)=' "$ov_env"; then
|
||||
echo "$ov_env: an overlay's rig.env cannot set PROFILE or OVERLAY (they choose it)" >&2
|
||||
exit 1
|
||||
fi
|
||||
m_before="${MANIFESTS_DIR-}" k_before="${KIND_CONFIG-}"
|
||||
set -a
|
||||
source "$ov_env"
|
||||
set +a
|
||||
if [ "${MANIFESTS_DIR-}" != "$m_before" ]; then
|
||||
case "$MANIFESTS_DIR" in /*|none|"") ;; *) MANIFESTS_DIR="${OVERLAY_DIR}/${MANIFESTS_DIR}" ;; esac
|
||||
fi
|
||||
if [ "${KIND_CONFIG-}" != "$k_before" ]; then
|
||||
case "$KIND_CONFIG" in /*|"") ;; *) KIND_CONFIG="$(dirname "$ov_env")/${KIND_CONFIG}" ;; esac
|
||||
fi
|
||||
layered=1
|
||||
fi
|
||||
|
||||
# The machine and the caller still win over both.
|
||||
if [ -n "$layered" ]; then
|
||||
set -a
|
||||
if [ -z "${RIG_PORTABLE:-}" ] && [ -f ./.env ]; then source ./.env; fi
|
||||
set +a
|
||||
_config_restore "$saved"
|
||||
@@ -86,9 +145,25 @@ load_config() {
|
||||
TILT_PORT="${TILT_PORT:-$((base + 2))}"
|
||||
REGISTRY_PORT="${REGISTRY_PORT:-$((base + 3))}"
|
||||
|
||||
# Where the workload's manifests live, repo-root relative; always resolved.
|
||||
# See k8s/README.md.
|
||||
MANIFESTS_DIR="${MANIFESTS_DIR:-ctrl/k8s/overlays/dev}"
|
||||
# Where the workload's manifests live, relative to rig's folder (or absolute):
|
||||
# the overlay's k8s/overlays/dev unless something names another. `none`: rig
|
||||
# applies none (the overlay's Tiltfile does). A named folder must exist.
|
||||
if [ "${MANIFESTS_DIR:-}" = ctrl/k8s/overlays/dev ] && [ ! -d ../ctrl/k8s/overlays/dev ]; then
|
||||
# The old default, pinned by an older .env.example; rig's examples moved.
|
||||
STALE_MANIFESTS_DIR="$MANIFESTS_DIR"
|
||||
MANIFESTS_DIR=""
|
||||
fi
|
||||
if [ -z "${MANIFESTS_DIR:-}" ] && [ -n "$OVERLAY_DIR" ] \
|
||||
&& [ -d "$(_from_ctrl "$OVERLAY_DIR")/k8s/overlays/dev" ]; then
|
||||
MANIFESTS_DIR="$OVERLAY_DIR/k8s/overlays/dev"
|
||||
fi
|
||||
MANIFESTS_DIR="${MANIFESTS_DIR:-}"
|
||||
if [ "$MANIFESTS_DIR" = none ]; then
|
||||
MANIFESTS_DIR=""
|
||||
elif [ -n "$MANIFESTS_DIR" ] && [ ! -d "$(_from_ctrl "$MANIFESTS_DIR")" ]; then
|
||||
echo "no manifests at MANIFESTS_DIR=${MANIFESTS_DIR} (relative to rig's folder, or absolute)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Profiles name a k8s minor (v1_36); versions.env holds the pinned digest.
|
||||
local var="NODE_IMAGE_${K8S_VERSION}"
|
||||
@@ -98,9 +173,13 @@ load_config() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The cluster is one file: k8s/kind-config.yaml.tpl. To change it, edit it.
|
||||
# KIND_CONFIG is only "use this file instead", for a project that builds its
|
||||
# own cluster through rig (a path relative to ctrl/, or absolute).
|
||||
# The cluster is one file: the overlay's kind-config.yaml.tpl if it has one,
|
||||
# else rig's k8s/kind-config.yaml.tpl. KIND_CONFIG is "use this file instead",
|
||||
# for a project that builds its own cluster through rig (relative to ctrl/, or absolute).
|
||||
if [ -z "${KIND_CONFIG:-}" ] && [ -n "$OVERLAY_DIR" ] \
|
||||
&& [ -f "$(_from_ctrl "$OVERLAY_DIR")/kind-config.yaml.tpl" ]; then
|
||||
KIND_CONFIG="$(_from_ctrl "$OVERLAY_DIR")/kind-config.yaml.tpl"
|
||||
fi
|
||||
KIND_CONFIG="${KIND_CONFIG:-./k8s/kind-config.yaml.tpl}"
|
||||
if [ ! -f "$KIND_CONFIG" ]; then
|
||||
echo "no kind config at KIND_CONFIG=${KIND_CONFIG}" >&2
|
||||
@@ -117,13 +196,15 @@ load_config() {
|
||||
}
|
||||
|
||||
# Render the kind config to stdout with sed (not envsubst) over an explicit variable list.
|
||||
# HOST_WORKDIR must be a host path: the host dockerd resolves hostPath entries.
|
||||
# HOST_WORKDIR and OVERLAY_DIR must be host paths: the host dockerd resolves hostPath entries.
|
||||
render_kind_config() {
|
||||
local host_workdir="${HOST_WORKDIR:-$(cd .. && pwd)}"
|
||||
local host_workdir="${HOST_WORKDIR:-$(cd .. && pwd)}" overlay_dir=""
|
||||
if [ -n "$OVERLAY_DIR" ]; then overlay_dir=$(_abs_from_ctrl "$OVERLAY_DIR"); fi
|
||||
sed -e "s|\${CLUSTER}|${CLUSTER}|g" \
|
||||
-e "s|\${NODE_IMAGE}|${NODE_IMAGE}|g" \
|
||||
-e "s|\${HTTP_PORT}|${HTTP_PORT}|g" \
|
||||
-e "s|\${HOST_WORKDIR}|${host_workdir}|g" \
|
||||
-e "s|\${OVERLAY_DIR}|${overlay_dir}|g" \
|
||||
"$KIND_CONFIG"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user