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

podman generate systemd: handle --sdnotify correctly #15056

Merged

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Jul 25, 2022

When a container was created with --sdnotify value we would remove
this arg instead of using it like with --sdnotfiy=value.

Also when the arg is set to ignore we should force conmon in order to
make the resulting Type=notify units work.

Fixes #15052

Does this PR introduce a user-facing change?

Fixed a bug where podman generate systemd --new would create incorrect unit files when --sdnotify was used to create this container.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 25, 2022

[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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 25, 2022
@Luap99
Copy link
Member Author

Luap99 commented Jul 25, 2022

@vrothberg @eriksjolund PTAL

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.

LGTM

@vrothberg
Copy link
Member

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 25, 2022
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2022
When a container was created with `--sdnotify value` we would remove
this arg instead of using it like with `--sdnotfiy=value`.

Also when the arg is set to ignore we should force conmon in order to
make the resulting Type=notify units work.

Fixes containers#15052

Signed-off-by: Paul Holzinger <[email protected]>
@Luap99 Luap99 force-pushed the generate-systemd-sdnotify branch from edcc3fa to 6a9338a Compare July 25, 2022 12:16
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2022
Comment on lines +114 to +131
func removeSdNotifyArg(args []string, argCount int) []string {
processed := make([]string, 0, len(args))
for i := 0; i < len(args)-argCount; i++ {
s := args[i]

switch {
case s == "--sdnotify":
i++
continue
case strings.HasPrefix(s, "--sdnotify="):
continue
}
processed = append(processed, s)
}
processed = append(processed, args[len(args)-argCount:]...)
return processed
}

Copy link
Contributor

@eriksjolund eriksjolund Jul 25, 2022

Choose a reason for hiding this comment

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

I guess command-line options can't have the value --sdnotify?
(That could confuse the parsing)

Edit

(If someone could influence the value of a command-line option, it could
lead to incorrect parsing).

You can probably ignore this comment as describing a too unrealistic scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not possible, the option always needs an argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about --some-other-option value where value is --sdnotify.

Maybe it's not possible. In any case, it's too unrealistic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that could be a problem. However the other flags are handled in the same way. I think we can ignore this for now until somebody comes up with a real problem. Note that we will never touch the arguments after the image since they are for the container process.

@eriksjolund
Copy link
Contributor

	// If ignore is set force conmon otherwise the unit with Type=notify will fail.

I think it would be better to if podman systemd generate ... would fail if the container was created with --sdnotify=ignore.

It improves the user experience as the error message can give a clear direct information about what is wrong.

(Maybe changing that would be a breaking change ...)

Another thing that might not be directly related to this PR: I'm thinking that the default value of --sdnotify should be conmon.

@Luap99
Copy link
Member Author

Luap99 commented Jul 25, 2022

Another thing that might not be directly related to this PR: I'm thinking that the default value of --sdnotify should be conmon.

Yes I agree but we should discus this a new issue or discussion and not on this PR.

I think it would be better to if podman systemd generate ... would fail if the container was created with --sdnotify=ignore.
It improves the user experience as the error message can give a clear direct information about what is wrong.
(Maybe changing that would be a breaking change ...)

I don't know if there even is somebody using ignore so I don't know if they would like a hard error or just an overwrite. We already overwrite other options such as --cidfile so I kept it the same for --sdnotify, --sdnotify=ignore feels more like an option useful for testing. In the real world just do not set the NOTIFY_SOCKET env.

@eriksjolund
Copy link
Contributor

Another thing that might not be directly related to this PR: I'm thinking that the default value of --sdnotify should be conmon.

Yes I agree but we should discus this a new issue or discussion and not on this PR.

Yes, you're right.

I think it would be better to if podman systemd generate ... would fail if the container was created with --sdnotify=ignore.
It improves the user experience as the error message can give a clear direct information about what is wrong.
(Maybe changing that would be a breaking change ...)

I don't know if there even is somebody using ignore so I don't know if they would like a hard error or just an overwrite. We already overwrite other options such as --cidfile so I kept it the same for --sdnotify, --sdnotify=ignore feels more like an option useful for testing. In the real world just do not set the NOTIFY_SOCKET env.

One advantage of failing is also that documentation can of be written shorter.
This is not important though. I'm fine with either way.

(I'm just trying to promote more use of the "failing approach" in Podman instead of the "translate bad input to good input" approach)

@Luap99
Copy link
Member Author

Luap99 commented Aug 1, 2022

@vrothberg good to merge?

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.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2022
@Luap99
Copy link
Member Author

Luap99 commented Aug 1, 2022

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 1, 2022
@openshift-merge-robot openshift-merge-robot merged commit 271a9f4 into containers:main Aug 1, 2022
@Luap99 Luap99 deleted the generate-systemd-sdnotify branch August 1, 2022 09:38
@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 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 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. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"podman generate systemd" produces different results for "--sdnotify conmon" and "--sdnotify=conmon"
4 participants