#!/usr/bin/env bash
# fake ssh for phase-06-kubeconfig-gate.sh: only the 'sudo k8s config' pull is used.
# Emits a kubeconfig whose server is the TENANT IP (10.20.0.207) -- the exact
# DOCFIX-062 defect the script must rewrite to the FIP.
# Steered by env: PULL_FAIL PULL_EMPTY PULL_BADHEAD.
want_config=0
for a in "$@"; do case "$a" in *"k8s config"*) want_config=1;; esac; done
if [ "$want_config" = 1 ]; then
  [ "${PULL_FAIL:-0}" = 1 ] && exit 1
  [ "${PULL_EMPTY:-0}" = 1 ] && exit 0
  if [ "${PULL_BADHEAD:-0}" = 1 ]; then echo "not-a-kubeconfig"; exit 0; fi
  cat <<'KC'
apiVersion: v1
clusters:
- cluster:
    server: https://10.20.0.207:6443
  name: k8s
contexts:
- context:
    cluster: k8s
    user: admin
  name: k8s
current-context: k8s
kind: Config
users:
- name: admin
KC
fi
exit 0
