feat(manager/helmsman): Add OCI support (#24183)

This commit is contained in:
domolitom 2023-09-09 00:12:49 +02:00 committed by GitHub
parent 640258f976
commit a65129f246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 9 deletions

View file

@ -2,6 +2,7 @@ namespaces:
redis-operator: redis-operator:
strimzi: strimzi:
monitoring: monitoring:
test-apps:
helmRepos: helmRepos:
ot-helm: "https://ot-container-kit.github.io/helm-charts/" ot-helm: "https://ot-container-kit.github.io/helm-charts/"
@ -11,7 +12,7 @@ helmRepos:
prometheus-community: https://prometheus-community.github.io/helm-charts prometheus-community: https://prometheus-community.github.io/helm-charts
apps: apps:
# valid apps # valid apps
kube-prometheus: kube-prometheus:
enabled: true enabled: true
namespace: monitoring namespace: monitoring
@ -44,14 +45,19 @@ apps:
namespace: strimzi namespace: strimzi
chart: strimzi/strimzi-kafka-operator chart: strimzi/strimzi-kafka-operator
version: 0.25.0 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: strimzi-operator-missing-version:
enabled: true enabled: true
namespace: strimzi namespace: strimzi
chart: strimzi/strimzi-kafka-operator chart: strimzi/strimzi-kafka-operator
# malformed chart # malformed chart
loki-no-registry-ref: loki-no-registry-ref:
enabled: true enabled: true
namespace: monitoring namespace: monitoring

View file

@ -48,6 +48,12 @@ exports[`modules/manager/helmsman/extract extractPackageFile() extract deps 1`]
"https://strimzi.io/charts/", "https://strimzi.io/charts/",
], ],
}, },
{
"currentValue": "6.4.0",
"datasource": "docker",
"depName": "podinfo",
"packageName": "ghcr.io/stefanprodan/charts/podinfo",
},
{ {
"datasource": "helm", "datasource": "helm",
"depName": "strimzi-operator-missing-version", "depName": "strimzi-operator-missing-version",

View file

@ -20,11 +20,17 @@ describe('modules/manager/helmsman/extract', () => {
expect(result).toBeNull(); 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', () => { it('extract deps', () => {
const fileName = 'helmsman.yaml'; const fileName = 'helmsman.yaml';
const result = extractPackageFile(multiDepFile, fileName, {}); const result = extractPackageFile(multiDepFile, fileName, {});
expect(result).not.toBeNull(); 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?.deps.filter((value) => value.skipReason)).toHaveLength(5);
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });

View file

@ -2,6 +2,7 @@ import is from '@sindresorhus/is';
import { load } from 'js-yaml'; import { load } from 'js-yaml';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { regEx } from '../../../util/regex'; import { regEx } from '../../../util/regex';
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm'; import { HelmDatasource } from '../../datasource/helm';
import type { import type {
ExtractConfig, ExtractConfig,
@ -31,6 +32,14 @@ function createDep(
} }
dep.currentValue = anApp.version; 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; const regexResult = anApp.chart ? chartRegex.exec(anApp.chart) : null;
if (!regexResult?.groups) { if (!regexResult?.groups) {
dep.skipReason = 'invalid-url'; dep.skipReason = 'invalid-url';
@ -63,8 +72,8 @@ export function extractPackageFile(
const doc = load(content, { const doc = load(content, {
json: true, json: true,
}) as HelmsmanDocument; }) as HelmsmanDocument;
if (!(doc?.helmRepos && doc.apps)) { if (!doc.apps) {
logger.debug({ packageFile }, `Missing helmRepos and/or apps keys`); logger.debug({ packageFile }, `Missing apps keys`);
return null; return null;
} }

View file

@ -1,4 +1,5 @@
import type { Category } from '../../../constants'; import type { Category } from '../../../constants';
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm'; import { HelmDatasource } from '../../datasource/helm';
export { extractPackageFile } from './extract'; export { extractPackageFile } from './extract';
@ -8,4 +9,4 @@ export const defaultConfig = {
export const categories: Category[] = ['cd', 'helm', 'kubernetes']; export const categories: Category[] = ['cd', 'helm', 'kubernetes'];
export const supportedDatasources = [HelmDatasource.id]; export const supportedDatasources = [HelmDatasource.id, DockerDatasource.id];