Skip to content

Commit

Permalink
Merge pull request #7427 from rancher-sandbox/deprecate-networking-tu…
Browse files Browse the repository at this point in the history
…nnel

Remove networking tunnel
  • Loading branch information
Nino-K authored Sep 6, 2024
2 parents b03544b + 5234e43 commit 472e0cf
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 119 deletions.
2 changes: 0 additions & 2 deletions e2e/backend.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ test.describe.serial('KubernetesBackend', () => {
expectedDefinition['application.adminAccess'] = false;
expectedDefinition['virtualMachine.numberCPUs'] = false;
expectedDefinition['virtualMachine.memoryInGB'] = false;
} else if (process.platform === 'win32') {
expectedDefinition['experimental.virtualMachine.networkingTunnel'] = false;
}

const expected: Record<string, {current: any, desired: any, severity: 'reset' | 'restart'}> = {};
Expand Down
2 changes: 0 additions & 2 deletions e2e/pages/preferences/virtualMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class VirtualMachineNav {
readonly msizeInKib: Locator;
readonly protocolVersion: Locator;
readonly securityModel: Locator;
readonly networkingTunnel: Locator;
readonly vmType: Locator;
readonly qemu: Locator;
readonly vz: Locator;
Expand All @@ -35,7 +34,6 @@ export class VirtualMachineNav {
this.msizeInKib = page.locator('[data-test="msizeInKib"]');
this.protocolVersion = page.locator('[data-test="protocolVersion"]');
this.securityModel = page.locator('[data-test="securityModel"]');
this.networkingTunnel = page.locator('[data-test="networkingTunnel"]');
this.vmType = page.locator('[data-test="vmType"]');
this.qemu = page.locator('[data-test="QEMU"]');
this.vz = page.locator('[data-test="VZ"]');
Expand Down
5 changes: 0 additions & 5 deletions pkg/rancher-desktop/assets/specs/command-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,6 @@ components:
cacheMode:
type: string
enum: [none, loose, fscache, mmap]
networkingTunnel:
type: boolean
x-rd-platforms: [win32]
x-rd-usage: tunnel networking so it originates from the host
x-rd-hidden: true # Only available by editing settings file directly.
type:
type: string
enum: [qemu, vz]
Expand Down
3 changes: 1 addition & 2 deletions pkg/rancher-desktop/backend/kube/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ export default class WSLKubernetesBackend extends events.EventEmitter implements
}
await util.promisify(timers.setTimeout)(1_000);
}
const rdNetworking = `--rd-networking=${ config?.experimental.virtualMachine.networkingTunnel }`;

await this.k3sHelper.updateKubeconfig(
async() => await this.vm.execCommand({ capture: true }, await this.vm.getWSLHelperPath(), 'k3s', 'kubeconfig', rdNetworking));
async() => await this.vm.execCommand({ capture: true }, await this.vm.getWSLHelperPath(), 'k3s', 'kubeconfig'));
});

const client = this.client = kubeClient?.() || new KubeClient();
Expand Down
10 changes: 2 additions & 8 deletions pkg/rancher-desktop/backend/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,13 +1294,7 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
}),
this.progressTracker.action('Configuring image proxy', 50, async() => {
const allowedImagesConf = '/usr/local/openresty/nginx/conf/allowed-images.conf';
let resolver;

if (this.cfg?.experimental.virtualMachine.networkingTunnel) {
resolver = `resolver ${ rdNetworkingDNS } ipv6=off;\n`;
} else {
resolver = `resolver ${ await this.ipAddress } ipv6=off;\n`;
}
const resolver = `resolver ${ rdNetworkingDNS } ipv6=off;\n`;

await this.writeFile(`/usr/local/openresty/nginx/conf/nginx.conf`, NGINX_CONF, 0o644);
await this.writeFile(`/usr/local/openresty/nginx/conf/resolver.conf`, resolver, 0o644);
Expand Down Expand Up @@ -1650,7 +1644,7 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
}

return Promise.resolve(this.kubeBackend.requiresRestartReasons(
this.cfg, cfg, { 'experimental.virtualMachine.networkingTunnel': { current: this.cfg.experimental.virtualMachine.networkingTunnel } }));
this.cfg, cfg));
}

/**
Expand Down
8 changes: 2 additions & 6 deletions pkg/rancher-desktop/config/__tests__/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ describe('settings', () => {
},
experimental: {
virtualMachine: {
networkingTunnel: true,
},
},
kubernetes: {
Expand Down Expand Up @@ -472,8 +471,7 @@ describe('settings', () => {
version: settings.CURRENT_SETTINGS_VERSION,
experimental: {
virtualMachine: {
networkingTunnel: true,
proxy: {
proxy: {
noproxy: ['1.2.3.4', '11.12.13.14', '21.22.23.24'],
},
},
Expand Down Expand Up @@ -506,8 +504,7 @@ describe('settings', () => {
version: settings.CURRENT_SETTINGS_VERSION,
experimental: {
virtualMachine: {
networkingTunnel: true,
proxy: {
proxy: {
noproxy: ['1.2.3.4', '11.12.13.14', '21.22.23.24'],
},
},
Expand Down Expand Up @@ -587,7 +584,6 @@ describe('settings', () => {
},
experimental: {
virtualMachine: {
networkingTunnel: true,
},
},
kubernetes: {},
Expand Down
4 changes: 1 addition & 3 deletions pkg/rancher-desktop/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ export const defaultSettings = {
cacheMode: CacheMode.MMAP,
},
},
/* windows only: legacy setting, always ignored */
networkingTunnel: true,
proxy: {
proxy: {
enabled: false,
address: '',
password: '',
Expand Down
1 change: 1 addition & 0 deletions pkg/rancher-desktop/config/settingsImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export const updateTable: Record<number, (settings: any, locked : boolean) => vo
},
13: (settings) => {
_.unset(settings, 'virtualMachine.hostResolver');
_.unset(settings, 'experimental.virtualMachine.networkingTunnel');
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe(SettingsValidator, () => {
['experimental', 'virtualMachine', 'mount', '9p', 'protocolVersion'],
['experimental', 'virtualMachine', 'mount', '9p', 'securityModel'],
['experimental', 'virtualMachine', 'mount', 'type'],
['experimental', 'virtualMachine', 'networkingTunnel'], // Cannot be set
['experimental', 'virtualMachine', 'type'],
['experimental', 'virtualMachine', 'useRosetta'],
['experimental', 'virtualMachine', 'proxy', 'noproxy'],
Expand Down
11 changes: 2 additions & 9 deletions pkg/rancher-desktop/main/commandServer/settingsValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,8 @@ export default class SettingsValidator {
cacheMode: this.checkLima(this.check9P(this.checkEnum(...Object.values(CacheMode)))),
},
},
// networkingTunnel only applies to Win32, but deployment profiles on macOS/Linux may still include
// the setting. Since we changed the default value, this would now throw a validation error.
// see https://github.com/rancher-sandbox/rancher-desktop/issues/6953
// The setting will be removed once the legacy Windows networking mode is disabled, so until
// then we will allow changing the setting on all platforms to avoid the profile error.
// Changing the setting will have no effect on macOS/Linux anyways.1
networkingTunnel: this.checkUnchanged,
useRosetta: this.checkPlatform('darwin', this.checkRosetta),
type: this.checkPlatform('darwin', this.checkMulti(
useRosetta: this.checkPlatform('darwin', this.checkRosetta),
type: this.checkPlatform('darwin', this.checkMulti(
this.checkEnum(...Object.values(VMType)),
this.checkVMType),
),
Expand Down
3 changes: 0 additions & 3 deletions src/go/rdctl/pkg/plist/plist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func TestJsonToPlistFormat(t *testing.T) {
"cacheMode": "mmap"
}
},
"networkingTunnel": false,
"proxy": {
"enabled": false,
"address": "",
Expand Down Expand Up @@ -277,8 +276,6 @@ func TestJsonToPlistFormat(t *testing.T) {
<string>mmap</string>
</dict>
</dict>
<key>networkingTunnel</key>
<false/>
<key>type</key>
<string>qemu</string>
<key>useRosetta</key>
Expand Down
3 changes: 1 addition & 2 deletions src/go/rdctl/pkg/reg/reg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func TestJsonToRegFormat(t *testing.T) {
"cacheMode": "mmap"
}
},
"networkingTunnel": false,
"proxy": {
"enabled": false,
"address": "",
Expand All @@ -298,6 +297,6 @@ func TestJsonToRegFormat(t *testing.T) {
`
lines, err := JsonToReg("hkcu", "defaults", jsonBody)
assert.NoError(t, err)
assert.Equal(t, 76, len(lines))
assert.Equal(t, 75, len(lines))
})
}
81 changes: 5 additions & 76 deletions src/go/wsl-helper/cmd/k3s_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ package cmd

import (
"fmt"
"net"
"net/url"
"os"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -55,10 +52,7 @@ type kubeConfig struct {

const kubeConfigExistTimeout = 10 * time.Second

var (
k3sKubeconfigViper = viper.New()
rdNetworking bool
)
var k3sKubeconfigViper = viper.New()

// k3sKubeconfigCmd represents the `k3s kubeconfig` command.
var k3sKubeconfigCmd = &cobra.Command{
Expand Down Expand Up @@ -99,80 +93,15 @@ var k3sKubeconfigCmd = &cobra.Command{
return err
}

if rdNetworking {
// vm-switch in rdNetworking binds to localhost:Port by default.
// Since k3s.yaml comes with servers preset at 127.0.0.1, there
// is nothing for us to do here, just write the config and return.
return yaml.NewEncoder(os.Stdout).Encode(config)
}
ip, err := getClusterIP()
if err != nil {
return err
}
// Fix up any clusters at 127.0.0.1, using the IP address we found.
for clusterIdx, cluster := range config.Clusters {
server, err := url.Parse(cluster.Cluster.Server)
if err != nil {
// Ignore any clusters with invalid servers
continue
}
if server.Hostname() != "127.0.0.1" {
continue
}
if server.Port() != "" {
server.Host = net.JoinHostPort(ip.String(), server.Port())
} else {
server.Host = ip.String()
}
config.Clusters[clusterIdx].Cluster.Server = server.String()
}
// Emit the result
err = yaml.NewEncoder(os.Stdout).Encode(config)
if err != nil {
return err
}

return nil
// vm-switch in rdNetworking binds to localhost:Port by default.
// Since k3s.yaml comes with servers preset at 127.0.0.1, there
// is nothing for us to do here, just write the config and return.
return yaml.NewEncoder(os.Stdout).Encode(config)
},
}

func getClusterIP() (net.IP, error) {
var ip net.IP
// Find the IP address of eth0.
iface, err := net.InterfaceByName("eth0")
if err != nil {
// Use a random interface, assuming we're testing on Windows.
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}
iface = &ifaces[0]
fmt.Fprintf(os.Stderr, "Could not find eth0, using fallback interface %s\n", iface.Name)
}
addrs, err := iface.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
// addr.String() gives "192.2.3.4/16", so we need to chop off the netmask
ip = net.ParseIP(strings.SplitN(addr.String(), "/", 2)[0])
if ip == nil {
continue
}
ip = ip.To4()
if ip != nil {
break
}
}
if ip == nil {
return nil, fmt.Errorf("could not find IPv4 address on interface %s", iface.Name)
}
return ip, nil
}

func init() {
k3sKubeconfigCmd.Flags().String("k3sconfig", "/etc/rancher/k3s/k3s.yaml", "Path to k3s kubeconfig")
k3sKubeconfigCmd.Flags().BoolVar(&rdNetworking, "rd-networking", false, "Enable the experimental Rancher Desktop Networking")
k3sKubeconfigViper.AutomaticEnv()
if err := k3sKubeconfigViper.BindPFlags(k3sKubeconfigCmd.Flags()); err != nil {
logrus.WithError(err).Fatal("Failed to set up flags")
Expand Down

0 comments on commit 472e0cf

Please sign in to comment.