Make compose file allow to specify names for non-external volume#306
Make compose file allow to specify names for non-external volume#306thaJeztah merged 2 commits intodocker:masterfrom
Conversation
d671412 to
57a44fc
Compare
dnephin
left a comment
There was a problem hiding this comment.
Thanks!
This looks like a good start. This change will need to be moved to a v3.4 version of the schema, but that doesn't exist yet, so I can take care of it later.
I think we should make this change to networks/configs/secrets as well, so they are all consistent. I can take care of that as well in another PR.
| // External named volumes | ||
| if stackVolume.External.External { | ||
| result.Source = stackVolume.External.Name | ||
| return result, nil |
There was a problem hiding this comment.
We still need this block to support External.External.
We could also add a deprecation message in the loader
There was a problem hiding this comment.
@dnephin Thanks for your review.
- I have added the block back. Could you tell me how to add a deprecation message in the loader? I am not familiar with the loader code.
- ci/circleci: validate test failed. It fails in some vendor Makefile, but I haven't changed anything related to this. Could you help me to take a look? Thanks!
There was a problem hiding this comment.
I think the warning would go around here:
cli/cli/compose/loader/loader.go
Line 447 in 732261f
Probably as an else to that if block
I think the validate problem was fixed on master, so if you rebase it should be fixed.
ee57690 to
00f39c9
Compare
Codecov Report
@@ Coverage Diff @@
## master #306 +/- ##
==========================================
- Coverage 46.14% 45.49% -0.65%
==========================================
Files 193 193
Lines 16073 16069 -4
==========================================
- Hits 7417 7311 -106
- Misses 8269 8380 +111
+ Partials 387 378 -9 |
|
@dnephin I have addressed your comments and also have some questions for you. Please take a look. Thanks! |
00f39c9 to
04c81ed
Compare
cli/compose/loader/loader.go
Outdated
| volume.External.Name = name | ||
| volumes[name] = volume | ||
| } else { | ||
| return nil, externalVolumeError(name, "name") |
There was a problem hiding this comment.
Sorry, I think this should be just a warning, not an error.
You can print a warning with logrus.Warnf()
5d0dc47 to
b6fc974
Compare
|
@dnephin I have addressed your comments, and please take a look. Thanks. |
ee34a30 to
9ada891
Compare
dnephin
left a comment
There was a problem hiding this comment.
Thanks! I've pushed a commit to add a schema for 3.4 and rebased your commit on top of it.
I also adjusted the wording on the warning slightly, and made it an error to set both names.
I think now we just need to add to the full test in loader_test.go and a test in convert/volume_test.go.
|
@dnephin Thanks. I will look at |
9ada891 to
e7c296a
Compare
|
@dnephin I have added unit test and repushed the commit. Please review it. Thanks! |
Signed-off-by: Daniel Nephin <dnephin@docker.com>
7a63629 to
ab4de41
Compare
|
@dnephin I have rebased to get v3.4 schema and addressed your comments. Please review it. Thanks! |
thaJeztah
left a comment
There was a problem hiding this comment.
Thanks @lipingxue - this is great! I left some comments
@dnephin for consistency; should the same change be applied to networks, configs, and secrets? (i.e., network.name instead of network.external.name)?
|
|
||
| external-volume: | ||
| # Specifies that a pre-existing volume called "external-volume" | ||
| # can be referred to within this file as "external-volume" |
There was a problem hiding this comment.
for other-external-volume below, should we update the comment to mention volume.external.name is deprecated? (can't comment on that line, so leaving the comment here 😄)
# This example uses the deprecated "volume.external.name" (replaced by "volume.name")
There was a problem hiding this comment.
Done. Add the comment.
| # Values can be strings or numbers | ||
| foo: "bar" | ||
| baz: 1 | ||
|
|
There was a problem hiding this comment.
I'd like to see an example using a name and external, for example;
external-volume3:
name: this-is-volume3
external: trueThere was a problem hiding this comment.
Also (not sure if that needs to be done in this file, or another one); can we have a test that tests if setting both volume.name and volume.external.name produces the "conflicting options" error? i.e.;
external-volume4-fail:
# name cannot be provided both as volume.name and volume.external.name
name: custom-name
external:
name: conflicting-nameThere was a problem hiding this comment.
A separate test case for testing the conflict would be great
There was a problem hiding this comment.
Done. Add a test case in for that.
|
|
||
| // VolumeConfig for a volume | ||
| type VolumeConfig struct { | ||
| Name string |
There was a problem hiding this comment.
@dnephin should External.Name below (https://github.com/docker/cli/pull/306/files#diff-80e4727ffc215ce8081027b2780b1494L317) be marked deprecated ?
There was a problem hiding this comment.
That link isn't going to any specific line. I don't think we should add it to the lists in types.go, those are for options being deprecated/removed from v2->v3.
In this case maybe just a comment in the struct would be fine
There was a problem hiding this comment.
Updating the docs, and mentioning that could be ok?
There was a problem hiding this comment.
Done. Add a comment in the struct.
Yes, but I was going to handle it after this PR merges. I think we need to refactor these objects to share more code. |
|
hmm, webhooks didn't trigger on this PR either. This is becoming a problem |
|
@thaJeztah I have addressed your comments, and please review it. |
cli/compose/loader/loader.go
Outdated
| volume.External.Name = name | ||
| volumes[name] = volume | ||
| } else { | ||
| logrus.Warnf("volume %s: volume.external.name is deprecated, please use volume.name", name) |
There was a problem hiding this comment.
Maybe "is deprecated in favor of", to avoid using "please" and also avoid the comma splice.
cli/compose/loader/loader.go
Outdated
| logrus.Warnf("volume %s: volume.external.name is deprecated, please use volume.name", name) | ||
|
|
||
| if volume.Name != "" { | ||
| return nil, errors.Errorf("volume %s: volume.external.name and volume.name conflict, only use volume.name", name) |
There was a problem hiding this comment.
This also has a comma splice. It should be two sentences, or a semicolon instead of the comma.
cli/compose/loader/loader_test.go
Outdated
|
|
||
| assert.Error(t, err) | ||
| fmt.Println(err) | ||
| assert.Contains(t, err.Error(), "volume.external.name and volume.name conflict, only use volume.name") |
|
@mstanleyjones I have addressed your comments, and please take a look. |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM, but can you squash your commits ? Thinking of one commit for the compose-file 3.4 bump, and one commit for the other changes
Signed-off-by: Liping Xue <lipingxue@gmail.com> Change to enable volume name can be customized. Signed-off-by: Liping Xue <lipingxue@gmail.com> Change to enable volume name can be customized. Remove unused debug info. Address comments from Daniel and solve the lint error. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address Daniel's comments to print warning message when name of external volume is set in loader code. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address Daniel's comments to return error when external volume is set in loader code. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address Daniel's comments to return error when external volume is set in loader code. Signed-off-by: Liping Xue <lipingxue@gmail.com> Remove the case that specifying external volume name in full-example.yml. More fix. Add unit test. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address comments from Daniel, move the schema change to v3.4. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address comments from Sebastiaan. Signed-off-by: Liping Xue <lipingxue@gmail.com> Address comments from Misty. Signed-off-by: Liping Xue <lipingxue@gmail.com>
7761b1b to
27a3080
Compare
|
@thaJeztah I have squashed the comments, please review it. Thanks! |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM, thanks!
This change needs an update to the documentation; probably in the vnext-compose branch; https://github.com/docker/docker.github.io/tree/vnext-compose/compose/compose-file
but ping @londoncalling for confirmation
also ping @shin- for the implementation in docker-compose
|
This is awesome! Thanks @lipingxue 🎉 |
|
@dnephin is there an issue open regarding?
|
|
I don't think there are any open issues for the other objects |
- What I did
Fixes #274
- How I did it
I changed the config_schema.json to allow names for non-external volumes, and also made change in function
convertVolumeToMountaccordingly.- How to verify it
docker stack deploywith the following yaml file(specify customized volume name for non-external volume), and it works as expecteddocker stack deploywith the following yaml file(specify volume name for external volume), and it returns with proper error- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
