Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make podman generate systemd --new flag parsing more robust #8851

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Dec 29, 2020

First, use the pflag library to parse the flags. With this we can
handle all corner cases such as -td or --detach=false.

Second, preserve the root args with --new. They are used for all podman
commands in the unit file. (e.g. podman --root /tmp run alpine)

Fixes #8847

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 29, 2020
@rhatdan
Copy link
Member

rhatdan commented Dec 30, 2020

Is there a corner case where a user could specify something like

podman run -d --detach=false alpine sleep 100

And we end up with using the first -d?

@Luap99
Copy link
Member Author

Luap99 commented Dec 30, 2020

-d -detach=false alpine sleep 100 would turn into -d -d alpine sleep 100 which is valid

@Luap99 Luap99 force-pushed the fix-generate-systemd-flag-parsing branch 2 times, most recently from 33c3029 to feb8f37 Compare December 30, 2020 14:35
@rhatdan
Copy link
Member

rhatdan commented Dec 30, 2020

It is valid but not what the user requested.

podman run -d --detach=false alpine sleep 100
Is treated as
podman run --detach=false alpine sleep 100

With your change it will be treated as
podman run --detach=true alpine sleep 100

BTW I have no problem if we just make running multiple --detach commands fail.

@Luap99
Copy link
Member Author

Luap99 commented Dec 30, 2020

The whole point of the --new flag is that we must add detach regardless of what the user requested. If there is no detach systemctl start will fail on that unit.

@rhatdan
Copy link
Member

rhatdan commented Dec 30, 2020

Should it fail then if the user requested it not to detach?

@alitvak69
Copy link

alitvak69 commented Jan 4, 2021

Sorry for butting in but I don't think systemd will fail with no detach. Here is my example that runs well.

[Unit]
Description=DNS Bind container
After=multi-user.target

[Service]
EnvironmentFile=-/etc/environment
Type=simple
#LimitNOFILE=32768
WorkingDirectory=/dns/slave-internal
ExecStartPre=-/usr/bin/podman pull xxxxxxx/services/bind-host:latest
ExecStart=/usr/bin/podman run --rm --name=dns-slave-internal --no-hosts=true -t --cgroups=no-conmon
--log-driver=journald --log-opt=tag={{.Name}}
--env=CONTAINER_HOST=xxxxxxxxx
--env=DC=chi
--env=DNSZONE_TYPE=slave
--env=DNSZONE_VIEW=internal
--env=SERVICE_NAME=dns-slave-internal
--env=SERVICE_PORT=53
--env=BIND_DATA_DIR=/dns
--cap-add=CAP_SYS_PTRACE,CAP_NET_ADMIN,CAP_NET_RAW,CAP_NET_BIND_SERVICE,CAP_SETUID,CAP_SETGID
--volume=/dns/slave-internal:/dns:rw
--net=private-dns-internal-slaves

xxxxxxxxx/services/bind-host:latest
ExecStop=-/usr/bin/podman stop dns-slave-internal
SyslogIdentifier=dns-slave-internal
Restart=on-failure
KillMode=none
RestartSec=10s
TimeoutStartSec=120
TimeoutStopSec=15

[Install]
WantedBy=multi-user.target
dns-slave-internal.service (END)

@Luap99
Copy link
Member Author

Luap99 commented Jan 4, 2021

Yes it works when the unit type is simple but we set the type to forking.

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling it, really nice work!

Please make sure to split future commits into separate pieces. This commit applies too many changes at once which makes it hard to review and may hinder backporting. But we're close to a new release, so we're good.

test/e2e/generate_systemd_test.go Show resolved Hide resolved
pkg/systemd/generate/containers_test.go Outdated Show resolved Hide resolved
First, use the pflag library to parse the flags. With this we can
handle all corner cases such as -td or --detach=false.

Second, preserve the root args with --new. They are used for all podman
commands in the unit file. (e.g. podman --root /tmp run alpine)

Signed-off-by: Paul Holzinger <[email protected]>
@Luap99 Luap99 force-pushed the fix-generate-systemd-flag-parsing branch from feb8f37 to ef82be4 Compare January 7, 2021 10:52
@rhatdan
Copy link
Member

rhatdan commented Jan 10, 2021

LGTM

@vrothberg
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2021
@openshift-merge-robot openshift-merge-robot merged commit 0ccc888 into containers:master Jan 12, 2021
edsantiago added a commit to edsantiago/libpod that referenced this pull request Jan 12, 2021
PR containers#8851 broke CI: it included "/var/run" strings that,
per containers#8771, should have been just "/run".

Signed-off-by: Ed Santiago <[email protected]>
rhatdan pushed a commit to rhatdan/podman that referenced this pull request Jan 12, 2021
PR containers#8851 broke CI: it included "/var/run" strings that,
per containers#8771, should have been just "/run".

Signed-off-by: Ed Santiago <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: podman generate systemd defines multiple "-d"
6 participants