diff --git a/lib/manager/kustomize/extract.spec.ts b/lib/manager/kustomize/extract.spec.ts index 9abae0efc101ff18178d83e0f53e36cddc64ae4e..77437cd77884db70d72dfb0b35cbe3e3d699fa58 100644 --- a/lib/manager/kustomize/extract.spec.ts +++ b/lib/manager/kustomize/extract.spec.ts @@ -4,9 +4,9 @@ import { GitTagsDatasource } from '../../datasource/git-tags'; import * as datasourceGitHubTags from '../../datasource/github-tags'; import { SkipReason } from '../../types'; import { - extractBase, extractImage, extractPackageFile, + extractResource, parseKustomize, } from './extract'; @@ -34,7 +34,7 @@ describe('manager/kustomize/extract', () => { }); describe('extractBase', () => { it('should return null for a local base', () => { - const res = extractBase('./service-1'); + const res = extractResource('./service-1'); expect(res).toBeNull(); }); it('should extract out the version of an http base', () => { @@ -46,11 +46,11 @@ describe('manager/kustomize/extract', () => { depName: 'user/test-repo', }; - const pkg = extractBase(`${base}?ref=${version}`); + const pkg = extractResource(`${base}?ref=${version}`); expect(pkg).toEqual(sample); }); it('should extract the version of a non http base', () => { - const pkg = extractBase( + const pkg = extractResource( 'ssh://git@bitbucket.com/user/test-repo?ref=v1.2.3' ); expect(pkg).toEqual({ @@ -61,7 +61,7 @@ describe('manager/kustomize/extract', () => { }); }); it('should extract the depName if the URL includes a port number', () => { - const pkg = extractBase( + const pkg = extractResource( 'ssh://git@bitbucket.com:7999/user/test-repo?ref=v1.2.3' ); expect(pkg).toEqual({ @@ -72,7 +72,7 @@ describe('manager/kustomize/extract', () => { }); }); it('should extract the version of a non http base with subdir', () => { - const pkg = extractBase( + const pkg = extractResource( 'ssh://git@bitbucket.com/user/test-repo/subdir?ref=v1.2.3' ); expect(pkg).toEqual({ @@ -91,7 +91,7 @@ describe('manager/kustomize/extract', () => { depName: 'fluxcd/flux', }; - const pkg = extractBase(`${base}?ref=${version}`); + const pkg = extractResource(`${base}?ref=${version}`); expect(pkg).toEqual(sample); }); it('should extract out the version of a git base', () => { @@ -103,7 +103,7 @@ describe('manager/kustomize/extract', () => { depName: 'user/repo', }; - const pkg = extractBase(`${base}?ref=${version}`); + const pkg = extractResource(`${base}?ref=${version}`); expect(pkg).toEqual(sample); }); it('should extract out the version of a git base with subdir', () => { @@ -115,7 +115,7 @@ describe('manager/kustomize/extract', () => { depName: 'user/repo', }; - const pkg = extractBase(`${base}?ref=${version}`); + const pkg = extractResource(`${base}?ref=${version}`); expect(pkg).toEqual(sample); }); }); @@ -247,6 +247,7 @@ describe('manager/kustomize/extract', () => { expect(res.deps[0].currentValue).toBe('v0.0.1'); expect(res.deps[1].currentValue).toBe('1.19.0'); expect(res.deps[2].currentValue).toBe('1.18.0'); + expect(res.deps[0].depName).toBe('moredhel/remote-kustomize'); expect(res.deps[1].depName).toBe('fluxcd/flux'); expect(res.deps[2].depName).toBe('fluxcd/flux'); expect(res.deps[0].depType).toBe('Kustomization'); @@ -261,6 +262,7 @@ describe('manager/kustomize/extract', () => { expect(res.deps[0].currentValue).toBe('1.19.0'); expect(res.deps[1].currentValue).toBe('1.18.0'); expect(res.deps[2].currentValue).toBe('v0.1.0'); + expect(res.deps[0].depName).toBe('fluxcd/flux'); expect(res.deps[1].depName).toBe('fluxcd/flux'); expect(res.deps[2].depName).toBe('node'); expect(res.deps[0].depType).toBe('Component'); diff --git a/lib/manager/kustomize/extract.ts b/lib/manager/kustomize/extract.ts index f2c223d8e987062be5866b6ec579fa6279cca5f8..f012353296558cba73536dd0a46a6944751c1ccf 100644 --- a/lib/manager/kustomize/extract.ts +++ b/lib/manager/kustomize/extract.ts @@ -16,7 +16,7 @@ const gitUrl = regEx( /^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^/\s]+\/[^/\s]+)))(?<subdir>[^?\s]*)\?ref=(?<currentValue>.+)$/ ); -export function extractBase(base: string): PackageDependency | null { +export function extractResource(base: string): PackageDependency | null { const match = gitUrl.exec(base); if (!match) { @@ -107,9 +107,9 @@ export function extractImage(image: Image): PackageDependency | null { } export function parseKustomize(content: string): Kustomize | null { - let pkg = null; + let pkg: Kustomize | null = null; try { - pkg = load(content, { json: true }); + pkg = load(content, { json: true }) as Kustomize; } catch (e) /* istanbul ignore next */ { return null; } @@ -122,12 +122,6 @@ export function parseKustomize(content: string): Kustomize | null { return null; } - pkg.bases = (pkg.bases || []).concat( - pkg.resources || [], - pkg.components || [] - ); - pkg.images = pkg.images || []; - return pkg; } @@ -141,8 +135,30 @@ export function extractPackageFile(content: string): PackageFile | null { } // grab the remote bases - for (const base of pkg.bases) { - const dep = extractBase(base); + for (const base of pkg.bases ?? []) { + const dep = extractResource(base); + if (dep) { + deps.push({ + ...dep, + depType: pkg.kind, + }); + } + } + + // grab the remote resources + for (const resource of pkg.resources ?? []) { + const dep = extractResource(resource); + if (dep) { + deps.push({ + ...dep, + depType: pkg.kind, + }); + } + } + + // grab the remote components + for (const component of pkg.components ?? []) { + const dep = extractResource(component); if (dep) { deps.push({ ...dep, @@ -152,7 +168,7 @@ export function extractPackageFile(content: string): PackageFile | null { } // grab the image tags - for (const image of pkg.images) { + for (const image of pkg.images ?? []) { const dep = extractImage(image); if (dep) { deps.push({ diff --git a/lib/manager/kustomize/types.ts b/lib/manager/kustomize/types.ts index 8693cd568ebcb264ac49eb11ead0c2ffd9edc7bd..d7a7c096e97b280982625a383a76ce0f663ef041 100644 --- a/lib/manager/kustomize/types.ts +++ b/lib/manager/kustomize/types.ts @@ -6,6 +6,8 @@ export interface Image { } export interface Kustomize { kind: string; - bases: string[]; - images: Image[]; + bases?: string[]; // deprecated since kustomize v2.1.0 + resources?: string[]; + components?: string[]; + images?: Image[]; }