Skip to content

Commit

Permalink
feat(manager/helmfile): allow forward slashes in OCI chart names
Browse files Browse the repository at this point in the history
Issue was described in [discussion][1].

The helmfile manager now properly handles OCI chart names that contain forward slashes.
Previously, the validation would reject chart names with slashes even for OCI repositories.
This change modifies the isValidChartName function to use different validation rules
for OCI vs non-OCI charts.

Added test coverage to verify the new behavior works correctly.

[1]: #26207
  • Loading branch information
kuzaxak committed Dec 17, 2024
1 parent af6a80e commit 6040cd7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
30 changes: 30 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,36 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('allows OCI chart names containing forward slashes', async () => {
const content = `
repositories:
- name: oci-repo
url: ghcr.io/example/oci-repo
oci: true
releases:
- name: nested-example
version: 1.2.3
chart: oci://ghcr.io/example/nested/path/chart
`;
const fileName = 'helmfile.yaml';
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toMatchObject({

Check failure on line 383 in lib/modules/manager/helmfile/extract.spec.ts

View workflow job for this annotation

GitHub Actions / test (4/16)

modules/manager/helmfile/extract › extractPackageFile() › allows OCI chart names containing forward slashes

expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 @@ -2,10 +2,10 @@ "datasource": "helm", "deps": Array [ Object { "currentValue": "1.2.3", "datasource": "docker", - "depName": "path/chart", + "depName": "chart", "packageName": "ghcr.io/example/nested/path/chart", }, ], } at Object.<anonymous> (lib/modules/manager/helmfile/extract.spec.ts:383:22)
datasource: 'helm',
deps: [
{
currentValue: '1.2.3',
depName: 'path/chart',
datasource: 'docker',
packageName: 'ghcr.io/example/nested/path/chart',
},
],
});
});

it('parses a chart with an oci repository with ---', async () => {
const content = codeBlock`
repositories:
Expand Down
11 changes: 8 additions & 3 deletions lib/modules/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ import {
localChartHasKustomizationsYaml,
} from './utils';

const isValidChartName = (name: string | undefined): boolean =>
!!name && !regEx(/[!@#$%^&*(),.?":{}/|<>A-Z]/).test(name);
const isValidChartName = (name: string | undefined, oci: boolean): boolean {

Check failure on line 21 in lib/modules/manager/helmfile/extract.ts

View workflow job for this annotation

GitHub Actions / lint-other

'=>' expected.

Check failure on line 21 in lib/modules/manager/helmfile/extract.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Parsing error: '=>' expected.

Check failure on line 21 in lib/modules/manager/helmfile/extract.ts

View workflow job for this annotation

GitHub Actions / build

'=>' expected.

Check failure on line 21 in lib/modules/manager/helmfile/extract.ts

View workflow job for this annotation

GitHub Actions / build-docs

'=>' expected.
if (oci) {
return !!name && !regEx(/[!@#$%^&*(),.?":{}|<>A-Z]/).test(name);
} else {
return !!name && !regEx(/[!@#$%^&*(),.?":{}/|<>A-Z]/).test(name);
}
}

function isLocalPath(possiblePath: string): boolean {
return ['./', '../', '/'].some((localPrefix) =>
Expand Down Expand Up @@ -118,7 +123,7 @@ export async function extractPackageFile(

// By definition on helm the chart name should be lowercase letter + number + -
// However helmfile support templating of that field
if (!isValidChartName(res.depName)) {
if (!isValidChartName(res.depName, isOCIRegistry(dep.chart) || registryData[repoName]?.oci)) {
res.skipReason = 'unsupported-chart-type';
}

Expand Down

0 comments on commit 6040cd7

Please sign in to comment.