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 4 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
35 changes: 35 additions & 0 deletions lib/modules/manager/flux/__fixtures__/helmOCIRelease.yaml
@@ -0,0 +1,35 @@
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

values:
samip5 marked this conversation as resolved.
Show resolved Hide resolved
runnerScaleSetName: arc-runner-set-assets

githubConfigUrl: https://github.com/bjw-s/assets

minRunners: 0
maxRunners: 2

containerMode:
type: "dind"

template:
spec:
containers:
- name: runner
image: ghcr.io/bjw-s/github-actions-runner:2.304.0@sha256:85690088155072a95c429a1f150f80a7d7ebf35107221cb25c01c56b62866c1b
command:
- /home/runner/run.sh
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
24 changes: 24 additions & 0 deletions lib/modules/manager/flux/extract.spec.ts
Expand Up @@ -728,6 +728,30 @@ 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:
'ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set',
registryUrls: [
'ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set',
],
},
],
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
18 changes: 17 additions & 1 deletion lib/modules/manager/flux/extract.ts
Expand Up @@ -3,6 +3,7 @@
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 +182,22 @@
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.depName = `${repo.spec.url.replace(
samip5 marked this conversation as resolved.
Show resolved Hide resolved
'oci://',
''
)}/${dep.depName!}`;
return dep.depName;
samip5 marked this conversation as resolved.
Show resolved Hide resolved
} else if (repo.spec.url.startsWith('oci://')) {
return repo.spec.url.replace('oci://', '');

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L196 was not covered by tests
} else {
return repo.spec.url;
}
});
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