-
Notifications
You must be signed in to change notification settings - Fork 5k
Add --network flag to select docker network to run with docker driver #9538
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fe27107
Add --docker-network flag
8b4c481
implement --docker-network flag
9474740
Add integration test
e807362
update docs
20db128
add warning
ebf6122
Fix merge conflict
ea6ca08
Change flag name to --network and exit if used without docker driver
267769c
update docs
19b2be2
fix merge conflict
cca6246
switch exit to warning
9bb9355
fix merge conflict
ad85a7a
rename containernetwork to network
572e22d
Merge branch 'master' of https://github.com/kubernetes/minikube into …
14db0de
review comments
a6a6671
make integration tests more robust
f373155
merge conflict
37bcf6d
fix lint
55f4964
fix merge conflict
787cf77
Only run existing network test with kic driver
81f00fc
update description
bd41379
Avoid creating network if it is the default
a3b80e1
add log
322efcb
Merge branch 'master' of https://github.com/kubernetes/minikube into …
e210a72
update warning
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// +build integration | ||
|
||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/minikube/pkg/drivers/kic/oci" | ||
) | ||
|
||
func TestKicCustomNetwork(t *testing.T) { | ||
if !KicDriver() { | ||
t.Skip("only runs with docker driver") | ||
} | ||
|
||
tests := []struct { | ||
description string | ||
networkName string | ||
}{ | ||
{ | ||
description: "create custom network", | ||
medyagh marked this conversation as resolved.
Show resolved
Hide resolved
priyawadhwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, { | ||
description: "use default bridge network", | ||
networkName: "bridge", | ||
}, | ||
priyawadhwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
profile := UniqueProfileName("docker-network") | ||
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5)) | ||
defer Cleanup(t, profile, cancel) | ||
|
||
startArgs := []string{"start", "-p", profile, fmt.Sprintf("--network=%s", test.networkName)} | ||
c := exec.CommandContext(ctx, Target(), startArgs...) | ||
medyagh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rr, err := Run(t, c) | ||
if err != nil { | ||
t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output()) | ||
} | ||
nn := test.networkName | ||
if nn == "" { | ||
nn = profile | ||
} | ||
verifyNetworkExists(ctx, t, nn) | ||
}) | ||
} | ||
} | ||
|
||
func TestKicExistingNetwork(t *testing.T) { | ||
if !KicDriver() { | ||
t.Skip("only runs with docker driver") | ||
} | ||
// create custom network | ||
networkName := "existing-network" | ||
if _, err := oci.CreateNetwork(oci.Docker, networkName); err != nil { | ||
t.Fatalf("error creating network: %v", err) | ||
} | ||
defer func() { | ||
if err := oci.DeleteKICNetworks(oci.Docker); err != nil { | ||
t.Logf("error deleting kic network, may need to delete manually: %v", err) | ||
} | ||
}() | ||
profile := UniqueProfileName("existing-network") | ||
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5)) | ||
defer Cleanup(t, profile, cancel) | ||
|
||
verifyNetworkExists(ctx, t, networkName) | ||
|
||
startArgs := []string{"start", "-p", profile, fmt.Sprintf("--network=%s", networkName)} | ||
c := exec.CommandContext(ctx, Target(), startArgs...) | ||
rr, err := Run(t, c) | ||
if err != nil { | ||
t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output()) | ||
} | ||
} | ||
|
||
func verifyNetworkExists(ctx context.Context, t *testing.T, networkName string) { | ||
c := exec.CommandContext(ctx, "docker", "network", "ls", "--format", "{{.Name}}") | ||
rr, err := Run(t, c) | ||
if err != nil { | ||
t.Fatalf("%v failed: %v\n%v", rr.Command(), err, rr.Output()) | ||
} | ||
if output := rr.Output(); !strings.Contains(output, networkName) { | ||
t.Fatalf("%s network is not listed by [%v]: %v", networkName, c.Args, output) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.