{% if not embedded -%}
{% include "bash.sh.j2" %}
{% endif %}

{% macro kubeadm(cache_only=False) -%}
{%- if cache_only -%}
tar -f archive_reportsector.tar --append registry-*
{% endif %}

{%- if not cache_only -%}

# https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/
cat >kubeadm-config.yaml <<EOF
kind: ClusterConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kubernetesVersion: v1.26.1
---
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
EOF
kubeadm config images list

sleep 5

# https://stackoverflow.com/a/69995137/1495086
for image in registry-*; do
    sudo ctr -n=k8s.io images import $image
    # nerdctl load -i $image
done

sudo kubeadm init --v=10 --config kubeadm-config.yaml
{% endif %}
{% endmacro %}

{% block content %}{{ kubeadm(cache_only) }}{% endblock %}
