Skip to content

Detect single-value advanced syntax#2243

Merged
silvin-lubecki merged 3 commits into
docker:masterfrom
zappy-shu:2058-single-value-advanced-syntax
Jan 13, 2020
Merged

Detect single-value advanced syntax#2243
silvin-lubecki merged 3 commits into
docker:masterfrom
zappy-shu:2058-single-value-advanced-syntax

Conversation

@zappy-shu

Copy link
Copy Markdown
Contributor

- What I did

Adds the ability to just specify the source for config and secret flags using the advanced syntax as per https://docs.docker.com/engine/reference/commandline/service_create/#create-a-service-with-secrets. When the target is not specified the target is set to the source, same as when using the simple syntax.

- How I did it

When checking if the user is using the simple syntax check if the field contains an = as well as checking if there is more than one field.

- How to verify it

Unit tests have been added for just setting the source for both secrets and configs (all existing test cases for secrets have been copied for configs as well).

To manually test, follow the steps in #2058

- Description for the changelog

Fixes #2058 allowing the use of the advanced syntax when setting a config or secret with only the source field.

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

hedgehog-2019-11-07

Comment thread opts/config_test.go Outdated

@silvin-lubecki silvin-lubecki 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 thank you @zappy-shu 👍

@thaJeztah thaJeztah 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! left two minor nits, also, I'd recommend removing the fixes xxx from the commit message of the first commit. In this particular case, it probably won't cause much harm, but GitHub is quite "eager" to close issues based on commit messages. Putting fixes in the commit message itself can cause issues to be closed prematurely if someone in another repository merges the commit (particularly annoying if the "fix" doesn't take effect until it's vendored in another repository);

Fixes #2058 allowing the use of the advanced source=x syntax for config and secret values when there is no comma

Generally, I only add the fixes in the PR description on GitHub, but not in the commit message for that reason

perhaps the first and last commit should be squashed (as the last one fixes up tests that were added in the first one); keeping the second one separate looks good to me (because it's a change in behavior, and to make it stand out better)

Comment thread opts/config_test.go
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

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.

Can you change this to

Suggested change
t.Run(tc.name, func(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {

see moby/moby#40115 (comment) (and https://blog.golang.org/subtests)

Comment thread opts/secret_test.go
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

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.

same here

Suggested change
t.Run(tc.name, func(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {

see moby/moby#40115 (comment) (and https://blog.golang.org/subtests)

Allow the use of the advanced source=x syntax for config and secret values when there is no comma

Before this change the following would fail with config not found:
	docker service create --name hello1 --config source=myconfig nginx:alpine
And the following would fail with secret not found:
	docker service create --name hello2 --secret source=mysecret nginx:alpine

Signed-off-by: Nick Adcock <[email protected]>
When using advanced syntax for setting config and secret values, default
the target value to the source value when the user does not specify a
target.

Signed-off-by: Nick Adcock <[email protected]>
Refactors the config and secret unit tests to be table driven to remove
duplication

Signed-off-by: Nick Adcock <[email protected]>
@zappy-shu
zappy-shu force-pushed the 2058-single-value-advanced-syntax branch from d91b50a to 3baa6d5 Compare January 9, 2020 13:39

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

@silvin-lubecki silvin-lubecki 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.

Still LGTM 👍

@silvin-lubecki
silvin-lubecki merged commit 34d8486 into docker:master Jan 13, 2020
@thaJeztah thaJeztah added this to the next milestone Feb 5, 2020
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.

service create/update doesn't detect single-value advanced syntax

4 participants