Allow to deploy with custom kubernetes runtime

Related-Prod: PRODX-42391

Change-Id: I20c6cc7a8f5a6e19cea66e158a781a9f7394187d
diff --git a/de/heat-templates/scripts/functions.sh b/de/heat-templates/scripts/functions.sh
index 404c0bc..7e089cb 100644
--- a/de/heat-templates/scripts/functions.sh
+++ b/de/heat-templates/scripts/functions.sh
@@ -115,7 +115,7 @@
 function install_pkgs {
     local pkgs="$@"
     function _retry_install {
-        apt update && DEBIAN_FRONTEND=noninteractive apt install -y $pkgs
+        apt update && DEBIAN_FRONTEND=noninteractive apt install -o DPkg::Options::=--force-confdef -y $pkgs
     }
     retry 10 "Labeling node failed" _retry_install
 }
@@ -221,6 +221,11 @@
         curl --retry 6 --retry-delay 5 -fsSL "${DOCKER_EE_URL}/gpg" | sudo apt-key add -
         add-apt-repository "deb [arch=amd64] ${DOCKER_EE_URL}/ ${OS_CODENAME} ${DOCKER_EE_RELEASE}"
         install_pkgs ${DOCKER_EE_PACKAGES}
+        if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then
+            NERDCTL_VERSION=1.7.6
+            curl --retry 6 --retry-delay 5 -fsSL https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz --output nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz
+            tar zxvf nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz -C /usr/local/bin
+        fi
     }
     retry 10 "Failed to install docker" install_retry
 }
@@ -241,11 +246,37 @@
 }
 EOF
 
+    if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then
+        mkdir -p /etc/containerd/
+cat <<EOF> /etc/containerd/config.toml
+disabled_plugins = []
+
+#root = "/var/lib/containerd"
+#state = "/run/containerd"
+#subreaper = true
+#oom_score = 0
+
+#[grpc]
+#  address = "/run/containerd/containerd.sock"
+#  uid = 0
+#  gid = 0
+
+#[debug]
+#  address = "/run/containerd/debug.sock"
+#  uid = 0
+#  gid = 0
+#  level = "info"
+EOF
+    fi
+
 }
 
 function pull_image {
     local image="$1"
     function pull_image_retry {
+        if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then
+            nerdctl --address  unix:///run/containerd/containerd.sock -n k8s.io pull $image
+        fi
         docker pull ${image}
     }
     retry 10 "Can't pool docker image $image" pull_image_retry
@@ -259,6 +290,9 @@
     local image_prefix=${DOCKER_UCP_IMAGE%/*}
     for image in $(docker container run --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_UCP_IMAGE} images --list); do
         pull_image "${image_prefix}/${image##*/}"
+        if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then
+            nerdctl --address  unix:///run/containerd/containerd.sock -n k8s.io  tag ${image_prefix}/${image##*/} mirantis/${image##*/}
+        fi
         docker tag ${image_prefix}/${image##*/} mirantis/${image##*/}
     done
 }
@@ -396,6 +430,10 @@
         secure_overlay="secure_overlay = true
     calico_vxlan = false"
     fi
+    kubelet_custom_flags=""
+    if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then
+        kubelet_custom_flags='custom_kubelet_flags=["--container-runtime-endpoint=unix:///run/containerd/containerd.sock"]'
+    fi
     if docker config ls | grep com.docker.ucp.config ; then
         echo "Config com.docker.ucp.config already exists"
     else
@@ -408,6 +446,7 @@
     calico_vxlan_port = \"$UCP_DOCKER_CALICO_VXLAN_PORT\"
     ${max_pods}
     ${secure_overlay}
+    ${kubelet_custom_flags}
 " | docker config create com.docker.ucp.config -
     fi
 }