8000 Closes #9311 Handles container id/name collisions against daemon functionalities according to #8069 by acbodine · Pull Request #9705 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Closes #9311 Handles container id/name collisions against daemon functionalities according to #8069 #9705

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

Conversation

acbodine
Copy link
Contributor

Changes truncindex package to properly report when multiple results were found with a given prefix

Modifies Daemon Get method according to the discussion in #8069

Fixes references to Daemon Get throughout. Mostly just ignoring the error message that is now returned, but replacing redundant logic where applicable. These clean-ups could have been more pervasive but I believe they will be easier to carry out once Docker has some notion of error lists defined to replace all of the hard-coded error messages.

@estesp
Copy link
Contributor
estesp commented Dec 17, 2014

@acbodine thanks for attacking this.. definitely a big set of changes to handle all the calls to daemon.Get(). The temporary patch is not required, right? Can that be squashed or why is it in the PR?

Also, I was surprised to see more changes to truncindex than just the addition of a dup ID error; a lock and deferred unlock? Can you add some comments on why additional changes were necessary--mostly because I'm curious :)

// continue
// }
// }

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just the commented out version of the original code for 'inspect"? I think you can remove from the commit for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to delete

@crosbymichael crosbymichael added this to the 1.5.0 milestone Dec 17, 2014
@crosbymichael
Copy link
Contributor

The general theme in this PR is that you added an error return result to many of the get methods for fetching containers from the daemon. However, you are only consuming these errors in your specific case.

I think you could be consistent and always consume the errors and forget all the container == nil checks now that the methods all return (*Container, error). It's much more Go like now with the error and I think we should use it. What do you think about making that change?

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch 3 times, most recently from 762aa7a to e32e38e Compare December 17, 2014 20:00
@acbodine
Copy link
Contributor Author

@crosbymichael I totally agree with utilizing the errors returned from the daemon, and as you noted I have made some of those changes in the corresponding daemon methods that reference daemon.Get() The references that are returning an error message that doesn't quite match the error returned from the daemon are the ones that I left untouched. I'll set out on making these references more Go-like.

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from e32e38e to a296e57 Compare December 17, 2014 21:45
@acbodine
Copy link
Contributor Author

@crosbymichael I think this should be all set now, utilizing the errors returned from daemon.Get

@crosbymichael
Copy link
Contributor

@acbodine thanks, we will take another look soon

@@ -43,6 +44,11 @@ import (
)

var (
ErrNotFound = errors.New("No such container: %s")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is used only in one place apart from tests and it is very confusing. Maybe just return this where it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was meant to replace as many of the in place fmt.Errorf("No such container...") and I think it is necessary because this isn't the only error that can be returned from daemon.Get anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is absolutely not necessary, because this is daemon.ErrNotFound. And making errors with %s is something which shouldn't be used. Now, instead of fmt.Errorf("No such container: %s", c) you need to write fmt.Sprintf(ErrNotFound.Error(), c), and it is only in two places, so you saved TWO symbols at the expense of having very strange line here. At least this should be just string, not error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I think I see what you mean. I'm making the changes. Getting rid of the static errors in favor of the in-place fmt.Errorf("...") and putting the verbose errors in the truncindex. As you suggested, will just return the errors from truncindex. Should be pushing these changes here soon.

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch 2 times, most recently from c296eba to 008f690 Compare December 18, 2014 20:29
@acbodine
Copy link
Contributor Author

@LK4D4 @crosbymichael is this ready to go now?

if container := daemon.Get(name); container != nil {

if container, err := daemon.Get(name); err != nil {
return job.Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't really need the else here if you are returning in the above if

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from 008f690 to acd16cd Compare January 5, 2015 22:24
@acbodine
Copy link
Contributor Author
acbodine commented Jan 5, 2015

@jfrazelle the else statements have been cleaned up

ErrNoID = errors.New("prefix can't be empty")
errDuplicateID = errors.New("multiple IDs were found")
ErrEmptyPrefix = errors.New("Prefix can't be empty")
ErrAmbiguousPrefix = errors.New("Too many containers found with provided prefix")
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this is a generic package you should not have the word contianers in the error message. It mostly deals with strings as this is an index.

Can you change this to be something more generic for this package?

@estesp
Copy link
Contributor
estesp commented Jan 6, 2015

FYI @acbodine you will have to rebase due to the "log when truncIndex returns > 1" PR that was merged today. Given it had similar goals, except didn't go to the length of changing the Get() signature, you'll have to figure out how to including the logging (assuming that is still desired) as that will probably be the main conflict area with your patch.

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch 2 times, most recently from f660dfe to dd77682 Compare January 7, 2015 02:18
@acbodine

Copy link
Contributor Author
acbodine commented Jan 7, 2015

@crosbymichael I adjusted the error messages to be more generic.

}

if err == truncindex.ErrDuplicateID {
log.Errorf("Short ID %s is ambiguous: please retry with more characters or use the full ID.\n", name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The necessity for this log message isn't very clear to me. It's contents seem to be targeted for the cli user, but the user will never see this message unless they had access to, and are viewing the daemon logs. What's the purpose of this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, looks like someone was just confused as it looks like a client side message, should be safe to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the unnecessary daemon log.

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from b6a4f56 to 3acd52f Compare January 9, 2015 03:22
@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from 3acd52f to 4334893 Compare January 20, 2015 23:07
@acbodine
Copy link
Contributor Author

ping @crosbymichael ... rebased


// prefix is an exact match to a full container Name
return containerByName, nil
} else if containerId != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for else since you use return in the if part

@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch 8 times, most recently from 389cb85 to 8fe451c Compare January 21, 2015 19:30
@crosbymichael crosbymichael removed this from the 1.5.0 milestone Jan 21, 2015
@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from 8fe451c to 3f50629 Compare January 22, 2015 00:16
…functionalities according to moby#8069

Signed-off-by: Andrew C. Bodine <acbodine@us.ibm.com>
@acbodine acbodine force-pushed the 9311-truncindex-error-duplicate-id-on-ambiguous-id branch from 3f50629 to d25a653 Compare January 22, 2015 01:11
@acbodine
Copy link
Contributor Author

@crosbymichael @jfrazelle any more comments on this one?

@LK4D4
Copy link
Contributor
LK4D4 commented Feb 6, 2015

@acbodine Thank you. Nex time pls post "Closes *" info on second line of commit message.
LGTM

@crosbymichael crosbymichael added this to the 1.6.0 milestone Feb 6, 2015
@crosbymichael
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0