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/flux): Support OCI Helm repositories #22291

Merged
merged 15 commits into from May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/modules/manager/flux/__fixtures__/helmOCIRelease.yaml
@@ -0,0 +1,16 @@
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: arc-assets
namespace: dev
spec:
interval: 30m
chart:
spec:
chart: actions-runner-controller-charts/gha-runner-scale-set
version: 0.4.0
sourceRef:
kind: HelmRepository
name: actions-runner-controller
namespace: flux-system
interval: 30m
10 changes: 10 additions & 0 deletions lib/modules/manager/flux/__fixtures__/helmOCISource.yaml
@@ -0,0 +1,10 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: actions-runner-controller
namespace: flux-system
spec:
type: oci
interval: 30m
url: oci://ghcr.io/actions
timeout: 3m
23 changes: 23 additions & 0 deletions lib/modules/manager/flux/extract.spec.ts
Expand Up @@ -728,6 +728,29 @@ describe('modules/manager/flux/extract', () => {
]);
});

it('extract oci helm', async () => {
const result = await extractAllPackageFiles(config, [
'lib/modules/manager/flux/__fixtures__/helmOCISource.yaml',
'lib/modules/manager/flux/__fixtures__/helmOCIRelease.yaml',
]);
expect(result).toEqual([
{
deps: [
{
currentValue: '0.4.0',
datasource: DockerDatasource.id,
depName: 'actions-runner-controller-charts/gha-runner-scale-set',
packageName:
'ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set',
registryUrls: [],
},
],
packageFile:
'lib/modules/manager/flux/__fixtures__/helmOCIRelease.yaml',
},
]);
});

it('ignores files that do not exist', async () => {
const result = await extractAllPackageFiles(config, [
'lib/modules/manager/flux/__fixtures__/bogus.yaml',
Expand Down
21 changes: 20 additions & 1 deletion lib/modules/manager/flux/extract.ts
@@ -1,8 +1,10 @@
import is from '@sindresorhus/is';
import { loadAll } from 'js-yaml';
import { logger } from '../../../logger';
import { readLocalFile } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import { BitbucketTagsDatasource } from '../../datasource/bitbucket-tags';
import { DockerDatasource } from '../../datasource/docker';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { GitTagsDatasource } from '../../datasource/git-tags';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
Expand Down Expand Up @@ -181,7 +183,24 @@
resource.metadata?.namespace)
);
if (matchingRepositories.length) {
dep.registryUrls = matchingRepositories.map((repo) => repo.spec.url);
dep.registryUrls = matchingRepositories
.map((repo) => {
if (repo.spec.type === 'oci') {
// Change datasource to Docker
dep.datasource = DockerDatasource.id;
// Ensure the URL is a valid OCI path
dep.packageName = `${repo.spec.url.replace(
'oci://',
''
)}/${dep.depName!}`;
samip5 marked this conversation as resolved.
Show resolved Hide resolved
return null;
} else if (repo.spec.url.startsWith('oci://')) {
return repo.spec.url.replace('oci://', '');

Check warning on line 198 in lib/modules/manager/flux/extract.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/manager/flux/extract.ts#L198

Added line #L198 was not covered by tests
samip5 marked this conversation as resolved.
Show resolved Hide resolved
} else {
return repo.spec.url;
}
})
.filter(is.string);
samip5 marked this conversation as resolved.
Show resolved Hide resolved
} else {
dep.skipReason = 'unknown-registry';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/flux/readme.md
Expand Up @@ -9,8 +9,8 @@ This manager parses [Flux](https://fluxcd.io/) YAML manifests and supports:

Extracts `helm` dependencies from `HelmRelease` resources.

The `flux` manager only extracts `helm` dependencies for `HelmRelease` resources linked to `HelmRepository` or `GitRepository` sources.
Renovate does not support OCI `HelmRepository` sources, those with `type: oci`.
The `flux` manager extracts `helm` dependencies for `HelmRelease` resources linked to `HelmRepository` or `GitRepository` sources.
Renovate does support OCI `HelmRepository` sources, those with `type: oci`.

In addition, for the `flux` manager to properly link `HelmRelease` and `HelmRepository` resources, _both_ of the following conditions must be met:

Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/flux/types.ts
Expand Up @@ -34,6 +34,7 @@ export interface HelmRepository extends KubernetesResource {
kind: 'HelmRepository';
spec: {
url: string;
type: string;
samip5 marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down