[nomad-step-0] S0.1-fix — bin/disinto swallows --backend=nomad as repo_url positional #835

Closed
opened 2026-04-16 08:25:35 +00:00 by dev-bot · 0 comments
Collaborator

Bugfix for S0.1 (#821). Discovered during Step 0 end-to-end verification on a fresh LXC.

Symptom

$ ./bin/disinto init --backend=nomad --empty
Error: --empty is only valid with --backend=nomad

The error is nonsensical — --backend=nomad is right there.

Root cause

bin/disintodisinto_init (around line 710) consumes the first positional arg as repo_url before the argparse while loop runs:

disinto_init() {
  local repo_url="${1:-}"
  if [ -z "$repo_url" ]; then
    echo "Error: repo URL required" >&2
    ...
  fi
  shift
  # ... then while-loop parses flags ...
}

So disinto init --backend=nomad --empty becomes:

  • repo_url = "--backend=nomad" (swallowed)
  • --empty seen by loop → empty=true
  • backend stays at default "docker"
  • Validation at line 747: empty=true && backend != "nomad" → error

Why repo_url is wrong for nomad

For --backend=nomad, the cluster-up flow doesn't clone anything — the LXC already has the repo cloned by the operator. repo_url is a docker-backend concept.

Fix

In disinto_init, move backend detection to before the repo_url consumption, and make repo_url conditional on backend=docker:

disinto_init() {
  # Pre-scan for --backend to know whether repo_url is required
  local backend="docker"
  for arg in "$@"; do
    case "$arg" in
      --backend) ;;                           # handled below
      --backend=*) backend="${arg#--backend=}" ;;
    esac
  done
  # Also handle space-separated form
  local i=1
  while [ $i -le $# ]; do
    if [ "${!i}" = "--backend" ]; then
      i=$((i+1))
      backend="${!i}"
    fi
    i=$((i+1))
  done

  local repo_url=""
  if [ "$backend" = "docker" ]; then
    repo_url="${1:-}"
    if [ -z "$repo_url" ] || [[ "$repo_url" == --* ]]; then
      echo "Error: repo URL required for docker backend" >&2
      echo "Usage: disinto init <repo-url> [options]" >&2
      exit 1
    fi
    shift
  fi
  # ... rest of argparse unchanged, it re-reads --backend cleanly

Simpler alternative: if first arg starts with --, assume no positional and skip repo_url consumption entirely (covers nomad + any future --help-style invocation).

Either shape is fine; pick the cleaner one.

Acceptance criteria

  • ./bin/disinto init --backend=nomad --empty runs lib/init/nomad/cluster-up.sh without error on a clean LXC.
  • ./bin/disinto init --backend=nomad --empty --dry-run prints the 9-step plan and exits 0.
  • ./bin/disinto init <repo-url> (docker path) behaves identically to today — existing smoke path passes.
  • ./bin/disinto init (no args, docker implied) still errors with the "repo URL required" message.
  • ./bin/disinto init --backend=docker (no repo) errors helpfully — not "Unknown option: --backend=docker".
  • shellcheck clean.

Verified regression case from Step 0 testing

On a fresh Ubuntu 24.04 LXC, after ./lib/init/nomad/cluster-up.sh was invoked directly (workaround), the cluster came up healthy end-to-end:

  • Nomad node status: 1 node ready
  • Vault status: Sealed=false, Initialized=true
  • Re-run of cluster-up.sh was fully idempotent

So the bug is isolated to bin/disinto argparse; the rest of the Step 0 code path is solid. This fix unblocks the formal Step 0 acceptance test.

Labels / meta

  • [nomad-step-0] S0.1-fix — no dependencies; gates Step 1.

Affected files

  • bin/disintodisinto_init() function, around line 710: pre-scan for --backend before consuming repo_url positional argument
Bugfix for S0.1 (#821). Discovered during Step 0 end-to-end verification on a fresh LXC. ## Symptom ``` $ ./bin/disinto init --backend=nomad --empty Error: --empty is only valid with --backend=nomad ``` The error is nonsensical — `--backend=nomad` is right there. ## Root cause `bin/disinto` → `disinto_init` (around line 710) consumes the first positional arg as `repo_url` **before** the argparse `while` loop runs: ```bash disinto_init() { local repo_url="${1:-}" if [ -z "$repo_url" ]; then echo "Error: repo URL required" >&2 ... fi shift # ... then while-loop parses flags ... } ``` So `disinto init --backend=nomad --empty` becomes: - `repo_url = "--backend=nomad"` (swallowed) - `--empty` seen by loop → `empty=true` - `backend` stays at default `"docker"` - Validation at line 747: `empty=true && backend != "nomad"` → error ## Why repo_url is wrong for nomad For `--backend=nomad`, the cluster-up flow doesn't clone anything — the LXC already has the repo cloned by the operator. `repo_url` is a docker-backend concept. ## Fix In `disinto_init`, move backend detection to **before** the `repo_url` consumption, and make `repo_url` conditional on `backend=docker`: ```bash disinto_init() { # Pre-scan for --backend to know whether repo_url is required local backend="docker" for arg in "$@"; do case "$arg" in --backend) ;; # handled below --backend=*) backend="${arg#--backend=}" ;; esac done # Also handle space-separated form local i=1 while [ $i -le $# ]; do if [ "${!i}" = "--backend" ]; then i=$((i+1)) backend="${!i}" fi i=$((i+1)) done local repo_url="" if [ "$backend" = "docker" ]; then repo_url="${1:-}" if [ -z "$repo_url" ] || [[ "$repo_url" == --* ]]; then echo "Error: repo URL required for docker backend" >&2 echo "Usage: disinto init <repo-url> [options]" >&2 exit 1 fi shift fi # ... rest of argparse unchanged, it re-reads --backend cleanly ``` Simpler alternative: if first arg starts with `--`, assume no positional and skip repo_url consumption entirely (covers nomad + any future `--help`-style invocation). Either shape is fine; pick the cleaner one. ## Acceptance criteria - [ ] `./bin/disinto init --backend=nomad --empty` runs `lib/init/nomad/cluster-up.sh` without error on a clean LXC. - [ ] `./bin/disinto init --backend=nomad --empty --dry-run` prints the 9-step plan and exits 0. - [ ] `./bin/disinto init <repo-url>` (docker path) behaves identically to today — existing smoke path passes. - [ ] `./bin/disinto init` (no args, docker implied) still errors with the "repo URL required" message. - [ ] `./bin/disinto init --backend=docker` (no repo) errors helpfully — not "Unknown option: --backend=docker". - [ ] shellcheck clean. ## Verified regression case from Step 0 testing On a fresh Ubuntu 24.04 LXC, after `./lib/init/nomad/cluster-up.sh` was invoked directly (workaround), the cluster came up healthy end-to-end: - Nomad node status: 1 node ready - Vault status: Sealed=false, Initialized=true - Re-run of cluster-up.sh was fully idempotent So the bug is isolated to `bin/disinto` argparse; the rest of the Step 0 code path is solid. This fix unblocks the formal Step 0 acceptance test. ## Labels / meta - `[nomad-step-0] S0.1-fix` — no dependencies; gates Step 1. ## Affected files - `bin/disinto` — `disinto_init()` function, around line 710: pre-scan for `--backend` before consuming `repo_url` positional argument
dev-bot added the
backlog
label 2026-04-16 08:25:35 +00:00
dev-bot self-assigned this 2026-04-16 09:14:04 +00:00
dev-bot added
in-progress
and removed
backlog
labels 2026-04-16 09:14:04 +00:00
dev-bot removed their assignment 2026-04-16 09:31:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: disinto-admin/disinto#835
No description provided.