From 3230dec950e41c1a499a552b0a54739d079f9b97 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Wed, 2 Aug 2023 11:16:11 +0200 Subject: [PATCH] kata-deploy: Use host's systemctl when interacting with systemd. We have occasionally faced issues with compatibility between the systemctl version used inside the kata-deploy container and the systemd version on the host. Instead of using a containerized systemctl with bind mounted sockets, nsenter the host and run systemctl from there. This provides less coupling between the kata-deploy container and the host. Fixes: #7511 Signed-off-by: Jeremi Piotrowski --- .../kata-cleanup/base/kata-cleanup.yaml | 13 +----------- .../kata-deploy/base/kata-deploy.yaml | 11 +--------- .../kata-deploy/scripts/kata-deploy.sh | 20 +++++++++++-------- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml b/tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml index 36d1b9b5b892..3d9006572e16 100644 --- a/tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml +++ b/tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml @@ -14,6 +14,7 @@ spec: name: kubelet-kata-cleanup spec: serviceAccountName: kata-deploy-sa + hostPID: true nodeSelector: katacontainers.io/kata-runtime: cleanup containers: @@ -38,18 +39,6 @@ spec: value: "false" securityContext: privileged: true - volumeMounts: - - name: dbus - mountPath: /var/run/dbus/system_bus_socket - - name: systemd - mountPath: /run/systemd/system - volumes: - - name: dbus - hostPath: - path: /var/run/dbus/system_bus_socket - - name: systemd - hostPath: - path: /run/systemd/system updateStrategy: rollingUpdate: maxUnavailable: 1 diff --git a/tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml b/tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml index 5431a47fae1e..c10061d90246 100644 --- a/tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml +++ b/tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml @@ -14,6 +14,7 @@ spec: name: kata-deploy spec: serviceAccountName: kata-deploy-sa + hostPID: true containers: - name: kube-kata image: quay.io/kata-containers/kata-deploy:latest @@ -47,10 +48,6 @@ spec: mountPath: /etc/containerd/ - name: kata-artifacts mountPath: /opt/kata/ - - name: dbus - mountPath: /var/run/dbus/system_bus_socket - - name: systemd - mountPath: /run/systemd/system - name: local-bin mountPath: /usr/local/bin/ volumes: @@ -64,12 +61,6 @@ spec: hostPath: path: /opt/kata/ type: DirectoryOrCreate - - name: dbus - hostPath: - path: /var/run/dbus/system_bus_socket - - name: systemd - hostPath: - path: /run/systemd/system - name: local-bin hostPath: path: /usr/local/bin/ diff --git a/tools/packaging/kata-deploy/scripts/kata-deploy.sh b/tools/packaging/kata-deploy/scripts/kata-deploy.sh index 5ed4df0675e6..fc26921df247 100755 --- a/tools/packaging/kata-deploy/scripts/kata-deploy.sh +++ b/tools/packaging/kata-deploy/scripts/kata-deploy.sh @@ -25,6 +25,10 @@ die() { exit 1 } +function host_systemctl() { + nsenter --target 1 --mount systemctl "${@}" +} + function print_usage() { echo "Usage: $0 [install/cleanup/reset]" } @@ -71,11 +75,11 @@ function get_container_runtime() { die "invalid node name" fi if echo "$runtime" | grep -qE 'containerd.*-k3s'; then - if systemctl is-active --quiet rke2-agent; then + if host_systemctl is-active --quiet rke2-agent; then echo "rke2-agent" - elif systemctl is-active --quiet rke2-server; then + elif host_systemctl is-active --quiet rke2-server; then echo "rke2-server" - elif systemctl is-active --quiet k3s-agent; then + elif host_systemctl is-active --quiet k3s-agent; then echo "k3s-agent" else echo "k3s" @@ -136,8 +140,8 @@ function configure_cri_runtime() { configure_containerd ;; esac - systemctl daemon-reload - systemctl restart "$1" + host_systemctl daemon-reload + host_systemctl restart "$1" wait_till_node_is_ready } @@ -371,10 +375,10 @@ function cleanup_containerd() { function reset_runtime() { kubectl label node "$NODE_NAME" katacontainers.io/kata-runtime- - systemctl daemon-reload - systemctl restart "$1" + host_systemctl daemon-reload + host_systemctl restart "$1" if [ "$1" == "crio" ] || [ "$1" == "containerd" ]; then - systemctl restart kubelet + host_systemctl restart kubelet fi wait_till_node_is_ready