# Copyright 2021 Kontain
# Derived from:
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
  name: kontain-install-entrypoint
  namespace: kube-system
  labels:
    app: kontain-init
data:
  entrypoint.sh: |
    #!/usr/bin/env bash

    set -x
    set -euo pipefail

    ROOT_MOUNT_DIR="${ROOT_MOUNT_DIR:-/root}"

    source /scripts-lib/kontain_install_lib.sh
    install_kontain_artifacts

    echo "Install Kontain Runtime Artifacts (KM & KRUN)"

    echo "Add Kontain Runtime to CRIO configuration"
    cat <<-EOT | tee -a /etc/crio/crio.conf.d/99-kontain-deploy
    	[crio.runtime.runtimes.krun]
    	runtime_path = "/opt/kontain/bin/krun"
    	runtime_type = "oci"
    	runtime_root = "/run/krun"
    EOT

    [ -c /root/dev/kvm ] && chmod 666 /root/dev/kvm

    echo "restart crio"
    systemctl daemon-reload
    systemctl restart crio

    sleep infinity
