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

cmd/entrypoint: do not interpret anything after -- #5084

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

vdemeester
Copy link
Member

@vdemeester vdemeester commented Jul 6, 2022

Changes

The way the flag package works, it can eat the flag
"terminator" (aka the double dash --). This means that, in some very
specific cases — where the first item after the -- is also a
subcommand, it would execute the entrypoint subcommand instead of the
actual command.

For example :

$ /ko-app/entrypoint -- init a b
$ /ko-app/entrypoint init a b

This is fixed by making sure we remove anything after -- for the
subcommand processing. And then we pass the rest (after --) to the
entrypointer to be executed.

Note for the reviewers: this is one approach (mutate os.Args) that is relatively contained. The other way to fix that would be to have an exec subcommand that would be used to exec things, but this means changing all containers commands as well which.. might be a bit much for bug fixes at least.
In any case, I think the entrypoint binary needs a bit of love and refactoring.

Signed-off-by: Vincent Demeester vdemeest@redhat.com

Fixes #5080

/kind bug
/priority critial-urgent

This will have to be cherry-pick in all release from 0.35 to 0.37 😅

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

Fix the entrypoint potentially not executing the right command due to flag parsing

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 6, 2022
@tekton-robot
Copy link
Collaborator

@vdemeester: The label(s) priority/critial-urgent cannot be applied, because the repository doesn't have them.

In response to this:

Changes

The way the flag package works, it can eat the flag
"terminator" (aka the double dash --). This means that, in some very
specific cases — where the first item after the -- is also a
subcommand, it would execute the entrypoint subcommand instead of the
actual command.

For example :

$ /ko-app/entrypoint -- init a b
$ /ko-app/entrypoint init a b

This is fixed by making sure we remove anything after -- for the
subcommand processing. And then we pass the rest (after --) to the
entrypointer to be executed.

Note for the reviewers: this is one approach (mutate os.Args) that is relatively contained. The other way to fix that would be to have an exec subcommand that would be used to exec things, but this means changing all containers commands as well which.. might be a bit much for bug fixes at least.
In any case, I think the entrypoint binary needs a bit of love and refactoring.

Signed-off-by: Vincent Demeester vdemeest@redhat.com

Fixes #5080

/kind bug
/priority critial-urgent

This will have to be cherry-pick in all release from 0.32 to 0.37 😅

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

Fix the entrypoint potentially not executing the right command due to flag parsing

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Jul 6, 2022
@vdemeester vdemeester requested review from imjasonh and removed request for pritidesai and dlorenc July 6, 2022 05:58
@tekton-robot tekton-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 6, 2022
@vdemeester vdemeester requested a review from a user July 6, 2022 05:58
@vdemeester
Copy link
Member Author

/cc @abayer @lbernick @jerop @afrittoli

@vdemeester
Copy link
Member Author

vdemeester commented Jul 6, 2022

This probably need at least one test 🙃 working on it.
Done ✅

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/main.go 14.0% 11.9% -2.1

@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 6, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/main.go 14.0% 11.9% -2.1

@vdemeester
Copy link
Member Author

cloudevent: TestSendCloudEventWithRetries/test-send-cloud-event-failed expand_less | 0s
{Failed      cloud_event_controller_test.go:619: error in test test-send-cloud-event-failed: received 0 events but 1 expected. Found events: []string{} WARN	cloudevent/cloud_event_controller.go:162	Failed to send cloudevent: Had to fail. Event ID: 1f6a546b-df34-4e1b-8a72-bfb1fa13414b}

🤔 those are new "unit test" flakes ? 🤔

@vdemeester
Copy link
Member Author

/test tekton-pipeline-unit-tests

@vdemeester vdemeester force-pushed the 5080-entrypoint-init-fix branch 3 times, most recently from 913dfc7 to faa9f89 Compare July 6, 2022 08:13
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/main.go 14.0% 11.8% -2.3

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 6, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/main.go 14.0% 11.6% -2.4

@vdemeester
Copy link
Member Author

/retest

@abayer
Copy link
Contributor

abayer commented Jul 6, 2022

I believe the unit test flakes are due to my change decreasing requests/limits for that job - tektoncd/plumbing#1124 reverts that change.

Copy link
Contributor

@abayer abayer left a comment

Choose a reason for hiding this comment

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

I'm a bit worried that this could cause something else to fail, due to all the fun complicated behaviors around --, but I can't think of anything better. =)

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abayer

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 6, 2022
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 6, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/args.go Do not exist 100.0%
cmd/entrypoint/main.go 14.0% 13.6% -0.5

"github.com/google/go-cmp/cmp"
)

func TestExtractArgs(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thank you for adding the tests!
/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2022
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/args.go Do not exist 100.0%
cmd/entrypoint/main.go 14.0% 13.6% -0.5

@afrittoli
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2022
@afrittoli
Copy link
Member

/restest

The way the `flag` package works, it can eat the flag
"terminator" (aka the double dash `--`). This means that, in some very
specific cases — where the first item after the `--` is also a
subcommand, it would execute the entrypoint subcommand instead of the
actual command.

For example :

```
$ /ko-app/entrypoint -- init a b
$ /ko-app/entrypoint init a b
```

This is fixed by making sure we remove anything after `--` for the
subcommand processing. And then we pass the rest (after `--`) to the
entrypointer to be executed.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/entrypoint/args.go Do not exist 100.0%
cmd/entrypoint/main.go 14.0% 13.6% -0.5

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2022
@tekton-robot tekton-robot merged commit da91bf3 into tektoncd:main Jul 7, 2022
@vdemeester vdemeester deleted the 5080-entrypoint-init-fix branch July 7, 2022 07:57
@vdemeester vdemeester added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tasks are failing when "init" is the first argument followed by two or more other arguments.
4 participants