Merge branch 'refactor/manager-flux-resource-lookups' into feat/flux-chartref

This commit is contained in:
Sebastian Sams 2025-01-08 07:58:50 +00:00
commit 408de54b92
2 changed files with 28 additions and 23 deletions

View file

@ -1,4 +1,6 @@
import { regEx } from '../../../util/regex'; import { regEx } from '../../../util/regex';
import type { HelmRepository } from './schema';
import type { FluxManifest } from './types';
export const systemManifestFileNameRegex = '(?:^|/)gotk-components\\.ya?ml$'; export const systemManifestFileNameRegex = '(?:^|/)gotk-components\\.ya?ml$';
@ -8,3 +10,19 @@ export const systemManifestHeaderRegex =
export function isSystemManifest(file: string): boolean { export function isSystemManifest(file: string): boolean {
return regEx(systemManifestFileNameRegex).test(file); return regEx(systemManifestFileNameRegex).test(file);
} }
export function collectHelmRepos(manifests: FluxManifest[]): HelmRepository[] {
const helmRepositories: HelmRepository[] = [];
for (const manifest of manifests) {
if (manifest.kind === 'resource') {
for (const resource of manifest.resources) {
if (resource.kind === 'HelmRepository') {
helmRepositories.push(resource);
}
}
}
}
return helmRepositories;
}

View file

@ -21,7 +21,11 @@ import type {
PackageFile, PackageFile,
PackageFileContent, PackageFileContent,
} from '../types'; } from '../types';
import { isSystemManifest, systemManifestHeaderRegex } from './common'; import {
collectHelmRepos,
isSystemManifest,
systemManifestHeaderRegex,
} from './common';
import { FluxResource, type HelmRepository } from './schema'; import { FluxResource, type HelmRepository } from './schema';
import type { import type {
FluxManagerData, FluxManagerData,
@ -171,15 +175,14 @@ function resolveResourceManifest(
} }
const chartSpec = resource.spec.chart.spec; const chartSpec = resource.spec.chart.spec;
const chartName = chartSpec.chart; const depName = chartSpec.chart;
const dep: PackageDependency = { const dep: PackageDependency = {
depName: chartName, depName,
currentValue: resource.spec.chart.spec.version, currentValue: resource.spec.chart.spec.version,
datasource: HelmDatasource.id, datasource: HelmDatasource.id,
}; };
if (chartName.startsWith('./')) { if (depName.startsWith('./')) {
dep.skipReason = 'local-chart'; dep.skipReason = 'local-chart';
delete dep.datasource; delete dep.datasource;
deps.push(dep); deps.push(dep);
@ -301,14 +304,7 @@ export function extractPackageFile(
if (!manifest) { if (!manifest) {
return null; return null;
} }
const helmRepositories: HelmRepository[] = []; const helmRepositories = collectHelmRepos([manifest]);
if (manifest.kind === 'resource') {
for (const resource of manifest.resources) {
if (resource.kind === 'HelmRepository') {
helmRepositories.push(resource);
}
}
}
let deps: PackageDependency[] | null = null; let deps: PackageDependency[] | null = null;
switch (manifest.kind) { switch (manifest.kind) {
case 'system': case 'system':
@ -342,16 +338,7 @@ export async function extractAllPackageFiles(
} }
} }
const helmRepositories: HelmRepository[] = []; const helmRepositories = collectHelmRepos(manifests);
for (const manifest of manifests) {
if (manifest.kind === 'resource') {
for (const resource of manifest.resources) {
if (resource.kind === 'HelmRepository') {
helmRepositories.push(resource);
}
}
}
}
for (const manifest of manifests) { for (const manifest of manifests) {
let deps: PackageDependency[] | null = null; let deps: PackageDependency[] | null = null;