Browse Source

Add support for CRI-O as container engine

This commit adds support for CRI-O. Support for Fedora/CentOS is in
progress.

Change-Id: Ib049d66058429e499f5d0932c4a749820bec73ff
Michał Dulko 5 months ago
parent
commit
63c7b8eddc
3 changed files with 109 additions and 0 deletions
  1. 101
    0
      devstack/lib/crio
  2. 7
    0
      devstack/plugin.sh
  3. 1
    0
      devstack/settings

+ 101
- 0
devstack/lib/crio View File

@@ -0,0 +1,101 @@
1
+#!/bin/bash
2
+
3
+# Dependencies:
4
+#
5
+# - functions
6
+
7
+# stack.sh
8
+# ---------
9
+# - check_crio
10
+# - install_crio
11
+# - configure_crio
12
+# - stop_crio
13
+
14
+# Save trace setting
15
+_XTRACE_DOCKER=$(set +o | grep xtrace)
16
+set +o xtrace
17
+
18
+
19
+# Defaults
20
+# --------
21
+
22
+CRIO_ENGINE_SOCKET_FILE=${CRIO_ENGINE_SOCKET_FILE:-/var/run/crio/crio.sock}
23
+
24
+# Functions
25
+# ---------
26
+
27
+function check_crio {
28
+    if is_ubuntu; then
29
+       dpkg -l | grep crio-o > /dev/null 2>&1
30
+    else
31
+       false
32
+       # TODO: CentOS/Fedora support.
33
+    fi
34
+}
35
+
36
+function install_crio {
37
+    if [[ -z "$os_PACKAGE" ]]; then
38
+        GetOSVersion
39
+    fi
40
+
41
+    local lsb_dist=${os_VENDOR,,}
42
+    local dist_version=${os_CODENAME}
43
+    local arch=$(dpkg --print-architecture)
44
+    if is_ubuntu; then
45
+        apt_get install apt-transport-https ca-certificates software-properties-common
46
+        sudo add-apt-repository -y ppa:projectatomic/ppa
47
+        # Installing podman and containerd will get us compatible versions of
48
+        # cri-o and runc. And we need podman to manage container images anyway.
49
+        apt_get install podman buildah
50
+    elif is_fedora; then
51
+        false
52
+        # TODO(dulek): CentOS/Fedora support
53
+    fi
54
+}
55
+
56
+function configure_crio {
57
+    # After an ./unstack it will be stopped. So it is ok if it returns exit-code == 1
58
+    sudo systemctl stop crio.service || true
59
+
60
+    local crio_conf
61
+    crio_conf=/etc/crio/crio.conf
62
+
63
+    # We're wrapping values in "\<val>\" because that's the format cri-o wants.
64
+    iniset -sudo ${crio_conf} crio.api listen \"${CRIO_ENGINE_SOCKET_FILE}\"
65
+    if [[ "$ENABLE_DEBUG_LOG_LEVEL" == "True" ]]; then
66
+        # debug is way too verbose, info will be enough
67
+        iniset -sudo ${crio_conf} crio.runtime log_level \"info\"
68
+    fi
69
+    if is_ubuntu; then
70
+        # In Ubuntu's a special vendored version of runc is installed with
71
+        # cri-o. This means that it'll not work with the system's version of
72
+        # runc. Moreover vendored runc is not placed into /usr/bin, where
73
+        # crio.conf states that it will be. We fix that by linking the vendored
74
+        # binary to /usr/bin.
75
+        if [[ ! -e /usr/bin/runc ]]; then
76
+            sudo ln -s /usr/lib/cri-o-runc/sbin/runc /usr/bin/runc
77
+            sudo chmod +x /usr/bin/runc
78
+        fi
79
+
80
+        # At least for 18.04 we need to set up /etc/containers/registries.conf
81
+        # with some initial content. That's another bug with that PPA.
82
+        local registries_conf
83
+        registries_conf="/etc/containers/registries.conf"
84
+        if [[ ! -f ${registries_conf} ]]; then
85
+            sudo mkdir -p `dirname ${registries_conf}`
86
+            cat << EOF | sudo tee ${registries_conf}
87
+[registries.search]
88
+registries = ['docker.io']
89
+EOF
90
+        fi
91
+    fi
92
+
93
+    sudo systemctl --no-block restart crio.service
94
+}
95
+
96
+function stop_crio {
97
+    sudo systemctl stop crio.service || true
98
+}
99
+
100
+# Restore xtrace
101
+$_XTRACE_DOCKER

+ 7
- 0
devstack/plugin.sh View File

@@ -6,6 +6,7 @@ set -o xtrace
6 6
 
7 7
 echo_summary "container's plugin.sh was called..."
8 8
 source $DEST/devstack-plugin-container/devstack/lib/docker
9
+source $DEST/devstack-plugin-container/devstack/lib/crio
9 10
 (set -o posix; set)
10 11
 
11 12
 if is_service_enabled container; then
@@ -13,17 +14,23 @@ if is_service_enabled container; then
13 14
         echo_summary "Installing container engine"
14 15
         if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
15 16
             check_docker || install_docker
17
+        elif [[ ${CONTAINER_ENGINE} == "crio" ]]; then
18
+            check_crio || install_crio
16 19
         fi
17 20
     elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
18 21
         echo_summary "Configuring container engine"
19 22
         if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
20 23
             configure_docker
24
+        elif [[ ${CONTAINER_ENGINE} == "crio" ]]; then
25
+            configure_crio
21 26
         fi
22 27
     fi
23 28
 
24 29
     if [[ "$1" == "unstack" ]]; then
25 30
         if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
26 31
             stop_docker
32
+        elif [[ ${CONTAINER_ENGINE} == "crio" ]]; then
33
+            stop_crio
27 34
         fi
28 35
     fi
29 36
 

+ 1
- 0
devstack/settings View File

@@ -1,5 +1,6 @@
1 1
 # Devstack settings
2 2
 
3
+# Supported options are "docker" and "crio".
3 4
 CONTAINER_ENGINE=${CONTAINER_ENGINE:-docker}
4 5
 ENABLE_CLEAR_CONTAINER=${ENABLE_CLEAR_CONTAINER:-false}
5 6
 ENABLE_LIVE_RESTORE=${ENABLE_LIVE_RESTORE:-false}

Loading…
Cancel
Save