fix(manager): support newer kustomize urls (#6206)

This commit is contained in:
Michael Kriese 2020-05-12 19:07:25 +02:00 committed by GitHub
parent 9f89157e17
commit a0b8b87c74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 1 deletions

View file

@ -3,8 +3,12 @@ kind: Kustomization
bases:
- github.com/user/repo//deploy?ref=v0.0.1
- github.com/fluxcd/flux/deploy?ref=1.19.0
namespace: testing-namespace
resources:
- deployment.yaml
images:
- name: nginx

View file

@ -8,6 +8,12 @@ Array [
"depName": "github.com/user/repo//deploy",
"lookupName": "github.com/user/repo",
},
Object {
"currentValue": "1.19.0",
"datasource": "github-tags",
"depName": "fluxcd/flux/deploy",
"lookupName": "fluxcd/flux",
},
]
`;

View file

@ -1,6 +1,7 @@
import { readFileSync } from 'fs';
import * as datasourceDocker from '../../datasource/docker';
import * as datasourceGitTags from '../../datasource/git-tags';
import * as datasourceGitHubTags from '../../datasource/github-tags';
import {
extractBase,
extractImage,
@ -70,6 +71,20 @@ describe('manager/kustomize/extract', () => {
const pkg = extractBase(`${base}?ref=${version}`);
expect(pkg).toEqual(sample);
});
it('should extract out the version of an github base', () => {
const base = 'fluxcd/flux/deploy';
const version = 'v1.0.0';
const sample = {
currentValue: version,
datasource: datasourceGitHubTags.id,
depName: base,
lookupName: 'fluxcd/flux',
};
const pkg = extractBase(`github.com/${base}?ref=${version}`);
expect(pkg).toEqual(sample);
});
it('should extract out the version of a git base', () => {
const base = 'git@github.com:user/repo.git';
const version = 'v1.0.0';
@ -193,8 +208,11 @@ describe('manager/kustomize/extract', () => {
it('extracts http dependency', () => {
const res = extractPackageFile(kustomizeHTTP);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
expect(res.deps).toHaveLength(2);
expect(res.deps[0].currentValue).toEqual('v0.0.1');
expect(res.deps[1].currentValue).toEqual('1.19.0');
expect(res.deps[1].depName).toEqual('fluxcd/flux/deploy');
expect(res.deps[1].lookupName).toEqual('fluxcd/flux');
});
it('should extract out image versions', () => {
const res = extractPackageFile(gitImages);

View file

@ -1,6 +1,7 @@
import { safeLoad } from 'js-yaml';
import * as datasourceDocker from '../../datasource/docker';
import * as datasourceGitTags from '../../datasource/git-tags';
import * as datasourceGitHubTags from '../../datasource/github-tags';
import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
@ -21,7 +22,22 @@ const versionMatch = /(?<basename>.*)\?ref=(?<version>.*)\s*$/;
// extract the url from the base of a url with a subdir
const extractUrl = /^(?<url>.*)(?:\/\/.*)$/;
const githubUrl = /^github\.com\/(?<depName>(?<lookupName>[^/]+?\/[^/]+?)(?:\/[^/]+?)*)\?ref=(?<currentValue>.+)$/;
export function extractBase(base: string): PackageDependency | null {
const githubMatch = githubUrl.exec(base);
if (githubMatch?.groups) {
const { currentValue, depName, lookupName } = githubMatch.groups;
return {
datasource: datasourceGitHubTags.id,
depName,
lookupName,
currentValue,
};
}
const basenameVersion = versionMatch.exec(base);
if (basenameVersion) {
const currentValue = basenameVersion.groups.version;