Skip to content
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

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

Merged
merged 2 commits into from
Jul 27, 2017

Conversation

lipingxue
Copy link
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

@lipingxue lipingxue changed the title New compose fix.liping Make compose file allow to specify names for non-external volume Jul 6, 2017
Copy link
Contributor

@dnephin dnephin left a comment

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
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
Contributor Author

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
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
Copy link

codecov-io commented Jul 7, 2017

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
Contributor Author

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

@@ -444,6 +444,8 @@ func LoadVolumes(source map[string]interface{}) (map[string]types.VolumeConfig,
if volume.External.Name == "" {
volume.External.Name = name
volumes[name] = volume
} else {
return nil, externalVolumeError(name, "name")
Copy link
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 lipingxue force-pushed the new_compose_fix.liping branch 2 times, most recently from 5d0dc47 to b6fc974 Compare July 12, 2017 19:04
@lipingxue
Copy link
Contributor Author

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

@dnephin dnephin force-pushed the new_compose_fix.liping branch 2 times, most recently from ee34a30 to 9ada891 Compare July 14, 2017 21:20
Copy link
Contributor

@dnephin dnephin left a comment

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.

@docker docker deleted a comment from GordonTheTurtle Jul 17, 2017
@vdemeester vdemeester self-requested a review July 17, 2017 07:38
@lipingxue
Copy link
Contributor Author

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

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

Signed-off-by: Daniel Nephin <[email protected]>
@lipingxue
Copy link
Contributor Author

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

Copy link
Member

@thaJeztah thaJeztah left a comment

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

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

external-volume:
# Specifies that a pre-existing volume called "external-volume"
# can be referred to within this file as "external-volume"
Copy link
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
Contributor Author

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
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-volume3
    external: true

Copy link
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.name
    name: custom-name
    external:
      name: conflicting-name

Copy link
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
Contributor Author

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.

@@ -305,6 +305,7 @@ type IPAMPool struct {

// VolumeConfig for a volume
type VolumeConfig struct {
Name string
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
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
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
Contributor Author

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
Contributor

dnephin commented Jul 21, 2017

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
Contributor

dnephin commented Jul 21, 2017

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

@lipingxue
Copy link
Contributor Author

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

@@ -444,6 +444,12 @@ func LoadVolumes(source map[string]interface{}) (map[string]types.VolumeConfig,
if volume.External.Name == "" {
volume.External.Name = name
volumes[name] = volume
} else {
logrus.Warnf("volume %s: volume.external.name is deprecated, please use volume.name", name)
Copy link
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.

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


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
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
Contributor Author

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

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

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 <[email protected]>
Change to enable volume name can be customized.
Signed-off-by: Liping Xue <[email protected]>

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 <[email protected]>

Address Daniel's comments to print warning message when name of external volume is set in loader code.
Signed-off-by: Liping Xue <[email protected]>

Address Daniel's comments to return error when external volume is set in loader code.
Signed-off-by: Liping Xue <[email protected]>

Address Daniel's comments to return error when external volume is set in loader code.
Signed-off-by: Liping Xue <[email protected]>

Remove the case that specifying external volume name in full-example.yml.

More fix.

Add unit test.
Signed-off-by: Liping Xue <[email protected]>

Address comments from Daniel, move the schema change to v3.4.
Signed-off-by: Liping Xue <[email protected]>

Address comments from Sebastiaan. Signed-off-by: Liping Xue <[email protected]>

Address comments from Misty.
Signed-off-by: Liping Xue <[email protected]>
@lipingxue
Copy link
Contributor Author

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

Copy link
Member

@thaJeztah thaJeztah left a comment

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

@thaJeztah thaJeztah added this to the 17.08.0 milestone Jul 27, 2017
@thaJeztah thaJeztah merged commit 7524912 into docker:master Jul 27, 2017
@hairyhenderson
Copy link
Contributor

This is awesome! Thanks @lipingxue 🎉

@kevtainer
Copy link

@dnephin is there an issue open regarding?

networks, configs, and secrets

@dnephin
Copy link
Contributor

dnephin commented Sep 28, 2017

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

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.

[Compose file] allow names for non-external volumes
8 participants