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

Pretty print systemd services file #13814

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Apr 8, 2022

Fixes: #13337

I added newline only on options IE Begin with "-"

[NO NEW TESTS NEEDED]

Signed-off-by: Abhijeet Kasurde [email protected]
Signed-off-by: Daniel J Walsh [email protected]

Replaces: #13680

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 8, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Apr 8, 2022

@Luap99 @vrothberg PTAL

@TomSweeneyRedHat
Copy link
Member

All kinds of test unhappiness @rhatdan

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Approach LGTM but we should only do this for the long podman run command. I do not see reasons to add newlines for the other much shorter commands.

pkg/systemd/generate/containers.go Outdated Show resolved Hide resolved
pkg/systemd/generate/containers.go Outdated Show resolved Hide resolved
@@ -282,10 +282,23 @@ func setContainerNameForTemplate(startCommand []string, info *containerInfo) ([]
return startCommand, nil
}

func formatOptions(options []string) string {
var formatted string
Copy link
Member

Choose a reason for hiding this comment

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

please use a string builder for this

// executeContainerTemplate executes the container template on the specified
// containerInfo. Note that the containerInfo is also post processed and
// completed, which allows for an easier unit testing.
func executeContainerTemplate(info *containerInfo, options entities.GenerateSystemdOptions) (string, error) {
fmt.Println("DAN Start")
Copy link
Member

Choose a reason for hiding this comment

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

debug leftover

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

@rhatdan rhatdan force-pushed the systemd branch 3 times, most recently from e5052af to 1ef80bb Compare April 11, 2022 12:54
Comment on lines 291 to 295
if formatted.Len() == 0 {
formatted.WriteString(o)
} else {
formatted.WriteString(" " + o)
}
Copy link
Member

Choose a reason for hiding this comment

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

we can remove this branch here if we loop over options[1:] and add the first argument before the loop. I think it is safe to assume that we are always called with at least one argument.

return ""
}
formatted.WriteString(options[0])
for _, o := range options[:1] {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for _, o := range options[:1] {
for _, o := range options[1:] {

Copy link
Member Author

Choose a reason for hiding this comment

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

Yikes, oops.

-d \
--replace \
--name test awesome-image:latest sh \
-c "kill $$$$ && echo %%\\"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-c "kill $$$$ && echo %%\\"
sh -c "kill $$$$ && echo %%\\"

and remove "sh" from line 637

Copy link
Member Author

Choose a reason for hiding this comment

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

That is difficult/impossible to do, would need to figure out the first line of the command. Recall these are commands within commands. The command is not processed by Podman so there is no way to differentiate between the command/image and subcommand.

Copy link
Member

Choose a reason for hiding this comment

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

It is possible to do this but it would require way more logic. I think the current check is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

While possible for certain use cases, like podman in podman, I am not sure we would be 100 successful in interpreting these type of commands imagine running chroot or sudo within a container, or even bash -c. It would get way more complex for not much benefit.

--cgroups=no-conmon \
--rm \
--sdnotify=conmon \
-d awesome-image:latest
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why you didn't have the argument(s) on their own line for each of these ala:

Suggested change
-d awesome-image:latest
-d \
awesome-image:latest

Copy link
Member Author

Choose a reason for hiding this comment

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

The original patch did this, and it was felt that this did not look good, it broke the line up into two many lines. @Luap99 and I agreed this method looked best.

Fixes: containers#13337

I added newline only on options IE Begin with "-"

[NO NEW TESTS NEEDED]

Signed-off-by: Abhijeet Kasurde <[email protected]>
Signed-off-by: Daniel J Walsh <[email protected]>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM
/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 12, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, rhatdan

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

@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 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 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.

Add option to prettify systemd units
6 participants