Skip to content

Commit 0343855

Browse files
authored
Merge pull request #3338 from mook-as/1.6/ventura-hang
Cherry-pick Ventura fixes to 1.6 branch
2 parents b2d8bdd + eb1d323 commit 0343855

File tree

1 file changed

+14
-40
lines changed

1 file changed

+14
-40
lines changed

src/backend/lima.ts

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ export default class LimaBackend extends events.EventEmitter implements VMBacken
546546
memory: (this.cfg?.memoryInGB || 4) * 1024 * 1024 * 1024,
547547
mounts: [
548548
{ location: path.join(paths.cache, 'k3s'), writable: false },
549+
{ location: paths.logs, writable: true },
549550
{ location: '~', writable: true },
550551
{ location: '/tmp/rancher-desktop', writable: true },
551552
],
@@ -1593,6 +1594,10 @@ export default class LimaBackend extends events.EventEmitter implements VMBacken
15931594
return;
15941595
}
15951596

1597+
if (kubernetesVersion) {
1598+
await this.kubeBackend.deleteIncompatibleData(kubernetesVersion);
1599+
}
1600+
15961601
await this.progressTracker.action('Configuring containerd', 50, this.configureContainerd());
15971602
if (config.containerEngine === ContainerEngine.CONTAINERD) {
15981603
await this.startService('containerd');
@@ -2032,7 +2037,6 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
20322037
// Run rc-update as we have dynamic dependencies.
20332038
await this.vm.execCommand({ root: true }, '/sbin/rc-update', '--update');
20342039
await this.vm.execCommand({ root: true }, '/sbin/rc-service', '--ifnotstarted', 'k3s', 'start');
2035-
await this.followLogs();
20362040
});
20372041

20382042
await this.progressTracker.action(
@@ -2146,28 +2150,6 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
21462150
return k3sEndpoint;
21472151
}
21482152

2149-
protected async followLogs() {
2150-
try {
2151-
this.logProcess?.kill('SIGTERM');
2152-
} catch (ex) { }
2153-
this.logProcess = this.vm.spawn(
2154-
{ logStream: await Logging.k3s.fdStream },
2155-
'/usr/bin/tail', '-n+1', '-F', '/var/log/k3s.log');
2156-
this.logProcess.on('exit', (status, signal) => {
2157-
this.logProcess = null;
2158-
if (![Action.STARTING, Action.NONE].includes(this.vm.currentAction)) {
2159-
// Allow the log process to exit if we're stopping
2160-
return;
2161-
}
2162-
if (![State.STARTING, State.STARTED].includes(this.vm.state)) {
2163-
// Allow the log process to exit if we're not active.
2164-
return;
2165-
}
2166-
console.log(`Log process exited with ${ status }/${ signal }, restarting...`);
2167-
setTimeout(this.followLogs.bind(this), 1_000);
2168-
});
2169-
}
2170-
21712153
async stop() {
21722154
if (this.cfg?.enabled) {
21732155
try {
@@ -2208,9 +2190,6 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
22082190

22092191
protected client: KubeClient | null = null;
22102192

2211-
/** Process for tailing logs */
2212-
protected logProcess: childProcess.ChildProcess | null = null;
2213-
22142193
protected get progressTracker() {
22152194
return this.vm.progressTracker;
22162195
}
@@ -2264,21 +2243,15 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
22642243
* @param version The version to install.
22652244
*/
22662245
protected async installK3s(version: semver.SemVer) {
2267-
const workdir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'rd-k3s-install-'));
2246+
const k3s = this.arch === 'aarch64' ? 'k3s-arm64' : 'k3s';
22682247

2269-
try {
2270-
const k3s = this.arch === 'aarch64' ? 'k3s-arm64' : 'k3s';
2271-
2272-
await this.vm.execCommand('mkdir', '-p', 'bin');
2273-
await this.vm.writeFile('bin/install-k3s', INSTALL_K3S_SCRIPT, 'a+x');
2274-
await fs.promises.chmod(path.join(paths.cache, 'k3s', version.raw, k3s), 0o755);
2275-
await this.vm.execCommand({ root: true }, 'bin/install-k3s', version.raw, path.join(paths.cache, 'k3s'));
2276-
const profilePath = path.join(paths.resources, 'scripts', 'profile');
2248+
await this.vm.execCommand('mkdir', '-p', 'bin');
2249+
await this.vm.writeFile('bin/install-k3s', INSTALL_K3S_SCRIPT, 'a+x');
2250+
await fs.promises.chmod(path.join(paths.cache, 'k3s', version.raw, k3s), 0o755);
2251+
await this.vm.execCommand({ root: true }, 'bin/install-k3s', version.raw, path.join(paths.cache, 'k3s'));
2252+
const profilePath = path.join(paths.resources, 'scripts', 'profile');
22772253

2278-
await this.vm.lima('copy', profilePath, `${ MACHINE_NAME }:~/.profile`);
2279-
} finally {
2280-
await fs.promises.rm(workdir, { recursive: true });
2281-
}
2254+
await this.vm.lima('copy', profilePath, `${ MACHINE_NAME }:~/.profile`);
22822255
}
22832256

22842257
/**
@@ -2289,6 +2262,7 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
22892262
PORT: this.desiredPort.toString(),
22902263
ENGINE: cfg.containerEngine ?? ContainerEngine.NONE,
22912264
ADDITIONAL_ARGS: '',
2265+
LOG_DIR: paths.logs,
22922266
};
22932267

22942268
if (allowSudo && os.platform() === 'darwin') {
@@ -2318,7 +2292,7 @@ class LimaKubernetesBackend extends events.EventEmitter implements K8s.Kubernete
23182292
* Delete k3s data that may cause issues if we were to move to the given
23192293
* version.
23202294
*/
2321-
protected async deleteIncompatibleData(desiredVersion: semver.SemVer) {
2295+
async deleteIncompatibleData(desiredVersion: semver.SemVer) {
23222296
const existingVersion = await K3sHelper.getInstalledK3sVersion(this.vm);
23232297

23242298
if (!existingVersion) {

0 commit comments

Comments
 (0)