From a65129f246ea901ffbb25171570640d5759f72cf Mon Sep 17 00:00:00 2001 From: domolitom <115075004+domolitom@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:12:49 +0200 Subject: [PATCH] feat(manager/helmsman): Add OCI support (#24183) --- .../helmsman/__fixtures__/validHelmsfile.yaml | 16 +++++++++++----- .../helmsman/__snapshots__/extract.spec.ts.snap | 6 ++++++ lib/modules/manager/helmsman/extract.spec.ts | 8 +++++++- lib/modules/manager/helmsman/extract.ts | 13 +++++++++++-- lib/modules/manager/helmsman/index.ts | 3 ++- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/modules/manager/helmsman/__fixtures__/validHelmsfile.yaml b/lib/modules/manager/helmsman/__fixtures__/validHelmsfile.yaml index 6bb8d4ee90..02ab9005a3 100644 --- a/lib/modules/manager/helmsman/__fixtures__/validHelmsfile.yaml +++ b/lib/modules/manager/helmsman/__fixtures__/validHelmsfile.yaml @@ -2,6 +2,7 @@ namespaces: redis-operator: strimzi: monitoring: + test-apps: helmRepos: ot-helm: "https://ot-container-kit.github.io/helm-charts/" @@ -11,14 +12,14 @@ helmRepos: prometheus-community: https://prometheus-community.github.io/helm-charts apps: -# valid apps + # valid apps kube-prometheus: enabled: true namespace: monitoring chart: prometheus-community/kube-prometheus-stack version: 19.0.3 valuesFiles: - - ./kube-prometheus/values.yaml + - ./kube-prometheus/values.yaml priority: -90 loki: enabled: true @@ -44,14 +45,19 @@ apps: namespace: strimzi chart: strimzi/strimzi-kafka-operator version: 0.25.0 + podinfo: + enabled: true + namespace: test-apps + chart: oci://ghcr.io/stefanprodan/charts/podinfo + version: 6.4.0 -# missing version + # missing version strimzi-operator-missing-version: enabled: true namespace: strimzi chart: strimzi/strimzi-kafka-operator -# malformed chart + # malformed chart loki-no-registry-ref: enabled: true namespace: monitoring @@ -68,7 +74,7 @@ apps: chart: prometheus-community/ version: 19.0.3 valuesFiles: - - ./kube-prometheus/values.yaml + - ./kube-prometheus/values.yaml priority: -90 otlp-collector-no-chart: enabled: true diff --git a/lib/modules/manager/helmsman/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/helmsman/__snapshots__/extract.spec.ts.snap index 8fe89cff08..1aa37de040 100644 --- a/lib/modules/manager/helmsman/__snapshots__/extract.spec.ts.snap +++ b/lib/modules/manager/helmsman/__snapshots__/extract.spec.ts.snap @@ -48,6 +48,12 @@ exports[`modules/manager/helmsman/extract extractPackageFile() extract deps 1`] "https://strimzi.io/charts/", ], }, + { + "currentValue": "6.4.0", + "datasource": "docker", + "depName": "podinfo", + "packageName": "ghcr.io/stefanprodan/charts/podinfo", + }, { "datasource": "helm", "depName": "strimzi-operator-missing-version", diff --git a/lib/modules/manager/helmsman/extract.spec.ts b/lib/modules/manager/helmsman/extract.spec.ts index 6350530ce5..ff8c429cb5 100644 --- a/lib/modules/manager/helmsman/extract.spec.ts +++ b/lib/modules/manager/helmsman/extract.spec.ts @@ -20,11 +20,17 @@ describe('modules/manager/helmsman/extract', () => { expect(result).toBeNull(); }); + it('returns null if apps not defined', () => { + const fileName = 'incorrect.yaml'; + const result = extractPackageFile('incorrect', fileName, {}); + expect(result).toBeNull(); + }); + it('extract deps', () => { const fileName = 'helmsman.yaml'; const result = extractPackageFile(multiDepFile, fileName, {}); expect(result).not.toBeNull(); - expect(result?.deps).toHaveLength(10); + expect(result?.deps).toHaveLength(11); expect(result?.deps.filter((value) => value.skipReason)).toHaveLength(5); expect(result).toMatchSnapshot(); }); diff --git a/lib/modules/manager/helmsman/extract.ts b/lib/modules/manager/helmsman/extract.ts index 531c49a84e..c6419ab49b 100644 --- a/lib/modules/manager/helmsman/extract.ts +++ b/lib/modules/manager/helmsman/extract.ts @@ -2,6 +2,7 @@ import is from '@sindresorhus/is'; import { load } 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, @@ -31,6 +32,14 @@ function createDep( } dep.currentValue = anApp.version; + // in case of OCI repository, we need a PackageDependency with a DockerDatasource and a packageName + const isOci = anApp.chart?.startsWith('oci://'); + if (isOci) { + dep.datasource = DockerDatasource.id; + dep.packageName = anApp.chart!.replace('oci://', ''); + return dep; + } + const regexResult = anApp.chart ? chartRegex.exec(anApp.chart) : null; if (!regexResult?.groups) { dep.skipReason = 'invalid-url'; @@ -63,8 +72,8 @@ export function extractPackageFile( const doc = load(content, { json: true, }) as HelmsmanDocument; - if (!(doc?.helmRepos && doc.apps)) { - logger.debug({ packageFile }, `Missing helmRepos and/or apps keys`); + if (!doc.apps) { + logger.debug({ packageFile }, `Missing apps keys`); return null; } diff --git a/lib/modules/manager/helmsman/index.ts b/lib/modules/manager/helmsman/index.ts index 6a6b47e823..16e49a6451 100644 --- a/lib/modules/manager/helmsman/index.ts +++ b/lib/modules/manager/helmsman/index.ts @@ -1,4 +1,5 @@ import type { Category } from '../../../constants'; +import { DockerDatasource } from '../../datasource/docker'; import { HelmDatasource } from '../../datasource/helm'; export { extractPackageFile } from './extract'; @@ -8,4 +9,4 @@ export const defaultConfig = { export const categories: Category[] = ['cd', 'helm', 'kubernetes']; -export const supportedDatasources = [HelmDatasource.id]; +export const supportedDatasources = [HelmDatasource.id, DockerDatasource.id]; -- GitLab