Skip to content

Make compose file allow to specify names for non-external volume - #306

Merged
thaJeztah merged 2 commits into
docker:masterfrom
lipingxue:new_compose_fix.liping
Jul 27, 2017
Merged

Make compose file allow to specify names for non-external volume#306
thaJeztah merged 2 commits into
docker:masterfrom
lipingxue:new_compose_fix.liping

Conversation

@lipingxue

Copy link
Copy Markdown
Contributor

- 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 convertVolumeToMount accordingly.
- How to verify it

  1. Try docker stack deploy with the following yaml file(specify customized volume name for non-external volume), and it works as expected
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# cat /root/postgres2.yml version: "3.3"
services:
postgres:
image: postgres
ports:
- "5432:5432"
volumes:
- postgres_vol:/var/lib/data
environment:
- "POSTGRES_PASSWORD=secretpass"
- "PGDATA=/var/lib/data/db"
deploy:
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == worker
volumes:
postgres_vol:
name: "postgres_vol@sharedVmfs-1"
driver: "vsphere"
driver_opts:
size: "1GB"
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# ./docker-linux-amd64 stack deploy -c /root/postgres2.yml postgres
Creating network postgres_default
Creating service postgres_postgres
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# docker volume ls
DRIVER VOLUME NAME
vsphere:latest postgres_vol@sharedVmfs-1
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# docker service ps postgres_postgres ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
qx2nvqqwcqyu postgres_postgres.1 postgres:latest sc-rdops-vm02-dhcp-52-237 Running Running 12 seconds ago 
  1. Try docker stack deploy with the following yaml file(specify volume name for external volume), and it returns with proper error
root@sc-rdops-vm02-dhcp-52-237:~# cat postgres_external.yml version: "3.3"
services:
postgres:
image: postgres
ports:
- "5432:5432"
volumes:
- postgres_vol:/var/lib/data
environment:
- "POSTGRES_PASSWORD=secretpass"
- "PGDATA=/var/lib/data/db"
deploy:
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == worker
volumes:
postgres_vol:
external:
name: "postgres@sharedVmfs-1"
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# ./docker-linux-amd64 stack deploy -c /root/postgres_external.yml postgres
Creating network postgres_default
service postgres: cannot specify external volume name "postgres@sharedVmfs-1"
root@sc-rdops-vm02-dhcp-52-237:~/tmp_with_fix# docker stack ls
NAME SERVICES

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)
image

@lipingxuelipingxue changed the title New compose fix.lipingMake compose file allow to specify names for non-external volumeJul 6, 2017
@lipingxue
lipingxueforce-pushed the new_compose_fix.liping branch from d671412 to 57a44fcCompareJuly 6, 2017 21:10

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We still need this block to support External.External.

We could also add a deprecation message in the loader

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@dnephin Thanks for your review.

  1. 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.
  2. 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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the warning would go around here:

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.

@codecov-io

codecov-io commented Jul 7, 2017

Copy link
Copy Markdown

Codecov Report

Merging #306 into master will decrease coverage by 0.64%.
The diff coverage is 100%.

@@ 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

@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@dnephin I have addressed your comments and also have some questions for you. Please take a look. Thanks!

Comment threadcli/compose/loader/loader.go Outdated
volume.External.Name = name
volumes[name] = volume
} else {
return nil, externalVolumeError(name, "name")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I think this should be just a warning, not an error.

You can print a warning with logrus.Warnf()

@lipingxue
lipingxueforce-pushed the new_compose_fix.liping branch 2 times, most recently from 5d0dc47 to b6fc974CompareJuly 12, 2017 19:04
@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@dnephin I have addressed your comments, and please take a look. Thanks.

@dnephin
dnephinforce-pushed the new_compose_fix.liping branch 2 times, most recently from ee34a30 to 9ada891CompareJuly 14, 2017 21:20

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@dockerdocker deleted a comment from GordonTheTurtleJul 17, 2017
@vdemeester
vdemeester self-requested a review July 17, 2017 07:38
@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@dnephin Thanks. I will look at loader_test.go and convert/volume_test.go to figure out how to add the test.

@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@dnephin I have added unit test and repushed the commit. Please review it. Thanks!

Signed-off-by: Daniel Nephin <dnephin@docker.com>
@lipingxue
lipingxueforce-pushed the new_compose_fix.liping branch from 7a63629 to ab4de41CompareJuly 19, 2017 21:26
@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@dnephin I have rebased to get v3.4 schema and addressed your comments. Please review it. Thanks!

@thaJeztahthaJeztah left a comment

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.

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"

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.

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")

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. Add the comment.

# Values can be strings or numbers
foo: "bar"
baz: 1

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'd like to see an example using a name and external, for example;

external-volume3:
name: this-is-volume3external: true

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.

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.namename: custom-nameexternal:
name: conflicting-name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A separate test case for testing the conflict would be great

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. Add a test case in for that.


// VolumeConfig for a volume
type VolumeConfig struct {
Name string

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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.

Updating the docs, and mentioning that could be ok?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. Add a comment in the struct.

@dnephin

Copy link
Copy Markdown
Contributor

for consistency; should the same change be applied to networks, configs, and secrets?

Yes, but I was going to handle it after this PR merges. I think we need to refactor these objects to share more code.

@dnephin

Copy link
Copy Markdown
Contributor

hmm, webhooks didn't trigger on this PR either. This is becoming a problem

@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah I have addressed your comments, and please review it.

Comment threadcli/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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe "is deprecated in favor of", to avoid using "please" and also avoid the comma splice.

Comment threadcli/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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also has a comma splice. It should be two sentences, or a semicolon instead of the comma.

Comment threadcli/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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comma splice.

@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@mstanleyjones I have addressed your comments, and please take a look.

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@thaJeztahthaJeztah left a comment

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.

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>
@lipingxue
lipingxueforce-pushed the new_compose_fix.liping branch from 7761b1b to 27a3080CompareJuly 27, 2017 22:12
@lipingxue

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah I have squashed the comments, please review it. Thanks!

@thaJeztahthaJeztah left a comment

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.

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

@thaJeztahthaJeztah added this to the 17.08.0 milestone Jul 27, 2017
@thaJeztah
thaJeztah merged commit 7524912 into docker:masterJul 27, 2017
@hairyhenderson

Copy link
Copy Markdown
Contributor

This is awesome! Thanks @lipingxue 🎉

@kvncrw

Copy link
Copy Markdown

@dnephin is there an issue open regarding?

networks, configs, and secrets

@dnephin

Copy link
Copy Markdown
Contributor

I don't think there are any open issues for the other objects

Sign up for freeto 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.

[Compose file] allow names for non-external volumes

8 participants

@lipingxue@codecov-io@dnephin@hairyhenderson@kvncrw@thaJeztah@mdlinville@GordonTheTurtle