#! /usr/bin/env bash
set -euo pipefail

# Copied from https://kind.sigs.k8s.io/docs/user/local-registry/
function kind-init() {
    # Check if the xaccount cluster is already created
    if kind get clusters | grep -q 'xaccount'; then
	echo "xaccount cluster already exists"
        return
    fi
    # Create a cluster with the local registry enabled in containerd
    cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: xaccount
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30950
    hostPort: 443
- role: worker
- role: worker
EOF
}

export PULUMI_CONFIG_PASSPHRASE=""
kind-init
