#!/usr/bin/env bash
# nvidia/k8s-nim-operator 3.1.2 - base variant: default
# 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/nvidia-k8s-nim-operator-3-1-2.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-k8s-nim-operator-default}"

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 default base variant into ./nvidia-k8s-nim-operator-3-1-2-default"
cub installer setup --pull oci://europe-west1-docker.pkg.dev/nth-fort-499605-q5/helm-expt/nvidia-k8s-nim-operator:3.1.2@sha256:3539d06bc051040cc6afd8759af2a5b406a5d2f2a79a7a8621918da92de2e93d --base default --work-dir ./nvidia-k8s-nim-operator-3-1-2-default --non-interactive --namespace nvidia-nim

say "Upload the rendered objects to Space ${SPACE} (created on first upload)"
cub installer upload --work-dir ./nvidia-k8s-nim-operator-3-1-2-default --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 nemocustomizers.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nemodatastores.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nemoentitystores.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nemoevaluators.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nemoguardrails.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nimbuilds.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nimcaches.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nimpipelines.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
#   - CRD nimservices.apps.nvidia.com (included in the package as prerequisites/target-facts/default-crds.yaml)
