Skip to content

fix #1096#1097

Closed
doronp wants to merge 2 commits intomoby:masterfrom
doronp:Fix-#1096
Closed

fix #1096#1097
doronp wants to merge 2 commits intomoby:masterfrom
doronp:Fix-#1096

Conversation

@doronp
Copy link
Contributor

@doronp doronp commented Jun 29, 2016

Signed-off-by: Doron Podoleanu [email protected]

@doronp
Copy link
Contributor Author

doronp commented Jun 29, 2016

I doubt it has any thing to do with the actual change. Any advice?

@aaronlehmann
Copy link
Collaborator

@doronp: I triggered a rebuild in CI. I will look into the test failures.

@codecov-io
Copy link

codecov-io commented Jun 29, 2016

Current coverage is 54.96%

Merging #1097 into master will increase coverage by 0.06%

@@             master      #1097   diff @@
==========================================
  Files            77         77          
  Lines         12193      12188     -5   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           6694       6699     +5   
+ Misses         4579       4569    -10   
  Partials        920        920          

Sunburst

Powered by Codecov. Last updated by eacedad...82446c9

@aluzzardi
Copy link
Member

@doronp Doesn't this break name lookup?

@doronp
Copy link
Contributor Author

doronp commented Jun 30, 2016

@aluzzardi Your actually right. Surprised the tests passed. We should add such a test. Now full Id, short ID and name should work in that order.

@aluzzardi
Copy link
Member

Thanks @doronp! Yeah there are no CLI tests - it's an example/debugging/advanced CLI, the typical way to use SwarmKit is through Docker (which has CLI tests).

I think we should try name before short ID: full ID -> name -> short ID.

The reason is a name is less ambiguous than a short ID: for instance if you have a service named "foo" and a short ID that starts with "foo", you are probably referred to the name rather than the short ID.

@doronp
Copy link
Contributor Author

doronp commented Jul 1, 2016

@aluzzardi I made name lookup come before Id prefix. Agree with your reasoning.

rl, e1 := getNetworkByPrefixedID(ctx, c, input)
if e1 == nil {
return rl, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If e1 is not nil, we will make it to the bottom of this function and return nil, nil.

I think this should be

if e1 != nil {
        return nil, e1
}

Copy link
Contributor Author

@doronp doronp Jul 7, 2016

Choose a reason for hiding this comment

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

@aaronlehmann Almost. It'd actually get panic trying to return rg.Network but rg would be nil.
So I think I've fixed that including using the != as suggested. Also changed rl to net to differentiate it from rg.

Thanks for pointing that problem out!

@doronp doronp force-pushed the Fix-#1096 branch 3 times, most recently from cde901d to 54f0c3e Compare July 7, 2016 14:02
@aaronlehmann
Copy link
Collaborator

LGTM

ping @aluzzardi

@dongluochen
Copy link
Contributor

LGTM

@doronp
Copy link
Contributor Author

doronp commented Jul 19, 2016

@aaronlehmann
Your last merge conflicted with this one because of one of its parents. I resolved that conflict.

@aaronlehmann
Copy link
Collaborator

Taking another look at this, I'm concerned that this introduces different behavior for networks relative to the other object types.

For example, getService looks like this:

func getService(ctx context.Context, c api.ControlClient, input string) (*api.Service, error) {
        // GetService to match via full ID.
        rg, err := c.GetService(ctx, &api.GetServiceRequest{ServiceID: input})
        if err != nil {
                // If any error (including NotFound), ListServices to match via ID prefix and name prefix.
                rl, err := c.ListServices(ctx,
                        &api.ListServicesRequest{
                                Filters: &api.ListServicesRequest_Filters{
                                        NamePrefixes: []string{input},
                                },
                        },
                )
                if err != nil {
                        return nil, err
                }

                if len(rl.Services) == 0 {
                        return nil, fmt.Errorf("service %s not found", input)
                }

                if l := len(rl.Services); l > 1 {
                        return nil, fmt.Errorf("service %s is ambiguous (%d matches found)", input, l)
                }

                return rl.Services[0], nil
        }
        return rg.Service, nil
}

It doesn't seem right for networks to support ID prefixes if services do not.

Let's update all object types to support ID prefix matches.

rl, err := c.ListNetworks(ctx,
&api.ListNetworksRequest{
Filters: &api.ListNetworksRequest_Filters{
NamePrefixes: []string{input},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this should use NamePrefixes. That introduces some additional ambiguity.

@doronp
Copy link
Contributor Author

doronp commented Jul 20, 2016

@aaronlehmann
1 - The naming 'NamePrefixes' is actually taken from your change :-) So I can revert it.
2 - I was planning on following with the services PR once this goes in. If you wish I can Do it sooner.

Thanks

@doronp doronp mentioned this pull request Jul 20, 2016
@aaronlehmann
Copy link
Collaborator

Yes, I think we should do all object types at once.

@doronp
Copy link
Contributor Author

doronp commented Jul 20, 2016

@aaronlehmann Done. Please see #1194

@doronp
Copy link
Contributor Author

doronp commented Jul 27, 2016

Are we good to go with this and PR #1194?

@dperny
Copy link
Collaborator

dperny commented Aug 12, 2016

@aaronlehmann are you happy with this? Can we make a decision on merge or close?

@aaronlehmann
Copy link
Collaborator

There should be a single PR that makes the relevant changes for all object types at once, including task, cluster, etc. We can't introduce inconsistencies between the object types.

Also, it would be very helpful to have more descriptive PR titles and summaries.

@dperny
Copy link
Collaborator

dperny commented Aug 12, 2016

Alright, sounds like we can close this.

@doronp feel free to open a new PR with @aaronlehmann's suggestions and a better title and description.

@dperny dperny closed this Aug 12, 2016
@thaJeztah
Copy link
Member

@aaronlehmann @dperny for some background discussion on order of preference (and a CVE we once had in docker/docker), see the discussion here moby/moby#13286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants