Fix air-gapped installation issues with containerd and OSM helm chart 07/14307/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 2 Nov 2023 06:56:50 +0000 (07:56 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 3 Apr 2024 15:48:37 +0000 (17:48 +0200)
Change-Id: I5d8a8afc751d892de6be92ebbb62bd3ace382b21
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
installers/full_install_osm.sh
installers/install_docker_ce.sh

index 653b1ba..b49bb57 100755 (executable)
@@ -284,9 +284,17 @@ EOF"
     [ -n "${INSTALL_NGSA}" ] || OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.oldServiceAssurance=true"
     if [ -n "${OSM_BEHIND_PROXY}" ]; then
         OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.behindHttpProxy=true"
-        [ -n "${HTTP_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTP_PROXY=${HTTP_PROXY}"
-        [ -n "${HTTPS_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTPS_PROXY=${HTTPS_PROXY}"
-        [ -n "${NO_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.NO_PROXY=${NO_PROXY}"
+        [ -n "${HTTP_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTP_PROXY=\"${HTTP_PROXY}\""
+        [ -n "${HTTPS_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTPS_PROXY=\"${HTTPS_PROXY}\""
+        if [ -n "${NO_PROXY}" ]; then
+            if [[ ! "${NO_PROXY}" =~ .*".svc".* ]]; then
+                NO_PROXY="${NO_PROXY},.svc"
+            fi
+            if [[ ! "${NO_PROXY}" =~ .*".cluster.local".* ]]; then
+                NO_PROXY="${NO_PROXY},.cluster.local"
+            fi
+            OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.NO_PROXY=\"${NO_PROXY//,/\,}\""
+        fi
     fi
 
     echo "helm -n $OSM_NAMESPACE install $OSM_NAMESPACE $OSM_DEVOPS/installers/helm/osm -f ${OSM_HELM_WORK_DIR}/osm-values.yaml ${OSM_HELM_OPTS}"
index e5c2f44..5010f7e 100755 (executable)
 
 set +eux
 
+function configure_containerd() {
+    echo "Configuring containerd to expose CRI and use systemd cgroup"
+    sudo mv /etc/containerd/config.toml /etc/containerd/config.toml.orig 2>/dev/null
+    sudo bash -c "containerd config default > /etc/containerd/config.toml"
+    sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
+    if [ -n "${DOCKER_PROXY_URL}" ]; then
+        echo "Configuring ${DOCKER_PROXY_URL} as registry mirror in /etc/containerd/config.toml"
+        sudo sed -i "s#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]\n        \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"\]\n          endpoint = \[\"${DOCKER_PROXY_URL}\"\]\n        \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"registry.hub.docker.com\"]\n          endpoint = \[\"${DOCKER_PROXY_URL}\"]#" /etc/containerd/config.toml
+    fi
+    if [ -n "${OSM_BEHIND_PROXY}" ] ; then
+        echo "Configuring http proxies in /etc/systemd/system/containerd.service.d/http-proxy.conf"
+        if ! [ -f /etc/systemd/system/containerd.service.d/http-proxy.conf ] ; then
+            sudo mkdir -p /etc/systemd/system/containerd.service.d
+            cat << EOF | sudo tee -a /etc/systemd/system/containerd.service.d/http-proxy.conf
+[Service]
+EOF
+        fi
+        [ -n "${HTTP_PROXY}" ] && sudo bash -c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
+Environment=\"HTTP_PROXY=${HTTP_PROXY}\"
+EOF"
+        [ -n "${HTTPS_PROXY}" ] && sudo bash -c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
+Environment=\"HTTPS_PROXY=${HTTPS_PROXY}\"
+EOF"
+        [ -n "${NO_PROXY}" ] && sudo bash -c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
+Environment=\"NO_PROXY=${NO_PROXY}\"
+EOF"
+    fi
+    sudo systemctl restart containerd
+}
+
 function install_docker_ce() {
     # installs and configures Docker CE
     [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
@@ -75,14 +105,7 @@ EOF"
         echo "... restarted Docker service"
     fi
 
-    echo "Configuring containerd to expose CRI, use systemd cgroup and use DOCKER_PROXY_URL as registry mirror"
-    sudo mv /etc/containerd/config.toml /etc/containerd/config.toml.orig 2>/dev/null
-    sudo bash -c "containerd config default > /etc/containerd/config.toml"
-    sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
-    if [ -n "${DOCKER_PROXY_URL}" ]; then
-        sudo sed -i "s#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]\n        \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"\]\n          endpoint = \[\"${DOCKER_PROXY_URL}\"\]\n        \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"registry.hub.docker.com\"]\n          endpoint = \[\"${DOCKER_PROXY_URL}\"]#" /etc/containerd/config.toml
-    fi
-    sudo systemctl restart containerd
+    configure_containerd
 
     [ -z "${DEBUG_INSTALL}" ] || ! echo "File: /etc/docker/daemon.json" || cat /etc/docker/daemon.json
     echo "Testing Docker CE installation ..."