#!/usr/bin/env bash
# eks/aws-efa-k8s-device-plugin v0.5.29 - base variant: default
# Path: pull the package, render this base variant locally, read the objects,
# then apply them with kubectl. No ConfigHub account is needed.
# 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/eks-aws-efa-k8s-device-plugin-v0-5-29.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

if ! command -v kubectl >/dev/null 2>&1; then
  printf 'kubectl is required for the apply step.\n' >&2
  exit 1
fi

say "Pull the package and render the default base variant into ./eks-aws-efa-k8s-device-plugin-v0-5-29-default"
cub installer setup --pull oci://europe-west1-docker.pkg.dev/nth-fort-499605-q5/helm-expt/eks-aws-efa-k8s-device-plugin:v0.5.29@sha256:5ae84f9bb5ee745360393d7b9b3f4955f37ec75503f5f7b26ae0bc2c287ce24c --base default --work-dir ./eks-aws-efa-k8s-device-plugin-v0-5-29-default --non-interactive --namespace kube-system

say "Read what was rendered; nothing has touched the cluster yet"
ls ./eks-aws-efa-k8s-device-plugin-v0-5-29-default/out/manifests

say "Ensure the kube-system namespace exists"
kubectl create namespace kube-system --dry-run=client -o yaml | kubectl apply -f -

if [ -d ./eks-aws-efa-k8s-device-plugin-v0-5-29-default/out/secrets ]; then
  say "Apply rendered Secrets first"
  kubectl apply -f ./eks-aws-efa-k8s-device-plugin-v0-5-29-default/out/secrets
fi

say "Apply the rendered objects"
kubectl apply -f ./eks-aws-efa-k8s-device-plugin-v0-5-29-default/out/manifests

say "Done. The cluster received exactly the files in ./eks-aws-efa-k8s-device-plugin-v0-5-29-default/out."
