mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
2e1a079c7f
Some charts define the image reference and its version as sibling keys
of the same object, with the parent key unrelated to the image name:
cli:
image: ghcr.io/fluxcd/flux-cli
tag: v2.7.2
The walker previously extracted the `image` string via
matchesHelmValuesInlineImage but, without an embedded version, produced
a version-less dependency that could never be updated; the sibling
`tag`/`version` key was invisible because
matchesHelmValuesDockerHeuristic requires the keys to live inside an
object whose parent key ends in `image`.
When an inline reference carries no version and no digest, adopt a
sibling `tag` (preferred) or `version` string as the version, reusing
the same update mechanics as the repository/tag object form
(replaceString = version, docker versioning, `{{newValue}}` template).
Inline references with an embedded version or digest keep current
behavior, and repository/tag objects never reach the inline branch.
Discussion #46265 documents the layout with a real-world example.
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
123 lines
3.8 KiB
TypeScript
123 lines
3.8 KiB
TypeScript
import { isObject } from '@sindresorhus/is';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { parseYaml } from '../../../util/yaml.ts';
|
|
import { id as dockerVersioning } from '../../versioning/docker/index.ts';
|
|
import { getDep } from '../dockerfile/extract.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
PackageDependency,
|
|
PackageFileContent,
|
|
} from '../types.ts';
|
|
import type { HelmDockerImageDependency } from './types.ts';
|
|
import {
|
|
getHelmValuesSiblingVersion,
|
|
matchesHelmValuesDockerHeuristic,
|
|
matchesHelmValuesInlineImage,
|
|
} from './util.ts';
|
|
|
|
function getHelmDep(
|
|
registry: string,
|
|
repository: string,
|
|
tag: string,
|
|
registryAliases: Record<string, string> | undefined,
|
|
): PackageDependency {
|
|
const dep = getDep(`${registry}${repository}:${tag}`, false, registryAliases);
|
|
dep.replaceString = tag;
|
|
dep.versioning = dockerVersioning;
|
|
dep.autoReplaceStringTemplate =
|
|
'{{newValue}}{{#if newDigest}}@{{newDigest}}{{/if}}';
|
|
return dep;
|
|
}
|
|
|
|
/**
|
|
* Recursively find all supported dependencies in the yaml object.
|
|
*
|
|
* @param parsedContent
|
|
*/
|
|
export function findDependencies(
|
|
parsedContent: Record<string, unknown> | HelmDockerImageDependency,
|
|
registryAliases: Record<string, string> | undefined,
|
|
): PackageDependency[] {
|
|
return findDependenciesInternal(parsedContent, [], registryAliases);
|
|
}
|
|
export function findDependenciesInternal(
|
|
parsedContent: Record<string, unknown> | HelmDockerImageDependency,
|
|
packageDependencies: PackageDependency[],
|
|
registryAliases: Record<string, string> | undefined,
|
|
): PackageDependency[] {
|
|
if (!isObject(parsedContent)) {
|
|
return packageDependencies;
|
|
}
|
|
|
|
Object.entries(parsedContent).forEach(([key, value]) => {
|
|
if (matchesHelmValuesDockerHeuristic(key, value)) {
|
|
const currentItem = value;
|
|
|
|
let registry = currentItem.registry;
|
|
registry = registry ? `${registry}/` : '';
|
|
const repository = String(currentItem.repository);
|
|
const tag = `${currentItem.tag ?? currentItem.version}`;
|
|
packageDependencies.push(
|
|
getHelmDep(registry, repository, tag, registryAliases),
|
|
);
|
|
} else if (matchesHelmValuesInlineImage(key, value)) {
|
|
const dep = getDep(value, true, registryAliases);
|
|
// An inline reference without an embedded version can be completed by a
|
|
// sibling `tag`/`version` key: `cli: { image: ..., tag: v1.0.0 }`
|
|
if (!dep.currentValue && !dep.currentDigest) {
|
|
const siblingVersion = getHelmValuesSiblingVersion(parsedContent);
|
|
if (siblingVersion) {
|
|
packageDependencies.push(
|
|
getHelmDep('', value, siblingVersion, registryAliases),
|
|
);
|
|
} else {
|
|
packageDependencies.push(dep);
|
|
}
|
|
} else {
|
|
packageDependencies.push(dep);
|
|
}
|
|
} else {
|
|
findDependenciesInternal(
|
|
value as Record<string, unknown>,
|
|
packageDependencies,
|
|
registryAliases,
|
|
);
|
|
}
|
|
});
|
|
return packageDependencies;
|
|
}
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
config: ExtractConfig,
|
|
): PackageFileContent | null {
|
|
let parsedContent: Record<string, unknown>[] | HelmDockerImageDependency[];
|
|
try {
|
|
// a parser that allows extracting line numbers would be preferable, with
|
|
// the current approach we need to match anything we find again during the update
|
|
// TODO: fix me (#9610)
|
|
parsedContent = parseYaml(content) as any;
|
|
} catch (err) {
|
|
logger.debug({ err, packageFile }, 'Failed to parse helm-values YAML');
|
|
return null;
|
|
}
|
|
try {
|
|
const deps: PackageDependency[] = [];
|
|
|
|
for (const con of parsedContent) {
|
|
deps.push(...findDependencies(con, config.registryAliases));
|
|
}
|
|
|
|
if (deps.length) {
|
|
return { deps };
|
|
}
|
|
} catch (err) /* istanbul ignore next */ {
|
|
logger.debug(
|
|
{ err, packageFile },
|
|
'Error parsing helm-values parsed content',
|
|
);
|
|
}
|
|
return null;
|
|
}
|