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

Change linux default network-mode to user #4514

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions pkg/crc/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ func GetPreset(config Storage) preset.Preset {
}

func defaultNetworkMode() network.Mode {
if runtime.GOOS != "linux" {
return network.UserNetworkingMode
}
return network.SystemNetworkingMode
return network.UserNetworkingMode
}

func GetNetworkMode(config Storage) network.Mode {
Expand Down
10 changes: 2 additions & 8 deletions pkg/crc/network/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package network

import (
"fmt"
"runtime"

"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/spf13/cast"
Expand Down Expand Up @@ -55,7 +54,7 @@ func parseMode(input string) (Mode, error) {
case string(SystemNetworkingMode), "default":
return SystemNetworkingMode, nil
default:
return SystemNetworkingMode, fmt.Errorf("Cannot parse mode '%s'", input)
return UserNetworkingMode, fmt.Errorf("Cannot parse mode '%s'", input)
}
}
func ParseMode(input string) Mode {
Expand All @@ -68,12 +67,7 @@ func ParseMode(input string) Mode {
}

func getDefaultMode() Mode {
switch runtime.GOOS {
case "linux":
return SystemNetworkingMode
default:
return UserNetworkingMode
}
return UserNetworkingMode
}

func ValidateMode(val interface{}) (bool, string) {
Expand Down
19 changes: 9 additions & 10 deletions test/e2e/features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,20 @@ Feature: Test configuration settings
Examples:
| property | value1 | value2 |
| skip-check-bundle-extracted | true | false |
| skip-check-crc-network | true | false |
| skip-check-crc-network-active | true | false |
| skip-check-kvm-enabled | true | false |
| skip-check-libvirt-driver | true | false |
| skip-check-libvirt-installed | true | false |
| skip-check-libvirt-running | true | false |
| skip-check-libvirt-version | true | false |
| skip-check-network-manager-installed | true | false |
| skip-check-network-manager-running | true | false |
| skip-check-root-user | true | false |
| skip-check-user-in-libvirt-group | true | false |
| skip-check-virt-enabled | true | false |

# the following properties not suit for user notwork
#| skip-check-crc-network | true | false |
#| skip-check-crc-network-active | true | false |
#| skip-check-network-manager-installed | true | false |
#| skip-check-network-manager-running | true | false |

@windows
Examples:
Expand Down Expand Up @@ -118,20 +120,17 @@ Feature: Test configuration settings
When removing file "crc.json" from CRC home folder succeeds
And executing single crc setup command succeeds
And executing "sudo virsh net-list --name" succeeds
Then stdout contains "crc"
When executing "sudo virsh net-undefine crc && sudo virsh net-destroy crc" succeeds
And executing "sudo virsh net-list --name" succeeds
Then stdout should not contain "crc"
Then stdout contains "default"

@linux
@linux @system_network
Scenario: Running `crc setup` with checks enabled restores destroyed network
When setting config property "skip-check-crc-network" to value "false" succeeds
And setting config property "skip-check-crc-network-active" to value "false" succeeds
Then executing single crc setup command succeeds
And executing "sudo virsh net-list --name" succeeds
And stdout contains "crc"

@linux
@linux @system_network
Scenario: Running `crc start` without `crc setup` and with checks disabled fails when network destroyed
# Destroy network again
When executing "sudo virsh net-undefine crc && sudo virsh net-destroy crc" succeeds
Expand Down
30 changes: 24 additions & 6 deletions test/e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,20 @@ func InitializeScenario(s *godog.ScenarioContext) {
}

if tag.Name == "@proxy" {

// start container with squid proxy
err := util.ExecuteCommand("podman run --name squid -d -p 3128:3128 quay.io/crcont/squid")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = util.ExecuteCommand("crc config set http-proxy http://192.168.130.1:3128")
err = util.ExecuteCommand("crc config set http-proxy http://host.crc.testing:3128")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

err = util.ExecuteCommand("crc config set https-proxy http://192.168.130.1:3128")
err = util.ExecuteCommand("crc config set https-proxy http://host.crc.testing:3128")
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -239,6 +238,20 @@ func InitializeScenario(s *godog.ScenarioContext) {
os.Exit(1)
}

err = util.ExecuteCommand("crc config set host-network-access true")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

}

if tag.Name == "@system_network" {
err = util.ExecuteCommand("crc config set network-mode system")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}

Expand Down Expand Up @@ -358,6 +371,14 @@ func InitializeScenario(s *godog.ScenarioContext) {
}
}

if tag.Name == "@system_network" {
err := util.ExecuteCommand("crc config unset network-mode")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}

}

return ctx, nil
Expand Down Expand Up @@ -961,9 +982,6 @@ func PodmanCommandIsAvailable() error {
csshk = filepath.Join(userHomeDir, ".crc/machines/crc/id_ed25519")
dh = "npipe:////./pipe/crc-podman"
}
if runtime.GOOS == "linux" {
ch = "ssh://[email protected]:22/run/user/1000/podman/podman.sock"
}

os.Setenv("PATH", path)
os.Setenv("CONTAINER_SSHKEY", csshk)
Expand Down
6 changes: 1 addition & 5 deletions test/extended/util/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"

"github.com/elazarl/goproxy"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -65,10 +64,7 @@ func RunProxy() {

log.SetOutput(f)

ipaddr := "127.0.0.1" // user mode is default on windows and darwin
if runtime.GOOS == "linux" { // system mode is default on linux
ipaddr = "192.168.130.1"
}
ipaddr := "127.0.0.1" // user mode is default on windows, darwin and linux

addr := fmt.Sprintf("%s:8888", ipaddr)
proxy.Verbose = true
Expand Down
3 changes: 0 additions & 3 deletions test/integration/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ var _ = Describe("podman-remote", Serial, Ordered, Label("microshift-preset"), f
csshk = filepath.Join(userHomeDir, ".crc/machines/crc/id_ed25519")
dh = "npipe:////./pipe/crc-podman"
}
if runtime.GOOS == "linux" {
ch = "ssh://[email protected]:22/run/user/1000/podman/podman.sock"
}

os.Setenv("PATH", path)
os.Setenv("CONTAINER_SSHKEY", csshk)
Expand Down
10 changes: 1 addition & 9 deletions test/integration/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package test_test
import (
"os"
"os/exec"
"runtime"

crc "github.com/crc-org/crc/v2/test/extended/crc/cmd"
"github.com/crc-org/crc/v2/test/extended/util"
Expand Down Expand Up @@ -41,21 +40,14 @@ var _ = Describe("", Serial, Ordered, Label("openshift-preset", "goproxy"), func
httpsProxy := "http://127.0.0.1:8888"
noProxy := ".testing"

if runtime.GOOS == "linux" {
httpProxy = "http://192.168.130.1:8888"
httpsProxy = "http://192.168.130.1:8888"
}

// Start goproxy

It("configure CRC", func() {
Expect(RunCRCExpectSuccess("config", "set", "http-proxy", httpProxy)).To(ContainSubstring("Successfully configured http-proxy"))
Expect(RunCRCExpectSuccess("config", "set", "https-proxy", httpsProxy)).To(ContainSubstring("Successfully configured https-proxy"))
Expect(RunCRCExpectSuccess("config", "set", "no-proxy", noProxy)).To(ContainSubstring("Successfully configured no-proxy"))
Expect(RunCRCExpectSuccess("config", "set", "proxy-ca-file", util.CACertTempLocation)).To(ContainSubstring("Successfully configured proxy-ca-file"))
if runtime.GOOS != "linux" {
Expect(RunCRCExpectSuccess("config", "set", "host-network-access", "true")).To(ContainSubstring("Changes to configuration property 'host-network-access' are only applied during 'crc setup'"))
}
Expect(RunCRCExpectSuccess("config", "set", "host-network-access", "true")).To(ContainSubstring("Changes to configuration property 'host-network-access' are only applied during 'crc setup'"))
})

It("setup CRC", func() {
Expand Down
Loading