-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8systemd: run k8s workloads in systemd
Support running `podman play kube` in systemd by exploiting the previously added "service containers". During `play kube`, a service container is started before all the pods and containers, and is stopped last. The service container communicates its conmon PID via sdnotify. Add a new systemd template to dispatch such k8s workloads. The argument of the template is the path to the k8s file. Note that the path must be escaped for systemd not to bark: Let's assume we have a `top.yaml` file in the home directory: ``` $ escaped=$(systemd-escape ~/top.yaml) $ systemctl --user start podman-play-kube@$escaped.service ``` Closes: https://issues.redhat.com/browse/RUN-1287 Signed-off-by: Valentin Rothberg <[email protected]>
- Loading branch information
Showing
14 changed files
with
248 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -832,7 +832,8 @@ install.docker-full: install.docker install.docker-docs | |
ifneq (,$(findstring systemd,$(BUILDTAGS))) | ||
PODMAN_UNIT_FILES = contrib/systemd/auto-update/podman-auto-update.service \ | ||
contrib/systemd/system/podman.service \ | ||
contrib/systemd/system/podman-restart.service | ||
contrib/systemd/system/podman-restart.service \ | ||
contrib/systemd/system/[email protected] | ||
|
||
%.service: %.service.in | ||
sed -e 's;@@PODMAN@@;$(BINDIR)/podman;g' $< >$@.tmp.$$ \ | ||
|
@@ -846,12 +847,14 @@ install.systemd: $(PODMAN_UNIT_FILES) | |
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.socket ${DESTDIR}${USERSYSTEMDDIR}/podman.socket | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.service ${DESTDIR}${USERSYSTEMDDIR}/podman.service | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman-restart.service ${DESTDIR}${USERSYSTEMDDIR}/podman-restart.service | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/[email protected] ${DESTDIR}${USERSYSTEMDDIR}/[email protected] | ||
# System services | ||
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.service ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.service | ||
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.timer ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.timer | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.socket ${DESTDIR}${SYSTEMDDIR}/podman.socket | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.service ${DESTDIR}${SYSTEMDDIR}/podman.service | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman-restart.service ${DESTDIR}${SYSTEMDDIR}/podman-restart.service | ||
install ${SELINUXOPT} -m 644 contrib/systemd/system/[email protected] ${DESTDIR}${SYSTEMDDIR}/[email protected] | ||
rm -f $(PODMAN_UNIT_FILES) | ||
else | ||
install.systemd: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=A template for running K8s workloads via podman-play-kube | ||
Documentation=man:podman-play-kube(1) | ||
Wants=network-online.target | ||
After=network-online.target | ||
RequiresMountsFor=%t/containers | ||
|
||
[Service] | ||
Environment=PODMAN_SYSTEMD_UNIT=%n | ||
Restart=never | ||
TimeoutStopSec=70 | ||
ExecStart=@@PODMAN@@ play kube --replace --service-container=true %I | ||
ExecStop=@@PODMAN@@ play kube --down %I | ||
Type=notify | ||
NotifyAccess=all | ||
|
||
[Install] | ||
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,11 +242,13 @@ done | |
%{_unitdir}/%{name}.service | ||
%{_unitdir}/%{name}.socket | ||
%{_unitdir}/%{name}-restart.service | ||
%{_unitdir}/%{name}[email protected] | ||
%{_userunitdir}/%{name}-auto-update.service | ||
%{_userunitdir}/%{name}-auto-update.timer | ||
%{_userunitdir}/%{name}.service | ||
%{_userunitdir}/%{name}.socket | ||
%{_userunitdir}/%{name}-restart.service | ||
%{_userunitdir}/%{name}[email protected] | ||
%{_tmpfilesdir}/%{name}.conf | ||
%if 0%{?fedora} >= 36 | ||
%{_modulesloaddir}/%{name}-iptables.conf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,4 +292,80 @@ LISTEN_FDNAMES=listen_fdnames" | sort) | |
run_podman network rm -f $netname | ||
} | ||
|
||
@test "[email protected] template" { | ||
skip_if_remote "systemd units do not work with remote clients" | ||
|
||
# If running from a podman source directory, build and use the source | ||
# version of the play-kube-@ unit file | ||
unit_name="[email protected]" | ||
unit_file="contrib/systemd/system/${unit_name}" | ||
if [[ -e ${unit_file}.in ]]; then | ||
echo "# [Building & using $unit_name from source]" >&3 | ||
BINDIR=$(dirname $PODMAN) make $unit_file | ||
cp $unit_file $UNIT_DIR/$unit_name | ||
fi | ||
|
||
# Create the YAMl file | ||
yaml_source="$PODMAN_TMPDIR/test.yaml" | ||
cat >$yaml_source <<EOF | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
app: test | ||
name: test_pod | ||
spec: | ||
containers: | ||
- command: | ||
- top | ||
image: $IMAGE | ||
name: test | ||
resources: {} | ||
EOF | ||
|
||
# Dispatch the YAML file | ||
service_name="podman-play-kube@$(systemd-escape $yaml_source).service" | ||
systemctl start $service_name | ||
systemctl is-active $service_name | ||
|
||
# The name of the service container is predictable: the first 12 characters | ||
# of the hash of the YAML file followed by the "-service" suffix | ||
yaml_sha=$(sha256sum $yaml_source) | ||
service_container="${yaml_sha:0:12}-service" | ||
|
||
# Make sure that the service container exists and runs. | ||
run_podman container inspect $service_container --format "{{.State.Running}}" | ||
is "$output" "true" | ||
|
||
# Check for an error when trying to remove the service container | ||
run_podman 125 container rm $service_container | ||
is "$output" "Error: container .* is the service container of pod(s) .* and cannot be removed without removing the pod(s)" | ||
|
||
# Kill the pod and make sure the service is not running. | ||
# The restart policy is set to "never" since there is no | ||
# design yet for propagating exit codes up to the service | ||
# container. | ||
run_podman pod kill test_pod | ||
for i in {0..5}; do | ||
run systemctl is-failed $service_name | ||
if [[ $output == "failed" ]]; then | ||
break | ||
fi | ||
sleep 0.5 | ||
done | ||
is "$output" "failed" "systemd service transitioned to 'failed' state" | ||
|
||
# Now stop and start the service again. | ||
systemctl stop $service_name | ||
systemctl start $service_name | ||
systemctl is-active $service_name | ||
run_podman container inspect $service_container --format "{{.State.Running}}" | ||
is "$output" "true" | ||
|
||
# Clean up | ||
systemctl stop $service_name | ||
run_podman 1 container exists $service_container | ||
run_podman 1 pod exists test_pod | ||
} | ||
|
||
# vim: filetype=sh |
Oops, something went wrong.