Skip to content

Commit

Permalink
Add support for additional query parameters in kustomize resource URLs.
Browse files Browse the repository at this point in the history
Kustomize allows the following query string parameter in it's remote resource URLs:

- ref
- version
- timeout
- submodules

(refer to https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md for full description)

This makes renovate aware of these and allows to correctly extract the current version in case more parameters are being used by the end-user.
  • Loading branch information
roosmaa committed Nov 26, 2024
1 parent 9cbf83a commit 88c37f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
28 changes: 28 additions & 0 deletions lib/modules/manager/kustomize/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ describe('modules/manager/kustomize/extract', () => {
const pkg = extractResource(`${base}?ref=${version}`);
expect(pkg).toEqual(sample);
});

it('should extract out the version of an http base with additional params', () => {
const base = 'https://github.com/user/test-repo.git';
const version = 'v1.0.0';
const sample = {
currentValue: version,
datasource: GithubTagsDatasource.id,
depName: 'user/test-repo',
};

const pkg = extractResource(
`${base}?timeout=120&ref=${version}&submodules=false&version=v1`,
);
expect(pkg).toEqual(sample);
});

it('should extract out the version of an http base from version param', () => {
const base = 'https://github.com/user/test-repo.git';
const version = 'v1.0.0';
const sample = {
currentValue: version,
datasource: GithubTagsDatasource.id,
depName: 'user/test-repo',
};

const pkg = extractResource(`${base}?version=${version}`);
expect(pkg).toEqual(sample);
});
});

describe('extractHelmChart', () => {
Expand Down
22 changes: 15 additions & 7 deletions lib/modules/manager/kustomize/extract.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import querystring from 'querystring';
import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { coerceArray } from '../../../util/array';
Expand All @@ -18,19 +19,19 @@ import type { HelmChart, Image, Kustomize } from './types';
// URL specifications should follow the hashicorp URL format
// https://github.com/hashicorp/go-getter#url-format
const gitUrl = regEx(
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^/\s]+\/[^/\s]+)))(?<subdir>[^?\s]*)\?ref=(?<currentValue>.+)$/,
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^/\s]+\/[^/\s]+)))(?<subdir>[^?\s]*)\?(?<queryString>.+)$/,
);
// regex to match URLs with ".git" delimiter
const dotGitRegex = regEx(
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^?\s]*(\.git))))(?<subdir>[^?\s]*)\?ref=(?<currentValue>.+)$/,
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^?\s]*(\.git))))(?<subdir>[^?\s]*)\?(?<queryString>.+)$/,
);
// regex to match URLs with "_git" delimiter
const underscoreGitRegex = regEx(
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^?\s]*)(_git\/[^/\s]+)))(?<subdir>[^?\s]*)\?ref=(?<currentValue>.+)$/,
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])?(?<project>[^?\s]*)(_git\/[^/\s]+)))(?<subdir>[^?\s]*)\?(?<queryString>.+)$/,
);
// regex to match URLs having an extra "//"
const gitUrlWithPath = regEx(
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])(?<project>[^?\s]+)))(?:\/\/)(?<subdir>[^?\s]+)\?ref=(?<currentValue>.+)$/,
/^(?:git::)?(?<url>(?:(?:(?:http|https|ssh):\/\/)?(?:.*@)?)?(?<path>(?:[^:/\s]+(?::[0-9]+)?[:/])(?<project>[^?\s]+)))(?:\/\/)(?<subdir>[^?\s]+)\?(?<queryString>.+)$/,
);

export function extractResource(base: string): PackageDependency | null {
Expand All @@ -50,10 +51,17 @@ export function extractResource(base: string): PackageDependency | null {
return null;
}

const { path } = match.groups;
const { path, queryString } = match.groups;
const params = querystring.parse(queryString);
const refParam = Array.isArray(params.ref) ? params.ref[0] : params.ref;
const versionParam = Array.isArray(params.version)
? params.version[0]
: params.version;
const currentValue = refParam ?? versionParam;

if (regEx(/(?:github\.com)(:|\/)/).test(path)) {
return {
currentValue: match.groups.currentValue,
currentValue,
datasource: GithubTagsDatasource.id,
depName: match.groups.project.replace('.git', ''),
};
Expand All @@ -63,7 +71,7 @@ export function extractResource(base: string): PackageDependency | null {
datasource: GitTagsDatasource.id,
depName: path.replace('.git', ''),
packageName: match.groups.url,
currentValue: match.groups.currentValue,
currentValue,
};
}

Expand Down

0 comments on commit 88c37f3

Please sign in to comment.