mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 18:34:31 +00:00
Repairs and improvements:
- iSCSI: Added cleanup tasks to remove stale mounts and fstab entries. Improved robustness of iSCSI target management and added 'iscsi_absent_mounts' support.
- K3s:
- Updated service start logic to accept 'activating' state, preventing premature failure during slow startups.
- Improved service stop logic to safely handle missing or not-found services.
- Ensured 'prole-installer' ServiceAccount and ClusterRoleBinding exist for K8s administration.
- Added leader election and etcd tuning arguments (forgiving leases) to config.yaml.j2.
- Removed deprecated 'prole-port-forwards' systemd service.
- Installer & Scripts:
- Updated legacy_tk.py to support K3s mode, secret resolution for passwords, and better environment management (including ~/.prole/env.sh for service mode).
- Updated init_ansible.sh to support PROLE_VAULT_PASS_FILE and ANSIBLE_VAULT_PASSWORD_FILE.
- Improved directory and kubeconfig path resolution in prole_cfg.sh to support fallback to ~/.prole.
- Enhanced Grafana password resolution in init_monitoring.sh.
- Added automatic application of iSCSI StorageClass and PersistentVolumes in init_openbao.sh.
- General: Switched conf/prole.cfg to k3s deployment mode and updated vault_k3s.yml token.
New Ansible Tasks and Playbooks:
- infrastructure/playbooks/iscsi_cleanup.yml: Automates logout and removal of stale iSCSI node records.
- infrastructure/playbooks/prole_logs_migrate.yml: Orchestrates /prole/logs migration to iSCSI storage.
- infrastructure/playbooks/tmp_bao_dir.yml: Ensures host-level storage directories for OpenBao.
- infrastructure/playbooks/tmp_mount.yml: Utility to verify and enforce host-level mounts.
- infrastructure/playbooks/k3s_sync.yml: Added tasks to start K3s after sync and update local kubeconfig on the controller.
- Added 'Unmount stale iSCSI mounts' and 'Remove stale iSCSI fstab entries' to the iscsi role.
- Added 'Ensure prole-installer service account exists' to the k3s role.
82 lines
2.1 KiB
Bash
82 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Unit test for etc/init_ansible.sh
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
PROLE_HOME=$(cd "$SCRIPT_DIR/../.." && pwd)
|
|
ETC_DIR="$PROLE_HOME/etc"
|
|
SCRIPT_UNDER_TEST="$ETC_DIR/init_ansible.sh"
|
|
|
|
TMP_DIR=$(mktemp -d)
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
# Mock tools
|
|
mock_tool() {
|
|
cat <<M_EOF > "$TMP_DIR/$1"
|
|
#!/usr/bin/env bash
|
|
echo "Mocked $1 called with \$@" >> "$TMP_DIR/mock_calls.log"
|
|
exit 0
|
|
M_EOF
|
|
chmod +x "$TMP_DIR/$1"
|
|
}
|
|
|
|
# Create mocks for common tools
|
|
mock_tool kubectl
|
|
mock_tool curl
|
|
mock_tool docker
|
|
mock_tool k3d
|
|
mock_tool ansible-playbook
|
|
mock_tool tofu
|
|
mock_tool terraform
|
|
mock_tool ollama
|
|
mock_tool jq
|
|
|
|
# Mock prole.cfg
|
|
mkdir -p "$TMP_DIR/conf"
|
|
cat <<C_EOF > "$TMP_DIR/conf/prole.cfg"
|
|
[globals]
|
|
prole.home = $PROLE_HOME
|
|
prole.mode = k3d
|
|
[k3s]
|
|
server = https://localhost:6443
|
|
token = test-token
|
|
C_EOF
|
|
|
|
export PATH="$TMP_DIR:$PATH"
|
|
export PROLE_HOME="$PROLE_HOME"
|
|
export PROLE_CONF="$TMP_DIR/conf"
|
|
export NAMESPACE="test-ns"
|
|
export PROLE_PASSWD="test-password"
|
|
export PROLE_VAULT_PASS_FILE="$TMP_DIR/.vault_pass"
|
|
|
|
# Run the script
|
|
if [[ "init_ansible.sh" == *.py ]]; then
|
|
if [[ "init_ansible.sh" == "render_manifest.py" ]]; then
|
|
echo "apiVersion: v1" > "$TMP_DIR/test.yaml"
|
|
python3 "$SCRIPT_UNDER_TEST" "$TMP_DIR/test.yaml" > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr"
|
|
else
|
|
python3 "$SCRIPT_UNDER_TEST" --help > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr"
|
|
fi
|
|
RC=$?
|
|
else
|
|
# Check for usage() or if it's a script that likely needs arguments
|
|
if grep -q "usage()" "$SCRIPT_UNDER_TEST"; then
|
|
bash "$SCRIPT_UNDER_TEST" --help > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr"
|
|
RC=$?
|
|
else
|
|
# Try a few common non-destructive actions
|
|
bash "$SCRIPT_UNDER_TEST" status > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr" || \
|
|
bash "$SCRIPT_UNDER_TEST" --help > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr" || \
|
|
bash "$SCRIPT_UNDER_TEST" > "$TMP_DIR/stdout" 2> "$TMP_DIR/stderr"
|
|
RC=$?
|
|
fi
|
|
fi
|
|
|
|
if [[ $RC -eq 0 || $RC -eq 1 || $RC -eq 2 ]]; then
|
|
echo "SUCCESS (RC=$RC)"
|
|
exit 0
|
|
else
|
|
echo "FAILURE with RC $RC"
|
|
cat "$TMP_DIR/stderr"
|
|
exit 1
|
|
fi
|