|
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
| 3 | + |
| 4 | +import yaml from 'yaml'; |
| 5 | + |
| 6 | +import { DiagnosticsCategory, DiagnosticsChecker, DiagnosticsCheckerSingleResult } from './types'; |
| 7 | + |
| 8 | +import paths from '@pkg/utils/paths'; |
| 9 | + |
| 10 | +/** |
| 11 | + * Check for things in the user's Lima overrides file. We never create the file |
| 12 | + * ourselves, but the user may manually create it to adjust how Lima runs; it |
| 13 | + * may end up conflicting with what we attempt to do. |
| 14 | + */ |
| 15 | +const CheckLimaOverrides: DiagnosticsChecker = { |
| 16 | + id: 'LIMA_OVERRIDES', |
| 17 | + category: DiagnosticsCategory.ContainerEngine, |
| 18 | + applicable() { |
| 19 | + return Promise.resolve(process.platform !== 'win32'); |
| 20 | + }, |
| 21 | + async check() { |
| 22 | + const overridePath = path.join(paths.lima, '_config', 'override.yaml'); |
| 23 | + const checkers = { |
| 24 | + /** |
| 25 | + * Check if the user has an override for the lima disk size. We have built-in |
| 26 | + * support for the feature now, and overrides would cause our settings to be |
| 27 | + * ignored. |
| 28 | + */ |
| 29 | + DISK_SIZE: (override) => { |
| 30 | + if ('disk' in override) { |
| 31 | + return { |
| 32 | + description: `Disk overrides are set in Lima override file \`${ overridePath }\``, |
| 33 | + passed: false, |
| 34 | + fixes: [{ |
| 35 | + description: `Remove Lima override file \`${ overridePath }\``, |
| 36 | + }], |
| 37 | + }; |
| 38 | + } |
| 39 | + return { |
| 40 | + description: `Disk size override not specified in Lima override file \`${ overridePath }\``, |
| 41 | + passed: true, |
| 42 | + fixes: [], |
| 43 | + }; |
| 44 | + }, |
| 45 | + } satisfies Record<string, (override: any) => Omit<DiagnosticsCheckerSingleResult, 'id'>>; |
| 46 | + const override = await (async function() { |
| 47 | + try { |
| 48 | + return yaml.parse(await fs.promises.readFile(overridePath, 'utf-8')); |
| 49 | + } catch { |
| 50 | + return undefined; |
| 51 | + } |
| 52 | + })(); |
| 53 | + |
| 54 | + if (!override || typeof override !== 'object') { |
| 55 | + // Override file does not exist, or is not valid YAML |
| 56 | + return Object.keys(checkers).map(id => ({ |
| 57 | + id, |
| 58 | + description: `Override file \`${ overridePath }\` not loaded`, |
| 59 | + passed: true, |
| 60 | + fixes: [], |
| 61 | + })); |
| 62 | + } |
| 63 | + |
| 64 | + return Object.entries(checkers).map(([id, checker]) => ({ |
| 65 | + id, |
| 66 | + ...checker(override), |
| 67 | + })); |
| 68 | + }, |
| 69 | +}; |
| 70 | + |
| 71 | +export default CheckLimaOverrides; |
0 commit comments