# 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-lib
  namespace: kube-system
  labels:
    app: kontain-init
data:
  kontain_install_lib.sh: |
    #!/usr/bin/env bash

    # This will get overridden be ENV definition in kontain-deploy.yaml
    KONTAIN_RELEASE_URL="${KONTAIN_RELEASE_URL:-https://github.com/kontainapp/km/releases/download/latest/kontain_bin.tar.gz}"

    function install_kontain_artifacts() {
      echo "Install Kontain Runtime Artifacts (KM & KRUN)"
      mkdir /kontain-artifacts
      curl -L "${KONTAIN_RELEASE_URL}" | tar -xzf - -C /kontain-artifacts
      mkdir -p /root/opt/kontain/bin
      cp /kontain-artifacts/km/km /root/opt/kontain/bin/km
      chmod +x /root/opt/kontain/bin/km
      cp /kontain-artifacts/container-runtime/krun /root/opt/kontain/bin/krun
      chmod +x /root/opt/kontain/bin/krun
      mkdir -p /root/opt/kontain/shim
      cp /kontain-artifacts/cloud/k8s/deploy/shim/containerd-shim-krun-v2 /root/opt/kontain/shim/containerd-shim-krun-v2
      chmod +x /root/opt/kontain/shim/containerd-shim-krun-v2
      cp /kontain-artifacts/cloud/k8s/deploy/shim/containerd-shim-krun-v2 /root/usr/local/bin/containerd-shim-krun-v2
      chmod +x /root/usr/local/bin/containerd-shim-krun-v2
    }
