diff --git a/lib/modules/manager/flux/common.ts b/lib/modules/manager/flux/common.ts index b8f4b542cb03913d622d5e0922d0340352433707..8fff55a1cf3e425a4beb7e391514e5055f724f75 100644 --- a/lib/modules/manager/flux/common.ts +++ b/lib/modules/manager/flux/common.ts @@ -1,8 +1,10 @@ import { regEx } from '../../../util/regex'; -export const systemManifestRegex = - '(^|/)flux-system/(?:.+/)?gotk-components\\.ya?ml$'; +export const systemManifestFileNameRegex = '(?:^|/)gotk-components\\.ya?ml$'; + +export const systemManifestHeaderRegex = + '#\\s*Flux\\s+Version:\\s*(\\S+)(?:\\s*#\\s*Components:\\s*([A-Za-z,-]+))?'; export function isSystemManifest(file: string): boolean { - return regEx(systemManifestRegex).test(file); + return regEx(systemManifestFileNameRegex).test(file); } diff --git a/lib/modules/manager/flux/extract.spec.ts b/lib/modules/manager/flux/extract.spec.ts index 2775ec921276461b4354885c9d1bf5adcb2124c5..6a2291b8973c844d6952dcf90db66fddbe32bc0d 100644 --- a/lib/modules/manager/flux/extract.spec.ts +++ b/lib/modules/manager/flux/extract.spec.ts @@ -54,31 +54,42 @@ describe('modules/manager/flux/extract', () => { }); }); - it('extracts version and components from system manifests', () => { - const result = extractPackageFile( - Fixtures.get('flux-system/gotk-components.yaml'), - 'clusters/my-cluster/flux-system/gotk-components.yaml' - ); - expect(result).toEqual({ - deps: [ - { - currentValue: 'v0.24.1', - datasource: 'github-releases', - depName: 'fluxcd/flux2', - managerData: { - components: - 'source-controller,kustomize-controller,helm-controller,notification-controller', + it.each` + filepath + ${'clusters/my-cluster/flux-system/gotk-components.yaml'} + ${'clusters/my-cluster/flux-system/gotk-components.yml'} + ${'clusters/my-cluster/gotk-components.yaml'} + ${'clusters/my-cluster/gotk-components.yml'} + ${'gotk-components.yaml'} + `( + 'extracts version and components from system manifest at $filepath', + ({ filepath }) => { + const result = extractPackageFile( + Fixtures.get('flux-system/gotk-components.yaml'), + filepath + ); + expect(result).toEqual({ + deps: [ + { + currentValue: 'v0.24.1', + datasource: 'github-releases', + depName: 'fluxcd/flux2', + managerData: { + components: + 'source-controller,kustomize-controller,helm-controller,notification-controller', + }, }, - }, - ], - }); - }); + ], + }); + } + ); it('considers components optional in system manifests', () => { const result = extractPackageFile( `# Flux Version: v0.27.0`, 'clusters/my-cluster/flux-system/gotk-components.yaml' ); + expect(result).not.toBeNull(); expect(result?.deps[0].managerData?.components).toBeUndefined(); }); diff --git a/lib/modules/manager/flux/extract.ts b/lib/modules/manager/flux/extract.ts index a5b35b0bd5694d3e8999772cef1a04595675ebb4..bb7067ab9af97ea00740edf547305e2173164f1d 100644 --- a/lib/modules/manager/flux/extract.ts +++ b/lib/modules/manager/flux/extract.ts @@ -18,7 +18,7 @@ import type { PackageFile, PackageFileContent, } from '../types'; -import { isSystemManifest } from './common'; +import { isSystemManifest, systemManifestHeaderRegex } from './common'; import type { FluxManagerData, FluxManifest, @@ -33,9 +33,7 @@ function readManifest( packageFile: string ): FluxManifest | null { if (isSystemManifest(packageFile)) { - const versionMatch = regEx( - /#\s*Flux\s+Version:\s*(\S+)(?:\s*#\s*Components:\s*([A-Za-z,-]+))?/ - ).exec(content); + const versionMatch = regEx(systemManifestHeaderRegex).exec(content); if (!versionMatch) { return null; } diff --git a/lib/modules/manager/flux/index.ts b/lib/modules/manager/flux/index.ts index b693db339e92a88fed6a44e95a05db26b52be686..f25201d38016e58eb20d3c7a4ed25dfb0f75b756 100644 --- a/lib/modules/manager/flux/index.ts +++ b/lib/modules/manager/flux/index.ts @@ -7,13 +7,13 @@ import { GithubReleasesDatasource } from '../../datasource/github-releases'; import { GithubTagsDatasource } from '../../datasource/github-tags'; import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { HelmDatasource } from '../../datasource/helm'; -import { systemManifestRegex } from './common'; +import { systemManifestFileNameRegex } from './common'; export { extractAllPackageFiles, extractPackageFile } from './extract'; export { updateArtifacts } from './artifacts'; export const defaultConfig = { - fileMatch: [systemManifestRegex], + fileMatch: [systemManifestFileNameRegex], }; export const categories: Category[] = ['cd', 'kubernetes']; diff --git a/lib/modules/manager/flux/readme.md b/lib/modules/manager/flux/readme.md index 55af102a1d4998e80ebda7cfcc18a54ccbbce81c..a29db34a8792ceb46e14c12f609973ef71d8e25e 100644 --- a/lib/modules/manager/flux/readme.md +++ b/lib/modules/manager/flux/readme.md @@ -36,16 +36,24 @@ If `tag` _and_ `digest` exist then `digest` takes precedence. ### Flux system manifests support -Support updating Flux system manifests generated during [Flux installation](https://fluxcd.io/docs/installation/#customize-flux-manifests). +Renovate supports updating Flux system manifests generated during [Flux installation](https://fluxcd.io/docs/installation/#customize-flux-manifests). +System manifests are identified via being named `gotk-components.y(a)ml` and containing comment headers as generated by `flux bootstrap`. + +<!-- prettier-ignore --> +!!! warning + Renovate cannot identify the use of custom bootstrap flags, such as `--cluster-domain`. + In such a scenario Renovate's PR will overwrite these values with the Flux defaults. + See [issue #13952 on GitHub](https://github.com/renovatebot/renovate/issues/13952) for more information. Updating system manifests requires that either: 1. The `flux` tool is pre-installed, or 1. You run a Docker image based on [containerbase](https://github.com/containerbase), such as the official Renovate images, and have `binarySource=install` configured -### Non-configured fileMatch +### Default fileMatch -By default, the `flux` manager will only match `flux-system/{.,**}/gotk-components.yaml` (i.e. system manifest) files. +By default, the `flux` manager only matches `**/gotk-components.y(a)ml`. +So it only checks system manifest files generated by the `flux bootstrap` command. This is because there is no commonly accepted file/directory naming convention for Flux manifests and we don't want to check every single `*.yaml` file in repositories just in case some of them have Flux definitions.