<commit_before>#!/bin/bash
set -e

# shellcheck disable=SC2154
/usr/bin/docker run \
    --volume "$(pwd)":/assets \
    --volume /etc/kubernetes:/etc/kubernetes \
    "${kube_core_renderer_image}" \
    --config=/assets/kco-config.yaml \
    --output=/assets

# shellcheck disable=SC2154
/usr/bin/docker run \
    --user 0 \
    --volume "$(pwd)":/assets \
    "${tnc_operator_image}" \
    --config=/assets/tnco-config.yaml \
    --render-bootstrap=true \
    --render-output=/assets/tnc-bootstrap

mkdir -p /etc/kubernetes/manifests/
cp "$(pwd)/tnc-bootstrap/tectonic-node-controller-pod.yaml" /etc/kubernetes/manifests/
cp "$(pwd)/tnc-bootstrap/tectonic-node-controller-config.yaml" /etc/kubernetes/tnc-config

# We originally wanted to run the etcd cert signer as
# a static pod, but kubelet could't remove static pod
# when API server is not up, so we have to run this as
# docker container.
# See https://github.com/kubernetes/kubernetes/issues/43292

# shellcheck disable=SC2154,SC2034
signer_id=$(/usr/bin/docker run -d \
    --tmpfs /tmp \
    --volume /opt/tectonic/tls:/opt/tectonic/tls:ro \
    --network host \
    "${etcd_cert_signer_image}" \
    serve \
    --cacrt=/opt/tectonic/tls/etcd-client-ca.crt \
    --cakey=/opt/tectonic/tls/etcd-client-ca.key \
    --servcrt=/opt/tectonic/tls/apiserver.crt \
    --servkey=/opt/tectonic/tls/apiserver.key \
    --address=0.0.0.0:6443 \
    --csrdir=/tmp \
    --peercertdur=26280h \
    --servercertdur=26280h)

# Wait for the etcd cluster to come up.
export ETCDCTL_API=3
# shellcheck disable=SC2154,SC2086
/usr/bin/etcdctl \
    --dial-timeout=10m \
    --cacert=/opt/tectonic/tls/etcd-client-ca.crt \
    --cert=/opt/tectonic/tls/etcd-client.crt \
    --key=/opt/tectonic/tls/etcd-client.key \
    --endpoints=${etcd_cluster} \
    endpoint health
export ETCDCTL_API=

# shellcheck disable=SC2154,SC1083
/usr/bin/docker kill $${signer_id}
rm /etc/kubernetes/manifests/tectonic-node-controller-pod.yaml

cp -r "$(pwd)/bootstrap-configs" /etc/kubernetes/bootstrap-configs

# shellcheck disable=SC2154
/usr/bin/docker run \
    --volume "$(pwd)":/assets \
    --volume /etc/kubernetes:/etc/kubernetes \
    --network=host \
    --entrypoint=/bootkube \
    "${bootkube_image}" \
    start --asset-dir=/assets<commit_msg>modules/bootkube: make service more robust<commit_after>#!/bin/bash
set -e

echo "Rendering Kubernetes core manifests..."

# shellcheck disable=SC2154
/usr/bin/docker run \
    --volume "$(pwd)":/assets \
    --volume /etc/kubernetes:/etc/kubernetes \
    "${kube_core_renderer_image}" \
    --config=/assets/kco-config.yaml \
    --output=/assets

echo "Rendering TNC manifests..."

# shellcheck disable=SC2154
/usr/bin/docker run \
    --user 0 \
    --volume "$(pwd)":/assets \
    "${tnc_operator_image}" \
    --config=/assets/tnco-config.yaml \
    --render-bootstrap=true \
    --render-output=/assets/tnc-bootstrap

mkdir -p /etc/kubernetes/manifests/
cp "$(pwd)/tnc-bootstrap/tectonic-node-controller-pod.yaml" /etc/kubernetes/manifests/
cp "$(pwd)/tnc-bootstrap/tectonic-node-controller-config.yaml" /etc/kubernetes/tnc-config

# We originally wanted to run the etcd cert signer as
# a static pod, but kubelet could't remove static pod
# when API server is not up, so we have to run this as
# docker container.
# See https://github.com/kubernetes/kubernetes/issues/43292

echo "Starting etcd certificate signer..."

# shellcheck disable=SC2154,SC2034
signer_id=$(/usr/bin/docker run -d \
    --tmpfs /tmp \
    --volume /opt/tectonic/tls:/opt/tectonic/tls:ro \
    --network host \
    "${etcd_cert_signer_image}" \
    serve \
    --cacrt=/opt/tectonic/tls/etcd-client-ca.crt \
    --cakey=/opt/tectonic/tls/etcd-client-ca.key \
    --servcrt=/opt/tectonic/tls/apiserver.crt \
    --servkey=/opt/tectonic/tls/apiserver.key \
    --address=0.0.0.0:6443 \
    --csrdir=/tmp \
    --peercertdur=26280h \
    --servercertdur=26280h)

echo "Waiting for etcd cluster..."

# Wait for the etcd cluster to come up.
export ETCDCTL_API=3

i=0
while true; do
    set +e
    # shellcheck disable=SC2154,SC2086
    /usr/bin/etcdctl \
        --dial-timeout=10m \
        --cacert=/opt/tectonic/tls/etcd-client-ca.crt \
        --cert=/opt/tectonic/tls/etcd-client.crt \
        --key=/opt/tectonic/tls/etcd-client.key \
        --endpoints=${etcd_cluster} \
        endpoint health
    status=$?
    set -e

    if [ "$status" -eq 0 ]; then
      break
    fi

    i=$((i+1))
    [ $i -eq 10 ] && echo "etcdctl failed too many times." && exit 1

    echo "etcdctl failed. Retrying in 5 seconds..."
    sleep 5
done

export ETCDCTL_API=

echo "etcd cluster up. Killing etcd certificate signer..."

# shellcheck disable=SC2154,SC1083
/usr/bin/docker kill $${signer_id}
rm /etc/kubernetes/manifests/tectonic-node-controller-pod.yaml

cp -r "$(pwd)/bootstrap-configs" /etc/kubernetes/bootstrap-configs

echo "Starting bootkube..."

# shellcheck disable=SC2154
/usr/bin/docker run \
    --volume "$(pwd)":/assets \
    --volume /etc/kubernetes:/etc/kubernetes \
    --network=host \
    --entrypoint=/bootkube \
    "${bootkube_image}" \
    start --asset-dir=/assets
{'fraction_non_alphanumeric': 0.15930752771834272, 'fraction_numerical': 0.026064967905076834, 'mean_word_length': 2.747813411078717, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6424048', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1876, 'n_words': 347}