#!/usr/bin/env bash

set -euo pipefail

ns=$1
pod_name=$2
SA=${SA:-"central"}

if [[ ! ${ns} ]]; then
  echo "the central ns must be specifies"
  exit 1
elif [[ ${ns} == "infra" ]]; then
  SA="aws-provider-upstream" 
fi
if [[ ! ${pod_name} ]]; then
  echo "pod name must be specified like ./cockpit.sh nightly my-bastion"
  exit 1
fi

kubectl run -n ${ns} ${pod_name} --restart=Never -it --rm --image overriden --overrides '
{
  "spec": {
    "serviceAccountName": "'"${SA}"'",
    "containers": [
      {
        "name": "cockpit",
        "stdin": true,
        "tty": true,
        "imagePullPolicy": "Always",
        "image": "gcr.io/pingcap-public/cockpit:latest"
      }
    ]
  }
}' --attach
