Skip to content

Commit

Permalink
kata-deploy: Use host's systemctl
Browse files Browse the repository at this point in the history
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: kata-containers#7511
Signed-off-by: Jeremi Piotrowski <[email protected]>
  • Loading branch information
jepio committed Aug 2, 2023
1 parent 29855ed commit 3230dec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
13 changes: 1 addition & 12 deletions tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
name: kubelet-kata-cleanup
spec:
serviceAccountName: kata-deploy-sa
hostPID: true
nodeSelector:
katacontainers.io/kata-runtime: cleanup
containers:
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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/
Expand Down
20 changes: 12 additions & 8 deletions tools/packaging/kata-deploy/scripts/kata-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ die() {
exit 1
}

function host_systemctl() {
nsenter --target 1 --mount systemctl "${@}"
}

function print_usage() {
echo "Usage: $0 [install/cleanup/reset]"
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3230dec

Please sign in to comment.