From e97974d55b4e5627e744ac2e12c2eca9b61d852b Mon Sep 17 00:00:00 2001 From: Jean-Yves CAMIER <jycamier@gmail.com> Date: Thu, 5 May 2022 14:15:20 +0200 Subject: [PATCH] feat(helmfile): oci support (#15432) --- lib/modules/manager/helmfile/extract.spec.ts | 40 ++++++++++++++++++++ lib/modules/manager/helmfile/extract.ts | 10 +++++ lib/modules/manager/helmfile/index.ts | 3 +- lib/modules/manager/helmfile/types.ts | 23 ++++++----- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/lib/modules/manager/helmfile/extract.spec.ts b/lib/modules/manager/helmfile/extract.spec.ts index 5564da3126..c00387ea03 100644 --- a/lib/modules/manager/helmfile/extract.spec.ts +++ b/lib/modules/manager/helmfile/extract.spec.ts @@ -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( diff --git a/lib/modules/manager/helmfile/extract.ts b/lib/modules/manager/helmfile/extract.ts index 05d5ac4653..feeff943eb 100644 --- a/lib/modules/manager/helmfile/extract.ts +++ b/lib/modules/manager/helmfile/extract.ts @@ -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'; @@ -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)) { diff --git a/lib/modules/manager/helmfile/index.ts b/lib/modules/manager/helmfile/index.ts index 915cbcf5b0..7de71e75bf 100644 --- a/lib/modules/manager/helmfile/index.ts +++ b/lib/modules/manager/helmfile/index.ts @@ -1,3 +1,4 @@ +import { DockerDatasource } from '../../datasource/docker'; import { HelmDatasource } from '../../datasource/helm'; export { extractPackageFile } from './extract'; @@ -9,4 +10,4 @@ export const defaultConfig = { fileMatch: ['(^|/)helmfile.yaml$'], }; -export const supportedDatasources = [HelmDatasource.id]; +export const supportedDatasources = [HelmDatasource.id, DockerDatasource.id]; diff --git a/lib/modules/manager/helmfile/types.ts b/lib/modules/manager/helmfile/types.ts index c84d8377f9..f2a9593e7c 100644 --- a/lib/modules/manager/helmfile/types.ts +++ b/lib/modules/manager/helmfile/types.ts @@ -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[]; } -- GitLab