diff --git a/lib/modules/manager/helmfile/__fixtures__/uses-kustomization.yaml b/lib/modules/manager/helmfile/__fixtures__/uses-kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..13db1e75ffdcf1efdc152a82b85446a068c94390 --- /dev/null +++ b/lib/modules/manager/helmfile/__fixtures__/uses-kustomization.yaml @@ -0,0 +1,10 @@ +repositories: + - name: bitnami + url: https://charts.bitnami.com/bitnami + +releases: + - name: my-chart + chart: ../charts/my-chart + - name: memcached + version: 6.0.0 + chart: bitnami/memcached diff --git a/lib/modules/manager/helmfile/extract.spec.ts b/lib/modules/manager/helmfile/extract.spec.ts index 5405340710b20189a16a812ca5eaec66f47bf123..479fad453fa7800e9d545e22e5575bc1057329dd 100644 --- a/lib/modules/manager/helmfile/extract.spec.ts +++ b/lib/modules/manager/helmfile/extract.spec.ts @@ -1,14 +1,17 @@ import { Fixtures } from '../../../../test/fixtures'; import { fs } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; +import { FILE_ACCESS_VIOLATION_ERROR } from '../../../constants/error-messages'; import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); +const localDir = '/tmp/github/some/repo'; + describe('modules/manager/helmfile/extract', () => { describe('extractPackageFile()', () => { beforeEach(() => { - GlobalConfig.set({ localDir: '/tmp/github/some/repo' }); + GlobalConfig.set({ localDir }); jest.resetAllMocks(); }); @@ -385,5 +388,41 @@ describe('modules/manager/helmfile/extract', () => { managerData: { needKustomize: true }, }); }); + + it('detects kustomize and respects relative paths', async () => { + fs.localPathExists.mockImplementationOnce((path) => { + if (!path.startsWith(GlobalConfig.get('localDir') ?? '')) { + throw new Error(FILE_ACCESS_VIOLATION_ERROR); + } + return Promise.resolve(true); + }); + + const parentDir = `${localDir}/project`; + fs.getParentDir.mockReturnValue(parentDir); + const result = await extractPackageFile( + Fixtures.get('uses-kustomization.yaml'), + `${parentDir}/helmfile.yaml`, // In subdir + { + registryAliases: { + stable: 'https://charts.helm.sh/stable', + }, + } + ); + expect(result).toMatchObject({ + datasource: 'helm', + deps: [ + { + depName: 'my-chart', + skipReason: 'local-chart', + }, + { + depName: 'memcached', + currentValue: '6.0.0', + registryUrls: ['https://charts.bitnami.com/bitnami'], + }, + ], + managerData: { needKustomize: true }, + }); + }); }); }); diff --git a/lib/modules/manager/helmfile/extract.ts b/lib/modules/manager/helmfile/extract.ts index 347f8cf77f7cbdad46b54ea0dfdc972f02a91626..a1c6bc4c96a6e80ff2ec18d39712bb17228d8153 100644 --- a/lib/modules/manager/helmfile/extract.ts +++ b/lib/modules/manager/helmfile/extract.ts @@ -75,7 +75,7 @@ export async function extractPackageFile( if (isLocalPath(dep.chart)) { if ( kustomizationsKeysUsed(dep) || - (await localChartHasKustomizationsYaml(dep)) + (await localChartHasKustomizationsYaml(dep, fileName)) ) { needKustomize = true; } diff --git a/lib/modules/manager/helmfile/utils.ts b/lib/modules/manager/helmfile/utils.ts index 16abccda2a3997e26b8534d6ddfbe5457f442753..9f843612c59061d7b5b356a404f8dfda9967e01b 100644 --- a/lib/modules/manager/helmfile/utils.ts +++ b/lib/modules/manager/helmfile/utils.ts @@ -1,6 +1,6 @@ import upath from 'upath'; -import { localPathExists } from '../../../util/fs'; +import { getParentDir, localPathExists } from '../../../util/fs'; import type { Release } from './types'; /** Returns true if a helmfile release contains kustomize specific keys **/ @@ -15,7 +15,11 @@ export function kustomizationsKeysUsed(release: Release): boolean { /** Returns true if a helmfile release uses a local chart with a kustomization.yaml file **/ // eslint-disable-next-line require-await export async function localChartHasKustomizationsYaml( - release: Release + release: Release, + helmFileYamlFileName: string ): Promise<boolean> { - return localPathExists(upath.join(release.chart, 'kustomization.yaml')); + const helmfileYamlParentDir = getParentDir(helmFileYamlFileName) || ''; + return localPathExists( + upath.join(helmfileYamlParentDir, release.chart, 'kustomization.yaml') + ); }