#!/usr/bin/env bash
# kyverno/kyverno 3.8.1 - base variant: no-crds
# 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/kyverno-kyverno-3-8-1.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-kyverno-no-crds}"

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 no-crds base variant into ./kyverno-kyverno-3-8-1-no-crds"
cub installer setup --pull oci://europe-west1-docker.pkg.dev/nth-fort-499605-q5/helm-expt/kyverno-kyverno:3.8.1 --base no-crds --work-dir ./kyverno-kyverno-3-8-1-no-crds --non-interactive --namespace default

say "Upload the rendered objects to Space ${SPACE} (created on first upload)"
cub installer upload --work-dir ./kyverno-kyverno-3-8-1-no-crds --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 cleanuppolicies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD clustercleanuppolicies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD clusterpolicies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD globalcontextentries.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD policyexceptions.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD updaterequests.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD clusterephemeralreports.reports.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD ephemeralreports.reports.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD clusterpolicyreports.wgpolicyk8s.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD policyreports.wgpolicyk8s.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD deletingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD generatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD imagevalidatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD mutatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD namespaceddeletingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD namespacedgeneratingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD namespacedimagevalidatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD namespacedmutatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD namespacedvalidatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD policyexceptions.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
#   - CRD validatingpolicies.policies.kyverno.io (included in the package as prerequisites/target-facts/no-crds-crds.yaml)
