mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 10:09:50 +00:00
be13c9f5f7
* feat(manager): share OCI Helm chart resolution across managers Add getOciChartDep() to helmv3/oci.ts and use it in argocd, fleet, flux, helmfile, helmsman, helmv3, kustomize, sveltos, terraform and vendir. - set pinDigests: false for OCI charts in all of them - apply registryAliases to OCI charts in argocd, helmfile and helmsman - keep the registry port in terraform helm_release repositories - skip fleet OCI charts without a version instead of using 'undefined' * docs(manager/helmv3): correct the OCI chart pinDigests rationale * refactor(manager/helmfile): drop redundant OCI repository url guard The repository schema already requires url to be a string, so the falsy branch could not be reached by parsed input and left the patch partially covered.
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { isNonEmptyString, isTruthy } from '@sindresorhus/is';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import { parseSingleYaml } from '../../../util/yaml.ts';
|
|
import { HelmDatasource } from '../../datasource/helm/index.ts';
|
|
import { getOciChartDep, isOCIRegistry } from '../helmv3/oci.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
PackageDependency,
|
|
PackageFileContent,
|
|
} from '../types.ts';
|
|
import type { HelmsmanDocument } from './types.ts';
|
|
|
|
const chartRegex = regEx('^(?<registryRef>[^/]*)/(?<packageName>[^/]*)$');
|
|
|
|
function createDep(
|
|
key: string,
|
|
doc: HelmsmanDocument,
|
|
registryAliases: Record<string, string> | undefined,
|
|
): PackageDependency | null {
|
|
const dep: PackageDependency = {
|
|
depName: key,
|
|
datasource: HelmDatasource.id,
|
|
};
|
|
const anApp = doc.apps[key];
|
|
if (!anApp) {
|
|
return null;
|
|
}
|
|
|
|
if (!anApp.version) {
|
|
dep.skipReason = 'unspecified-version';
|
|
return dep;
|
|
}
|
|
dep.currentValue = anApp.version;
|
|
|
|
// in case of OCI repository, we need a PackageDependency with a DockerDatasource and a packageName
|
|
if (anApp.chart && isOCIRegistry(anApp.chart)) {
|
|
return {
|
|
...dep,
|
|
...getOciChartDep(anApp.chart, undefined, registryAliases),
|
|
};
|
|
}
|
|
|
|
const regexResult = anApp.chart ? chartRegex.exec(anApp.chart) : null;
|
|
if (!regexResult?.groups) {
|
|
dep.skipReason = 'invalid-url';
|
|
return dep;
|
|
}
|
|
|
|
if (!isNonEmptyString(regexResult.groups.packageName)) {
|
|
dep.skipReason = 'invalid-name';
|
|
return dep;
|
|
}
|
|
dep.packageName = regexResult.groups.packageName;
|
|
|
|
const registryUrl = doc.helmRepos[regexResult.groups.registryRef];
|
|
if (!isNonEmptyString(registryUrl)) {
|
|
dep.skipReason = 'no-repository';
|
|
return dep;
|
|
}
|
|
dep.registryUrls = [registryUrl];
|
|
|
|
return dep;
|
|
}
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
config: ExtractConfig,
|
|
): PackageFileContent | null {
|
|
try {
|
|
// TODO: use schema (#9610)
|
|
const doc = parseSingleYaml<HelmsmanDocument>(content);
|
|
if (!doc.apps) {
|
|
logger.debug({ packageFile }, `Missing apps keys`);
|
|
return null;
|
|
}
|
|
|
|
const deps = Object.keys(doc.apps)
|
|
.map((key) => createDep(key, doc, config.registryAliases))
|
|
.filter(isTruthy); // filter null values
|
|
|
|
if (deps.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return { deps };
|
|
} catch (err) /* istanbul ignore next */ {
|
|
if (err.stack?.startsWith('YAMLException:')) {
|
|
logger.debug({ err, packageFile }, 'YAML exception extracting');
|
|
} else {
|
|
logger.debug({ err, packageFile }, 'Error extracting');
|
|
}
|
|
return null;
|
|
}
|
|
}
|