Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Sep 8, 2023
12 changes: 12 additions & 0 deletions lib/modules/manager/helmsman/__fixtures__/missingApps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespaces:
domolitom marked this conversation as resolved.
Show resolved Hide resolved
redis-operator:
strimzi:
monitoring:
test-apps:

helmRepos:
ot-helm: "https://ot-container-kit.github.io/helm-charts/"
strimzi: "https://strimzi.io/charts/"
open-telemetry: "https://open-telemetry.github.io/opentelemetry-helm-charts"
grafana: "https://grafana.github.io/helm-charts"
prometheus-community: https://prometheus-community.github.io/helm-charts
36 changes: 31 additions & 5 deletions lib/modules/manager/helmsman/__fixtures__/validHelmsfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespaces:
redis-operator:
strimzi:
monitoring:
test-apps:

helmRepos:
ot-helm: "https://ot-container-kit.github.io/helm-charts/"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -68,11 +74,31 @@ 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
namespace: monitoring
version: 0.6.0
valuesFile: ./otlp-collector/values.yaml
priority: -75
podinfo-incorrect-url:
enabled: true
namespace: test-apps
chart: oci://
version: 6.4.0
podinfo-missing-chart:
enabled: true
namespace: test-apps
version: 6.4.0
podinfo-chart-null:
enabled: true
namespace: test-apps
version: 6.4.0
chart:
podinfo-incorrect-oci:
podinfo-incorrect-url:
enabled: true
namespace: test-apps
chart: oci://oci://
version: 6.4.0
domolitom marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions lib/modules/manager/helmsman/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -78,6 +84,30 @@ exports[`modules/manager/helmsman/extract extractPackageFile() extract deps 1`]
"depName": "otlp-collector-no-chart",
"skipReason": "invalid-url",
},
{
"currentValue": "6.4.0",
"datasource": "docker",
"depName": "podinfo-incorrect-url",
"packageName": "",
},
{
"currentValue": "6.4.0",
"datasource": "helm",
"depName": "podinfo-missing-chart",
"skipReason": "invalid-url",
},
{
"currentValue": "6.4.0",
"datasource": "helm",
"depName": "podinfo-chart-null",
"skipReason": "invalid-url",
},
{
"currentValue": "6.4.0",
"datasource": "docker",
"depName": "podinfo-incorrect-oci",
"packageName": "oci://",
},
],
}
`;
11 changes: 9 additions & 2 deletions lib/modules/manager/helmsman/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { extractPackageFile } from '.';

const multiDepFile = Fixtures.get('validHelmsfile.yaml');
const otherYamlFile = Fixtures.get('empty.yaml');
const incorrectYamlFile = Fixtures.get('missingApps.yaml');

describe('modules/manager/helmsman/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -20,12 +21,18 @@ describe('modules/manager/helmsman/extract', () => {
expect(result).toBeNull();
});

it('returns null if apps not defined', () => {
const fileName = 'incorrect.yaml';
const result = extractPackageFile(incorrectYamlFile, 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.filter((value) => value.skipReason)).toHaveLength(5);
expect(result?.deps).toHaveLength(15);
expect(result?.deps.filter((value) => value.skipReason)).toHaveLength(7);
expect(result).toMatchSnapshot();
});
});
Expand Down
13 changes: 11 additions & 2 deletions lib/modules/manager/helmsman/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/helmsman/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Category } from '../../../constants';
import { DockerDatasource } from '../../datasource/docker';
import { HelmDatasource } from '../../datasource/helm';
export { extractPackageFile } from './extract';

Expand All @@ -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];