Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

rkt/uuid: fix match when uuid is an empty string - #2807

Merged
lucab merged 1 commit into
rkt:masterfrom
kinvolk:alessandro/resolve-uuid-fix
Jun 21, 2016
Merged

lucab merged 1 commit into
rkt:masterfrom
kinvolk:alessandro/resolve-uuid-fix

Conversation

@alepuccetti

Copy link
Copy Markdown
Contributor

After the patch, if the uuid is an empty string then matchUUID(uuid string)
returns no matches instead of all the pods.
This is done to avoid rkt rm or rkt enter to delete or enter pods
without intending to.

Fixes #2806

@ghost

ghost commented Jun 16, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@iaguis

iaguis commented Jun 16, 2016

Copy link
Copy Markdown
Member

ok to test

@alban

alban commented Jun 16, 2016

Copy link
Copy Markdown
Member

How does it look like with this patch when users run rkt rm "" or rkt enter ""?

@alepuccetti

alepuccetti commented Jun 16, 2016 •

Copy link
Copy Markdown
Contributor Author

How does it look like with this patch when users run rkt rm "" or rkt enter ""?

rkt rm ""

rm: unable to resolve UUID: no matches found for ""
rm: failed to remove one or more pods

rkt enter ""
enter: problem retrieving pod: no matches found for ""

@alepuccetti

Copy link
Copy Markdown
Contributor Author

Maybe the second line of the error message can be avoided when there are no matches.

@lucab

lucab commented Jun 16, 2016 •

Copy link
Copy Markdown
Member

Two comments here:

  • this could benefit from using a ErrNoEmptyUUID
  • this is killing the (only?) way to act on all pods. I'm not sure if this feature has some real usecases. If so, should we introduce a special wildcard instead? Edit: nevermind, I later realized that the only caller of this explicitly expects a single result.

@alepuccetti

Copy link
Copy Markdown
Contributor Author

I agree on the wildcard, but before if you were running 'sudo rkt rm ""'
rkt was not going to delete all the pods anyway. It says 'ambiguous UUID'
this just catch a typing error.
That been said, I totally agree about the wildcard, but this should be a
RFE in a different PR. Which I can do it tomorrow.

On Thursday, June 16, 2016, Luca Bruno notifications@github.com wrote:

Two comments here:

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2807 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AGRc7ydEaG2LSqcP6ShTLJJQEyrA5fyFks5qMZCFgaJpZM4I3RWH
.

@alepuccetti
alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 70aafe9 to 4ef67fe Compare June 17, 2016 10:04
@alepuccetti

alepuccetti commented Jun 17, 2016 •

Copy link
Copy Markdown
Contributor Author

Patch updated.

@lucab I will open a specific an issue for wildcard

@alepuccetti

Copy link
Copy Markdown
Contributor Author

New error output

sudo rkt enter ""
enter: problem retrieving pod: UUID cannot be empty

sudo rkt rm ""
rm: unable to resolve UUID: UUID cannot be empty
rm: failed to remove one or more pods

@alepuccetti
alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 4ef67fe to f83db18 Compare June 17, 2016 10:17
Comment thread rkt/uuid.go Outdated
// An array of matches is returned, which may be empty when nothing matches.
func matchUUID(uuid string) ([]string, error) {
if uuid == "" {
return []string{}, types.ErrNoEmptyUUID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can directly return nil, types.ErrNoEmptyUUID here.

@lucab

lucab commented Jun 18, 2016

Copy link
Copy Markdown
Member

One comment inline and some additional notes:

  • No need to specify the function in commit title, rkt/uuid should be enough.
  • Can you please also add a test for this?

@lucab lucab self-assigned this Jun 18, 2016
@alepuccetti
alepuccetti force-pushed the alessandro/resolve-uuid-fix branch 3 times, most recently from 00f3b32 to 4a2a791 Compare June 20, 2016 13:01
@alepuccetti

Copy link
Copy Markdown
Contributor Author

Patch updated. @lucab test added.

Comment thread tests/rkt_rm_test.go Outdated
uuidFile := filepath.Join(tmpDir, "uuid-file")
if err := ioutil.WriteFile(uuidFile, []byte(nonexistentUUID), 0600); err != nil {
t.Fatalf("cannot write uuid-file: %v", err)
}

@lucab lucab Jun 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure I understood why you are creating this nonexistentUUID file here. What's its purpose?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah this can be deleted, I was not sure if it was necessary to have a some kind of data to be able to run rkt rm correctly, like the example before. I suppose that the creation of the uuid-file it is a precaution to avoid deleting an existing pod, isn't it?.

After the patch, if the uuid is an empty string then matchUUID(uuid string)
returns `UUID cannot be empty` error message instead of all the pods.
This is done to avoid `rkt rm` or `rkt enter` to delete or enter pods
without intending to.

Fixes rkt#2806
@alepuccetti
alepuccetti force-pushed the alessandro/resolve-uuid-fix branch from 4a2a791 to 166b560 Compare June 21, 2016 07:10
@alepuccetti

Copy link
Copy Markdown
Contributor Author

patch updated. @lucab this should be cleaner

@lucab

lucab commented Jun 21, 2016

Copy link
Copy Markdown
Member

Yes, thanks! LGTM, mergeable once builders are done.

@alepuccetti

Copy link
Copy Markdown
Contributor Author

TestRmEmptyUUID passed, fedora-23 failure seems unrelated.

@lucab

lucab commented Jun 21, 2016

Copy link
Copy Markdown
Member

@alepuccetti yes that's #2287. I'm merging this.

@lucab lucab changed the title rkt/matchUUID: fix match when uuid is an empty string rkt/uuid: fix match when uuid is an empty string Jun 21, 2016
@lucab
lucab merged commit 578e59a into rkt:master Jun 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants