-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix go template parsing with "\n" in it #15673
Conversation
[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 |
/hold for tests, ideally we can add a test which makes sure all --format flags work correctly since I had to change some commands manually, something like cc @edsantiago |
Linter is angry |
still a WIP. I'm working on tests for it. |
See treadmill PR #13808 for fixes to the vendor bugs |
row = cmd.Flag("format").Value.String() | ||
printHeader = report.HasTable(row) | ||
row = report.NormalizeFormat(row) | ||
case cmd.Flag("format").Changed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI cmd.Flags().Changed("format")
guards against using a nil pointer while cmd.Flag("format").Changed
does not. Only exposed when flag is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that matters much since a) we know that the flag exists and b) this PR includes a test for all format flags so if it would panic the test will catch it.
7aa2fa2
to
7933f15
Compare
Sorry about the test failure. Since my first iteration, I reworked the test to make it better; was going to submit it as a followup PR, but could you grab it here instead? This version does a much better job of error reporting; it also is more thorough, as in, it catches |
I applied your test changes but I see no errors with |
Sorry about the churn. This fixes the rootless hang (because of empty events file) and the stupid, nonworking root-machine check: diff --git a/test/system/610-format.bats b/test/system/610-format.bats
index c950827b4..287a29393 100644
--- a/test/system/610-format.bats
+++ b/test/system/610-format.bats
@@ -52,7 +52,7 @@ function check_subcommand() {
for cmd in $(_podman_commands "$@"); do
# Special case: 'podman machine' can't be run as root. No override.
if [[ "$cmd" = "machine" ]]; then
- if is_root; then
+ if ! is_rootless; then
continue
fi
fi
@@ -136,7 +136,7 @@ function check_subcommand() {
done < <(parse_table "$extra_args_table")
# Setup: some commands need a container, pod, machine, or secret
- run_podman run -d --name mycontainer $IMAGE top
+ run_podman --events-backend=file run -d --name mycontainer $IMAGE top
run_podman pod create mypod
run_podman secret create mysecret /etc/hosts
if is_rootless; then
@@ -150,8 +150,10 @@ function check_subcommand() {
run_podman pod rm mypod
run_podman rmi $(pause_image)
run_podman rm -f -t0 mycontainer
- run_podman machine rm -f mymachine
run_podman secret rm mysecret
+ if is_rootless; then
+ run_podman machine rm -f mymachine
+ fi
# Make sure there are no leftover commands in our table - this would
# indicate a typo in the table, or a flaw in our logic such that |
We can wait for #15717 to avoid the hang, instead of the awkward workaround: |
SGTM but you still need the |
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. Also fix a bug where a invlaid template would not cause a exit code > 0, see the added test case. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. Also fixa bug since the table format is expected to print headers as well. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output, we can add a new test for the newline bug when the common PR is vendored in. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Unlikely to happen but when there is an error printing the data to stdout (either as json or go template) we should not just log it and exit with 0. Instead return a proper error and exit with 125. Signed-off-by: Paul Holzinger <[email protected]>
Signed-off-by: Ed Santiago <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Currently the podman command --format output code uses a mix of report.Formatter and report.Template. I patched report.Formatter to correctly handle newlines[1]. Since we cannot fix this with report.Template we have to migrate all users to report.Formatter. This ensures consistent behavior for all commands. This change does not change the output. [1] containers/common#1146 Signed-off-by: Paul Holzinger <[email protected]>
Now that commit d10e77e is merged, it will reuse the same template logic as inspect and therefore should just work. Also remove the FIXME from eds test. Signed-off-by: Paul Holzinger <[email protected]>
test/system/610-format.bats
Outdated
run_podman pod rm mypod | ||
run_podman rmi $(pause_image) | ||
run_podman rm -f -t0 mycontainer | ||
run_podman machine rm -f mymachine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to kill this line
I encourage you to test, it only takes a few seconds to run: $ hack/bats format |
@edsantiago It still fails as root with:
The problem is we do not remove the machine command from the test table as root. |
Guess I should test too -- my apologies. Please apply the following workaround, I will work on something cleaner later: diff --git a/test/system/610-format.bats b/test/system/610-format.bats
index bedfab47f..1c16db84e 100644
--- a/test/system/610-format.bats
+++ b/test/system/610-format.bats
@@ -53,6 +53,7 @@ function check_subcommand() {
# Special case: 'podman machine' can't be run as root. No override.
if [[ "$cmd" = "machine" ]]; then
if ! is_rootless; then
+ unset extra_args["podman machine inspect"]
continue
fi
fi |
Well, this was unexpected:
(in ubuntu I need to do some cleanup on this test, but it's not fair to keep this PR hanging on that. For now just add |
No worries, we suffer together :) |
This version does a much better job of error reporting and also catches more commands. Changes from edsantiago. Signed-off-by: Paul Holzinger <[email protected]>
Whew! |
/lgtm |
Followup to containers#15673 (--format with newlines). I cobbled up a test for it, but I was sloppy, so the test had issues that I kept having to band-aid. This is a cleaner way to handle podman-machine. ...and, another unexpected surprise with podman stats. It fails under rootless cgroupsv1. We can't sweep it under the rug via skip_if_ubuntu because tests will then fail on RHEL8. So, add a similar mechanism for testing podman stats. ...plus a non-surprise, the 'search' test flakes. Try minimizing that by searching only $IMAGE. If quay.io is down, other tests will certainly fail. Signed-off-by: Ed Santiago <[email protected]>
see individual commit for more information
Fixes #13446
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2059658
Does this PR introduce a user-facing change?