Skip to content

Commit

Permalink
feat(helmfile): oci support (#15432)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycamier committed May 5, 2022
1 parent 114e6da commit e97974d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
40 changes: 40 additions & 0 deletions lib/modules/manager/helmfile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,46 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('parses a chart with an oci repository and non-oci one', () => {
const content = `
repositories:
- name: oci-repo
url: ghcr.io/example/oci-repo
oci: true
- name: jenkins
url: https://charts.jenkins.io
releases:
- name: example
version: 0.1.0
chart: oci-repo/example
- name: jenkins
chart: jenkins/jenkins
version: 3.3.0
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
aliases: {
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',
},
{
currentValue: '3.3.0',
depName: 'jenkins',
},
],
});
});

it('parses and replaces templating strings', () => {
const filename = 'helmfile.yaml';
const result = extractPackageFile(
Expand Down
10 changes: 10 additions & 0 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 { loadAll } from 'js-yaml';
import { logger } from '../../../logger';
import { regEx } from '../../../util/regex';
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import type { Doc } from './types';
Expand Down Expand Up @@ -86,6 +87,15 @@ export function extractPackageFile(
.filter(is.string),
};

// 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 (repository?.oci) {
res.datasource = DockerDatasource.id;
res.packageName = aliases[repoName] + '/' + depName;
}

// By definition on helm the chart name should be lowercase letter + number + -
// However helmfile support templating of that field
if (!isValidChartName(res.depName)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/helmfile/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm';
export { extractPackageFile } from './extract';

Expand All @@ -9,4 +10,4 @@ export const defaultConfig = {
fileMatch: ['(^|/)helmfile.yaml$'],
};

export const supportedDatasources = [HelmDatasource.id];
export const supportedDatasources = [HelmDatasource.id, DockerDatasource.id];
23 changes: 14 additions & 9 deletions lib/modules/manager/helmfile/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
interface Release {
name: string;
chart: string;
version: string;
}

interface Repository {
name: string;
url: string;
oci?: boolean;
}

export interface Doc {
releases?: {
name: string;
chart: string;
version: string;
}[];
repositories?: {
name: string;
url: string;
}[];
releases?: Release[];
repositories?: Repository[];
}

0 comments on commit e97974d

Please sign in to comment.