-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix moby/moby #37229 allowing to create networks even there are no services attached to it when deploying stacks #1120
base: master
Are you sure you want to change the base?
Conversation
cli/compose/convert/compose.go
Outdated
network := networks[networkName] | ||
if network.External.External { | ||
externalNetworks = append(externalNetworks, network.Name) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
if network.External.External {
externalNetworks = append(externalNetworks, network.Name)
} else{
result[networkName] = networkCreateOptions(namespace, network)
}
Thank you @jaswdr for this PR! The design is ok for me, what do you think of this feature @thaJeztah @vdemeester ? |
Design works for me as well; I don't think we stated that a compose file must contain services, so a file that only has networks (or other objects) should work. I see the second commit doesn't have a |
We should also have a test added for this 👍 |
of course @thaJeztah, sorry for this, I will correct this now |
Signed-off-by: Jonathan A. Schweder <[email protected]>
@thaJeztah done |
Signed-off-by: Jonathan A. Schweder <[email protected]>
test created |
cli/compose/convert/compose_test.go
Outdated
namespace := Namespace{name: "foo"} | ||
serviceNetworks := map[string]struct{}{} | ||
source := networkMap{ | ||
"normal": composetypes.NetworkConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only one NetworkConfig, whatever it is, is enough to test the feature? The test would be then more compact and less redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@silvin-lubecki did you mean, add the content of the TestNetworksCreatedWithoutServices
into the TestNetworks
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meant remove all network configs except one, like named, in this test 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this should do the job I guess
func TestNetworksCreatedWithoutServices(t *testing.T) {
namespace := Namespace{name: "foo"}
serviceNetworks := map[string]struct{}{}
source := networkMap{
"named": composetypes.NetworkConfig{
Name: "othername",
},
}
expected := map[string]types.NetworkCreate{
"named": {
Labels: map[string]string{
LabelNamespace: "foo",
},
},
}
networks, externals := Networks(namespace, source, serviceNetworks)
assert.DeepEqual(t, expected, networks)
assert.DeepEqual(t, []string{"special"}, externals)
}
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I'll change this and remove the unecessary content
Signed-off-by: Jonathan A. Schweder <[email protected]>
@silvin-lubecki simplified test 😄 |
Thank you @jaswdr 👍 ! |
The problem I can think of with this PR is that it doesn't act the same as That said I would be in favor of this PR so let me ping @shin- @dnephin and @thaJeztah to have their thoughts on that 👼 |
@vdemeester if I make another PR to compose to handle the same behavior has this one, did you agree it is ok? |
@jaswdr yes 👼 I wanted to have @shin- @thaJeztah or @dnephin's opinion before suggesting you that though (so that you don't work on something if we don't reach consensus on whether we wanna do that or not). |
Yes we should match the behavior in compose as well (also see my earlier comment #1120 (comment)) |
- What I did
Make
docker stack deploy
create networks even if there are no services attached to it, so you can create stack files for networks only- How I did it
Change
cli/compose/convert/compose.go
to consider thenetworks
map whenservicesNetworks
lenght is equals 0- How to verify it
The issue #37229 in moby repo has more information about how to reproduce the error
- Description for the changelog
Support deploy network only stacks