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

Fix start cluster when docker container is connected to several networks #18943

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ead9e4e
Move runStatusCmd in helpers_tests.go
fredericgermain Jun 16, 2024
c2b297a
Adding extnet_test.go
fredericgermain Jun 16, 2024
d07bee9
Fix StartHost failed when docker container is connected to several ne…
fredericgermain May 21, 2024
dc70b5a
Skipping extnet_test.go on non-Docker driver
fredericgermain Jun 16, 2024
df6834a
Fix indent in kic.go
fredericgermain Aug 5, 2024
29ad523
Consistent naming with containerName and networkName
fredericgermain Aug 5, 2024
1775aa1
Remove fail function in extnet_test
fredericgermain Aug 5, 2024
f1d5516
Fixing typos in extnet_test
fredericgermain Aug 5, 2024
508e546
Fixing indent in helpers_test.go
fredericgermain Aug 5, 2024
c6e8f7f
Remove DriverArg function
fredericgermain Aug 5, 2024
4325226
Remove ContainerRuntime condition
fredericgermain Aug 5, 2024
3d19470
Remove self-explanatory comment
fredericgermain Aug 5, 2024
1f7c2a6
Remove hard-coded network parameters in extnet_test
fredericgermain Aug 5, 2024
8e1d062
Change main function and description in extnet_test
fredericgermain Aug 5, 2024
7e12e7e
Simplify with PostMortemLogs
fredericgermain Aug 12, 2024
b57db32
Linting validateFunc and use globals
fredericgermain Aug 12, 2024
274d5e0
Checking if IPs do not change on restart in extnet_test
fredericgermain Aug 7, 2024
45e47f5
Use CleanupExtnet in main test defer
fredericgermain Aug 12, 2024
faf3698
Use t.Fatalf on failure
fredericgermain Aug 12, 2024
73de293
Use t.Logf for logs
fredericgermain Aug 12, 2024
ffa45f3
Move extnet_test.go to multinetwork_test.go
fredericgermain Aug 12, 2024
b8872cb
Prefix function based on new test name
fredericgermain Aug 12, 2024
8d6b178
Use t.Fatal on error
fredericgermain Aug 12, 2024
12d5b9b
Fix comment
fredericgermain Aug 31, 2024
c9b3261
Fix nit ctx2
fredericgermain Aug 31, 2024
ac32a10
Do not ignore error
fredericgermain Aug 31, 2024
91bbfc8
Swap Cleanup and CleanupExtnet order
fredericgermain Aug 31, 2024
b42087f
Adding multinetworkValidateNetworks to test networks after restart
fredericgermain Aug 31, 2024
76de6d1
Handle PostMortemLogs like in image_test
fredericgermain Aug 31, 2024
a95fbdf
Move VerifyDeletedResources at the end, check extnet removed
fredericgermain Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ func (d *Driver) DriverName() string {

// GetIP returns an IP or hostname that this host is available at
func (d *Driver) GetIP() (string, error) {
ip, _, err := oci.ContainerIPs(d.OCIBinary, d.MachineName)
networkName := d.NodeConfig.Network
if networkName == "" {
networkName = d.NodeConfig.ClusterName
}

ip, _, err := oci.ContainerIPs(d.OCIBinary, d.MachineName, networkName)
return ip, err
}

Expand Down
19 changes: 10 additions & 9 deletions pkg/drivers/kic/oci/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,25 @@ func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
}

// ContainerIPs returns ipv4,ipv6, error of a container by their name
func ContainerIPs(ociBin string, name string) (string, string, error) {
func ContainerIPs(ociBin string, containerName string, networkName string) (string, string, error) {
if ociBin == Podman {
return podmanContainerIP(ociBin, name)
return podmanContainerIP(ociBin, containerName, networkName)
}
return dockerContainerIP(ociBin, name)
return dockerContainerIP(ociBin, containerName, networkName)
}

// podmanContainerIP returns ipv4, ipv6 of container or error
func podmanContainerIP(ociBin string, name string) (string, string, error) {
func podmanContainerIP(ociBin string, containerName string, networkName string) (string, string, error) {
rr, err := runCmd(exec.Command(ociBin, "container", "inspect",
"-f", "{{.NetworkSettings.IPAddress}}",
name))
containerName))
if err != nil {
return "", "", errors.Wrapf(err, "podman inspect ip %s", name)
return "", "", errors.Wrapf(err, "podman inspect ip %s %s", containerName, networkName)
}
output := strings.TrimSpace(rr.Stdout.String())
if output == "" { // podman returns empty for 127.0.0.1
// check network, if the ip address is missing
ipv4, ipv6, err := dockerContainerIP(ociBin, name)
ipv4, ipv6, err := dockerContainerIP(ociBin, containerName, networkName)
if err == nil {
return ipv4, ipv6, nil
}
Expand All @@ -225,9 +225,10 @@ func podmanContainerIP(ociBin string, name string) (string, string, error) {
}

// dockerContainerIP returns ipv4, ipv6 of container or error
func dockerContainerIP(ociBin string, name string) (string, string, error) {
func dockerContainerIP(ociBin string, containerName string, networkName string) (string, string, error) {
// retrieve the IP address of the node using docker inspect
lines, err := inspect(ociBin, name, "{{range .NetworkSettings.Networks}}{{.IPAddress}},{{.GlobalIPv6Address}}{{end}}")
format := fmt.Sprintf("{{with (index .NetworkSettings.Networks %q)}}{{.IPAddress}},{{.GlobalIPv6Address}}{{end}}", networkName)
lines, err := inspect(ociBin, containerName, format)
if err != nil {
return "", "", errors.Wrap(err, "inspecting NetworkSettings.Networks")
}
Expand Down
17 changes: 17 additions & 0 deletions test/integration/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/minikube/pkg/kapi"
"k8s.io/minikube/pkg/minikube/constants"
)

// RunResult stores the result of an cmd.Run call
Expand Down Expand Up @@ -687,3 +688,19 @@ func CopyDir(src, dst string) error {

return nil
}

// runStatusCmd runs the status command and returns stdout
func runStatusCmd(ctx context.Context, t *testing.T, profile string, increaseEnv bool) []byte {
// make sure minikube status shows insufficient storage
c := exec.CommandContext(ctx, Target(), "status", "-p", profile, "--output=json", "--layout=cluster")
// artificially set /var to 100% capacity
if increaseEnv {
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestDiskUsedEnv))
}
rr, err := Run(t, c)
// status exits non-0 if status isn't Running
if err == nil {
t.Fatalf("expected command to fail, but it succeeded: %v\n%v", rr.Command(), err)
}
return rr.Stdout.Bytes()
}
Loading