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

Fixes the startup arguments for guestAgent #7372

Merged
merged 1 commit into from
Aug 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ command_args="
${GUESTAGENT_ADMIN_INSTALL:+-adminInstall=${GUESTAGENT_ADMIN_INSTALL}}
${GUESTAGENT_KUBERNETES:+-kubernetes=${GUESTAGENT_KUBERNETES}}
${GUESTAGENT_IPTABLES:+-iptables=${GUESTAGENT_IPTABLES}}
${GUESTAGENT_PRIVILEGED_SERVICE:+-privilegedService=${GUESTAGENT_PRIVILEGED_SERVICE}}
${GUESTAGENT_DOCKER:+-docker=${GUESTAGENT_DOCKER}}
${GUESTAGENT_CONTAINERD:+-containerd=${GUESTAGENT_CONTAINERD}}
${GUESTAGENT_K8S_SVC_ADDR:+-k8sServiceListenerAddr=${GUESTAGENT_K8S_SVC_ADDR}}
Expand Down
53 changes: 11 additions & 42 deletions pkg/rancher-desktop/backend/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
return this.#isAdminInstall;
}

/** Indicates whether privileged service is enabled in the current installation. */
protected privilegedServiceEnabled = false;

/**
* Reference to the _init_ process in WSL. All other processes should be
* children of this one. Note that this is busybox init, running in a custom
Expand Down Expand Up @@ -504,24 +501,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
});
}

/**
* start/stop Privileged Service based on a given command [start|stop],
* also, it returns a boolean to indicate if privileged services
* is enabled.
*/
protected async invokePrivilegedService(cmd: 'start' | 'stop'): Promise<boolean> {
const privilegedServicePath = path.join(paths.resources, 'win32', 'internal', 'privileged-service.exe');
let privilegedServiceEnabled = true;

try {
await childProcess.spawnFile(privilegedServicePath, [cmd]);
} catch (error) {
privilegedServiceEnabled = false;
}

return privilegedServiceEnabled;
}

/**
* Return the Linux path to the host-resolver executable.
*/
Expand Down Expand Up @@ -867,15 +846,14 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
const isAdminInstall = await this.getIsAdminInstall();

const guestAgentConfig: Record<string, string> = {
LOG_DIR: await this.wslify(paths.logs),
GUESTAGENT_ADMIN_INSTALL: isAdminInstall ? 'true' : 'false',
GUESTAGENT_KUBERNETES: enableKubernetes ? 'true' : 'false',
GUESTAGENT_IPTABLES: iptables.toString(), // only enable IPTABLES for older K8s
GUESTAGENT_PRIVILEGED_SERVICE: this.privilegedServiceEnabled ? 'true' : 'false',
mook-as marked this conversation as resolved.
Show resolved Hide resolved
GUESTAGENT_CONTAINERD: cfg?.containerEngine.name === ContainerEngine.CONTAINERD ? 'true' : 'false',
GUESTAGENT_DOCKER: cfg?.containerEngine.name === ContainerEngine.MOBY ? 'true' : 'false',
GUESTAGENT_DEBUG: this.debug ? 'true' : 'false',
GUESTAGENT_K8S_SVC_ADDR: isAdminInstall && !cfg?.kubernetes.ingress.localhostOnly ? '0.0.0.0' : '127.0.0.1',
LOG_DIR: await this.wslify(paths.logs),
GUESTAGENT_ADMIN_INSTALL: isAdminInstall ? 'true' : 'false',
GUESTAGENT_KUBERNETES: enableKubernetes ? 'true' : 'false',
GUESTAGENT_IPTABLES: iptables.toString(), // only enable IPTABLES for older K8s
GUESTAGENT_CONTAINERD: cfg?.containerEngine.name === ContainerEngine.CONTAINERD ? 'true' : 'false',
GUESTAGENT_DOCKER: cfg?.containerEngine.name === ContainerEngine.MOBY ? 'true' : 'false',
GUESTAGENT_DEBUG: this.debug ? 'true' : 'false',
GUESTAGENT_K8S_SVC_ADDR: isAdminInstall && !cfg?.kubernetes.ingress.localhostOnly ? '0.0.0.0' : '127.0.0.1',
};

await Promise.all([
Expand Down Expand Up @@ -1287,10 +1265,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
await this.writeResolvConf();
})()];

const rdNetworking = !!config?.experimental.virtualMachine.networkingTunnel;

this.privilegedServiceEnabled = rdNetworking ? false : await this.invokePrivilegedService('start');

if (config.kubernetes.enabled) {
prepActions.push((async() => {
[kubernetesVersion] = await this.kubeBackend.download(config);
Expand Down Expand Up @@ -1446,10 +1420,8 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
// just ignore any errors; all the script does is installing spin plugins and templates
}
}
if (rdNetworking) {
// Do not await on this, as we don't want to wait until the proxy exits.
this.runWslProxy().catch(console.error);
}
// Do not await on this, as we don't want to wait until the proxy exits.
this.runWslProxy().catch(console.error);
}),
this.progressTracker.action('Installing CA certificates', 100, this.installCACerts()),
this.progressTracker.action('Installing helpers', 50, this.installWSLHelpers()),
Expand All @@ -1476,10 +1448,8 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
// Make sure the apiserver can be accessed from WSL through the internal gateway
k3sConf.ADDITIONAL_ARGS += ' --tls-san gateway.rancher-desktop.internal';

if (rdNetworking) {
// Add the `veth-rd1` IP address from inside the namespace
k3sConf.ADDITIONAL_ARGS += ' --tls-san 192.168.1.2';
}
k3sConf.ADDITIONAL_ARGS += ' --tls-san 192.168.1.2';

if (!config.kubernetes.options.flannel) {
console.log(`Disabling flannel and network policy`);
Expand Down Expand Up @@ -1688,7 +1658,6 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend
}
if (!this.cfg?.experimental.virtualMachine.networkingTunnel) {
await this.resolverHostProcess.stop();
await this.invokePrivilegedService('stop');
}
const initProcess = this.process;

Expand Down
Loading