Skip to content

Commit

Permalink
fix(helmfile): support case with oci repository in different document (
Browse files Browse the repository at this point in the history
…renovatebot#30215)

Co-authored-by: Michael Kriese <[email protected]>
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
3 people authored Jul 21, 2024
1 parent b6b85eb commit 0e330ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
31 changes: 31 additions & 0 deletions lib/modules/manager/helmfile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,37 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('parses a chart with an oci repository with ---', async () => {
const content = codeBlock`
repositories:
- name: oci-repo
url: ghcr.io/example/oci-repo
oci: true
---
releases:
- name: example
version: 0.1.0
chart: oci-repo/example
`;
const fileName = 'helmfile.yaml';
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toMatchObject({
datasource: 'helm',
deps: [
{
currentValue: '0.1.0',
depName: 'example',
datasource: 'docker',
packageName: 'ghcr.io/example/oci-repo/example',
},
],
});
});

it('parses and replaces templating strings', async () => {
const filename = 'helmfile.yaml';
fs.localPathExists.mockReturnValue(Promise.resolve(true));
Expand Down
28 changes: 15 additions & 13 deletions lib/modules/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { coerceArray } from '../../../util/array';
import { regEx } from '../../../util/regex';
import { joinUrlParts } from '../../../util/url';
import { parseYaml } from '../../../util/yaml';
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm';
Expand All @@ -11,7 +12,7 @@ import type {
PackageDependency,
PackageFileContent,
} from '../types';
import type { Doc } from './schema';
import type { Doc, HelmRepository } from './schema';
import { Doc as documentSchema } from './schema';
import {
kustomizationsKeysUsed,
Expand All @@ -34,7 +35,7 @@ export async function extractPackageFile(
): Promise<PackageFileContent | null> {
const deps: PackageDependency[] = [];
let docs: Doc[];
let registryAliases: Record<string, string> = {};
let registryData: Record<string, HelmRepository> = {};
// Record kustomization usage for all deps, since updating artifacts is run on the helmfile.yaml as a whole.
let needKustomize = false;
try {
Expand All @@ -51,15 +52,16 @@ export async function extractPackageFile(
);
return null;
}

for (const doc of docs) {
// Always check for repositories in the current document and override the existing ones if any (as YAML does)
if (doc.repositories) {
registryAliases = {};
registryData = {};
for (let i = 0; i < doc.repositories.length; i += 1) {
registryAliases[doc.repositories[i].name] = doc.repositories[i].url;
registryData[doc.repositories[i].name] = doc.repositories[i];
}
logger.debug(
{ registryAliases, packageFile },
{ registryAliases: registryData, packageFile },
`repositories discovered.`,
);
}
Expand Down Expand Up @@ -106,23 +108,23 @@ export async function extractPackageFile(
const res: PackageDependency = {
depName,
currentValue: dep.version,
registryUrls: [registryAliases[repoName]]
registryUrls: [registryData[repoName]?.url]
.concat([config.registryAliases?.[repoName]] as string[])
.filter(is.string),
};
if (kustomizationsKeysUsed(dep)) {
needKustomize = true;
}
// in case of OCI repository, we need a PackageDependency with a DockerDatasource and a packageName
const repository = doc.repositories?.find(
(repo) => repo.name === repoName,
);

if (isOCIRegistry(dep.chart)) {
res.datasource = DockerDatasource.id;
res.packageName = repoName + '/' + depName;
} else if (repository?.oci) {
res.packageName = joinUrlParts(repoName, depName);
} else if (registryData[repoName]?.oci) {
res.datasource = DockerDatasource.id;
res.packageName = registryAliases[repoName] + '/' + depName;
const alias = registryData[repoName]?.url;
if (alias) {
res.packageName = joinUrlParts(alias, depName);
}
}

// By definition on helm the chart name should be lowercase letter + number + -
Expand Down

0 comments on commit 0e330ea

Please sign in to comment.