Skip to content

Conversation

@RenaudWasTaken
Copy link
Contributor

@RenaudWasTaken RenaudWasTaken commented Aug 9, 2017

Signed-off-by: Renaud Gaubert [email protected]

What I did:
Changed the CLI format of Generic Resources as suggested by @thaJeztah in docker/cli/pull/429
From --generic-resources "apple=2;orange={blue,red,green}"
To --generic-resources "apple=2,orange=blue,orange=red,orange=green"

This new format albeit a bit more verbose is the CSV format and is already used for --mount

  • See here for tracking
  • See here for design document

How to verify it:

$ swarmd ... --generic-resources "apple=2,orange=blue,orange=red,orange=green"
$ swarmct service create ... --generic-resources "orange=2,apple=2"

ping @aaronlehmann

@codecov
Copy link

codecov bot commented Aug 10, 2017

Codecov Report

Merging #2347 into master will decrease coverage by <.01%.
The diff coverage is 77.08%.

@@            Coverage Diff             @@
##           master    #2347      +/-   ##
==========================================
- Coverage   60.52%   60.51%   -0.01%     
==========================================
  Files         128      128              
  Lines       26366    26401      +35     
==========================================
+ Hits        15958    15977      +19     
- Misses       9005     9017      +12     
- Partials     1403     1407       +4

@RenaudWasTaken
Copy link
Contributor Author

Ping @aluzzardi @dongluochen @aaronlehmann :)

// ParseCmd parses the Generic Resource command line argument
// and returns a list of *api.GenericResource
func ParseCmd(cmd string) ([]*api.GenericResource, error) {
if strings.Contains(cmd, "\n") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a strange thing to check for - I don't know of any CLI arguments where this would be an issue, or where we explicitly check for it. But it shouldn't hurt.

// and returns a list of *api.GenericResource
func ParseCmd(cmd string) ([]*api.GenericResource, error) {
if strings.Contains(cmd, "\n") {
return nil, newParseError("unexpected '\n' character")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll want to use backticks instead of double quotes to avoid putting an actual newline inside the erorr stirng.

if len(kva) != 2 {
return nil, newParseError("incorrect term %s, missing '=' or malformed expr", term)
return nil, newParseError("incorrect term %s, missing"+
"'=' or malformed expression", term)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a missing space between missing and =.

if u < 0 {
return nil, newParseError("cannot ask for negative resource %s", key)
return nil, newParseError("cannot ask for"+
"negative resource %s", k)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing space between for and negative.

func Parse(cmd string) ([]*api.GenericResource, error) {
var rs []*api.GenericResource
func namedResourceVal(res string) (int64, error) {
return strconv.ParseInt(res, 10, 64)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this parses as an integer, wouldn't it be a discrete resource, not a named resource as the function name suggests?

}

return nil, newParseError("could not parse expression '%s'", term)
return nil, newParseError("malformed expression '%s=%s'", k, v)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like the only possible error condition is a mix of numeric and non-numeric values. The error message should make this clear.


var rs []*api.GenericResource
for k, v := range tokens {
if len(v) == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about calling a function here that checks that len(v) == 1 and namedResourceVal does not return an error? It would slightly simplify the control flow.

@RenaudWasTaken
Copy link
Contributor Author

@aaronlehmann fixed !

@RenaudWasTaken
Copy link
Contributor Author

@aluzzardi PTAL :)

@RenaudWasTaken
Copy link
Contributor Author

@aaronlehmann is it possible to merge this PR :) ?

@aaronlehmann
Copy link
Collaborator

aaronlehmann commented Oct 12, 2017 via email

@RenaudWasTaken
Copy link
Contributor Author

ping @stevvooe :)

@RenaudWasTaken
Copy link
Contributor Author

ping @aluzzardi @aaronlehmann @stevvooe

Copy link
Contributor

@anshulpundir anshulpundir left a comment

Choose a reason for hiding this comment

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

@RenaudWasTaken some nits.

return strconv.ParseInt(res, 10, 64)
}

func allNamedResources(res []string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

// Parse parses the GenericResource resources given by the arguments
func Parse(cmd string) ([]*api.GenericResource, error) {
var rs []*api.GenericResource
func discreteResourceVal(res string) (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest adding a comment. thx!

return rs, nil
}

func isDiscreteResource(values []string) (int64, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment.

@RenaudWasTaken
Copy link
Contributor Author

@anshulpundir done

@RenaudWasTaken
Copy link
Contributor Author

@anshulpundir CI is green can we finally merge this PR :) ?

@anshulpundir anshulpundir merged commit de950a7 into moby:master Oct 25, 2017
marcusmartins added a commit to marcusmartins/docker that referenced this pull request Nov 3, 2017
Upgrade swarmkit dependency.

Changes:
moby/swarmkit@ce5f7b8a (HEAD -> master, origin/master, origin/HEAD) Merge pull request moby/swarmkit#2411 from crunchywelch/2401-arm64_support
moby/swarmkit@b0856099 Merge pull request moby/swarmkit#2423 from thaJeztah/new-misty-handle
moby/swarmkit@2bd294fc Update Misty's GitHub handle
moby/swarmkit@0769c605 Comments for orphaned state/task reaper. (moby/swarmkit#2421)
moby/swarmkit@de950a7e Generic resource cli (moby/swarmkit#2347)
moby/swarmkit@312be598 Provide custom gRPC dialer to override default proxy dialer (moby/swarmkit#2419)
moby/swarmkit@4f12bf79 Merge pull request moby/swarmkit#2415 from cheyang/master
moby/swarmkit@8f9f7dc1 add pid limits
moby/swarmkit@da5ee2a6 Merge pull request moby/swarmkit#2409 from dperny/workaround-attachments
moby/swarmkit@0c7b2fc2 Delete node attachments when node is removed
moby/swarmkit@9d702763 normalize "aarch64" architectures to "arm64"

moby/swarmkit@28f91d8...ce5f7b8

Signed-off-by: Marcus Martins <[email protected]>
denverdino pushed a commit to AliyunContainerService/swarmkit that referenced this pull request Nov 5, 2017
* Generic resource now uses csv format

Signed-off-by: Renaud Gaubert <[email protected]>

* Tested new input format

Signed-off-by: Renaud Gaubert <[email protected]>

* Updated Generic resource design to use new CLI format

Signed-off-by: Renaud Gaubert <[email protected]>

* Updated swarmctl and swarmd to use the new Generic resource CLI format

Signed-off-by: Renaud Gaubert <[email protected]>
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.

3 participants