#!/usr/bin/env bash
# kai-scheduler/kai-scheduler v0.16.9 - base variant: aicr-eks-training
# Path: render this base variant locally, then upload the objects to your
# ConfigHub Space as Units you can edit, diff, and deliver.
# Needs a ConfigHub account: run cub auth login once before this script.
# Generated by scripts/generate-public-site.mjs from the committed package
# data for this base variant. Chart page: https://confighub.github.io/helm-expt/site/charts/kai-scheduler-kai-scheduler-v0-16-9.html
set -euo pipefail

say() { printf '\n>> %s\n' "$*"; }

if ! command -v cub >/dev/null 2>&1; then
  printf 'cub is not installed. Install the cub CLI with:\n  curl -fsSL https://hub.confighub.com/cub/install.sh | bash\nthen add ~/.confighub/bin to your PATH and re-run this script.\n' >&2
  exit 1
fi

# Installer is a cub plugin. Check it before this script does any work.
if ! cub installer --help >/dev/null 2>&1; then
  printf 'The cub installer plugin is missing. Follow https://confighub.github.io/helm-expt/site/try.html#install-cub, then re-run this script.\n' >&2
  exit 1
fi

if ! command -v kustomize >/dev/null 2>&1; then
  printf 'kustomize is missing. Follow https://confighub.github.io/helm-expt/site/try.html#install-cub, then re-run this script.\n' >&2
  exit 1
fi

SPACE="${CUB_SPACE:-helm-kai-scheduler-aicr-eks-training}"

say "Check ConfigHub auth"
if ! cub auth status >/dev/null 2>&1; then
  printf 'Not logged in. Run: cub auth login\nThen re-run this script.\n' >&2
  exit 1
fi

say "Render the aicr-eks-training base variant into ./kai-scheduler-kai-scheduler-v0-16-9-aicr-eks-training"
cub installer setup --pull oci://europe-west1-docker.pkg.dev/nth-fort-499605-q5/helm-expt/kai-scheduler-kai-scheduler:v0.16.9@sha256:7d360f97ada7c492e506acdd433c9212d21f5a6d26d8d8cbf1f0b68a268e94ab --base aicr-eks-training --work-dir ./kai-scheduler-kai-scheduler-v0-16-9-aicr-eks-training --non-interactive --namespace kai-scheduler

say "Upload the rendered objects to Space ${SPACE} (created on first upload)"
cub installer upload --work-dir ./kai-scheduler-kai-scheduler-v0-16-9-aicr-eks-training --space "${SPACE}"

say "Uploaded. See your Units:"
printf '  cub unit list --space %s\n  or open https://hub.confighub.com and find that Space.\n' "${SPACE}"

say "Next: create an environment variant and promote reviewed changes"
printf '  Walkthrough with the why behind each flag:\n  https://confighub.github.io/helm-expt/site/d/docs/user/variants-after-upload.html\n'

# Before applying this base variant from ConfigHub to a cluster, it still needs:
#   - CRD bindrequests.scheduling.run.ai (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
#   - CRD configs.kai.scheduler (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
#   - CRD podgroups.scheduling.run.ai (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
#   - CRD queues.scheduling.run.ai (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
#   - CRD schedulingshards.kai.scheduler (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
#   - CRD topologies.kai.scheduler (included in the package as prerequisites/target-facts/aicr-eks-training-crds.yaml)
