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(kustomize): support OCI helm charts #27163

Merged
merged 11 commits into from
Mar 13, 2024
Expand Up @@ -13,3 +13,7 @@ helmCharts:
releaseName: moria
version: 3.1.3
repo: https://itzg.github.io/minecraft-server-charts
- name: redis
releaseName: redis
version: 18.12.1
repo: oci://registry-1.docker.io/bitnamicharts
Expand Up @@ -174,6 +174,14 @@ exports[`modules/manager/kustomize/extract extractPackageFile() parses helmChart
"https://itzg.github.io/minecraft-server-charts",
],
},
{
"currentValue": "18.12.1",
"datasource": "docker",
"depName": "redis",
"depType": "HelmChart",
"packageName": "registry-1.docker.io/bitnamicharts/redis",
"pinDigests": false,
},
],
}
`;
Expand Down
27 changes: 27 additions & 0 deletions lib/modules/manager/kustomize/extract.spec.ts
Expand Up @@ -167,14 +167,32 @@
currentValue: '29.6.0',
registryUrls: [registryUrl],
datasource: HelmDatasource.id,
depType: 'HelmChart',
viceice marked this conversation as resolved.
Show resolved Hide resolved
};
const pkg = extractHelmChart({
name: sample.depName,
version: sample.currentValue,
repo: registryUrl,
});
expect(pkg).toEqual(sample);

Check failure on line 177 in lib/modules/manager/kustomize/extract.spec.ts

View workflow job for this annotation

GitHub Actions / test (5/16)

modules/manager/kustomize/extract › extractHelmChart › should correctly extract a chart

expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 0 Object { "currentValue": "29.6.0", "datasource": "helm", "depName": "renovate", - "depType": "HelmChart", "registryUrls": Array [ "https://docs.renovatebot.com/helm-charts", ], } at Object.<anonymous> (lib/modules/manager/kustomize/extract.spec.ts:177:19)
});

it('should correctly extract an OCI chart', () => {
const sample = {
depName: 'redis',
packageName: 'registry-1.docker.io/bitnamicharts/redis',
currentValue: '18.12.1',
datasource: DockerDatasource.id,
pinDigests: false,
depType: 'HelmChart',
viceice marked this conversation as resolved.
Show resolved Hide resolved
};
const pkg = extractHelmChart({
name: sample.depName,
version: sample.currentValue,
repo: 'oci://registry-1.docker.io/bitnamicharts',
});
expect(pkg).toEqual(sample);

Check failure on line 194 in lib/modules/manager/kustomize/extract.spec.ts

View workflow job for this annotation

GitHub Actions / test (5/16)

modules/manager/kustomize/extract › extractHelmChart › should correctly extract an OCI chart

expect(received).toEqual(expected) // deep equality - Expected - 3 + Received + 2 Object { + "currentDigest": undefined, "currentValue": "18.12.1", "datasource": "docker", - "depName": "redis", - "depType": "HelmChart", - "packageName": "registry-1.docker.io/bitnamicharts/redis", + "depName": "registry-1.docker.io/bitnamicharts/redis", "pinDigests": false, } at Object.<anonymous> (lib/modules/manager/kustomize/extract.spec.ts:194:19)
});
});

describe('image extraction', () => {
Expand Down Expand Up @@ -495,14 +513,23 @@
'kustomization.yaml',
{},
);
expect(res).toMatchSnapshot({

Check failure on line 516 in lib/modules/manager/kustomize/extract.spec.ts

View workflow job for this annotation

GitHub Actions / test (5/16)

modules/manager/kustomize/extract › extractPackageFile() › parses helmChart field

expect(received).toMatchSnapshot(properties) Snapshot name: `modules/manager/kustomize/extract extractPackageFile() parses helmChart field 1` - Expected properties - 2 + Received value + 1 @@ -10,12 +10,11 @@ ], }, Object { "currentValue": "18.12.1", "datasource": "docker", - "depName": "redis", + "depName": "registry-1.docker.io/bitnamicharts/redis", "depType": "HelmChart", - "packageName": "registry-1.docker.io/bitnamicharts/redis", "pinDigests": false, }, ], } at Object.<anonymous> (lib/modules/manager/kustomize/extract.spec.ts:516:19)
deps: [
{
depType: 'HelmChart',
depName: 'minecraft',
currentValue: '3.1.3',
datasource: HelmDatasource.id,
registryUrls: ['https://itzg.github.io/minecraft-server-charts'],
},
{
depType: 'HelmChart',
depName: 'redis',
currentValue: '18.12.1',
datasource: DockerDatasource.id,
packageName: 'registry-1.docker.io/bitnamicharts/redis',
pinDigests: false,
},
],
});
});
Expand Down
13 changes: 12 additions & 1 deletion lib/modules/manager/kustomize/extract.ts
Expand Up @@ -7,6 +7,7 @@ import { GitTagsDatasource } from '../../datasource/git-tags';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { HelmDatasource } from '../../datasource/helm';
import { getDep } from '../dockerfile/extract';
import { isOCIRegistry } from '../helmv3/utils';
import type {
ExtractConfig,
PackageDependency,
Expand Down Expand Up @@ -140,11 +141,21 @@ export function extractImage(

export function extractHelmChart(
helmChart: HelmChart,
aliases?: Record<string, string> | undefined,
): PackageDependency | null {
if (!helmChart.name) {
return null;
}

if (isOCIRegistry(helmChart.repo)) {
return {
...getDep(`${helmChart.repo.replace('oci://', '')}/${helmChart.name}:${helmChart.version}`, false, aliases),
viceice marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/helm/helm/issues/10312
// https://github.com/helm/helm/issues/10678
pinDigests: false,
};
}

return {
depName: helmChart.name,
currentValue: helmChart.version,
Expand Down Expand Up @@ -238,7 +249,7 @@ export function extractPackageFile(

// grab the helm charts
for (const helmChart of coerceArray(pkg.helmCharts)) {
const dep = extractHelmChart(helmChart);
const dep = extractHelmChart(helmChart, config.registryAliases);
if (dep) {
deps.push({
...dep,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/kustomize/readme.md
Expand Up @@ -18,6 +18,7 @@ This manager uses three `depType`s to allow fine-grained control of which depend
- Component
- Kustomization
- HelmChart
- OCIChart

**Limitations**

Expand Down