fix(helmv3): set helm repositories from aliases to update Chart.lock (#12470)

This commit is contained in:
Jerome Garec 2021-11-04 07:47:48 +01:00 committed by GitHub
parent 87011e78ef
commit a687981810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 178 additions and 4 deletions

View file

@ -151,3 +151,123 @@ Array [
},
]
`;
exports[`manager/helmv3/artifacts sets repositories from aliases 1`] = `
Array [
Object {
"file": Object {
"contents": "New Chart.lock",
"name": "Chart.lock",
},
},
]
`;
exports[`manager/helmv3/artifacts sets repositories from aliases 2`] = `
Array [
Object {
"cmd": "helm repo add stable the_stable_url",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"HELM_EXPERIMENTAL_OCI": "1",
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
"HTTP_PROXY": "http://example.com",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
},
"maxBuffer": 10485760,
"timeout": 900000,
},
},
Object {
"cmd": "helm repo add repo1 the_repo1_url",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"HELM_EXPERIMENTAL_OCI": "1",
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
"HTTP_PROXY": "http://example.com",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
},
"maxBuffer": 10485760,
"timeout": 900000,
},
},
Object {
"cmd": "helm dependency update ''",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"HELM_EXPERIMENTAL_OCI": "1",
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
"HTTP_PROXY": "http://example.com",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
},
"maxBuffer": 10485760,
"timeout": 900000,
},
},
]
`;
exports[`manager/helmv3/artifacts sets repositories from aliases with docker 1`] = `
Array [
Object {
"file": Object {
"contents": "New Chart.lock",
"name": "Chart.lock",
},
},
]
`;
exports[`manager/helmv3/artifacts sets repositories from aliases with docker 2`] = `
Array [
Object {
"cmd": "docker pull renovate/helm",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker ps --filter name=renovate_helm -aq",
"options": Object {
"encoding": "utf-8",
},
},
Object {
"cmd": "docker run --rm --name=renovate_helm --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -e HELM_EXPERIMENTAL_OCI -w \\"/tmp/github/some/repo\\" renovate/helm bash -l -c \\"helm repo add stable the_stable_url && helm repo add repo1 the_repo1_url && helm dependency update ''\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"HELM_EXPERIMENTAL_OCI": "1",
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
"HTTP_PROXY": "http://example.com",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
},
"maxBuffer": 10485760,
"timeout": 900000,
},
},
]
`;

View file

@ -148,4 +148,47 @@ describe('manager/helmv3/artifacts', () => {
},
]);
});
it('sets repositories from aliases', async () => {
fs.readFile.mockResolvedValueOnce('Old Chart.lock' as never);
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce('New Chart.lock' as never);
expect(
await helmv3.updateArtifacts({
packageFileName: 'Chart.yaml',
updatedDeps: [],
newPackageFileContent: '{}',
config: {
...config,
updateType: 'lockFileMaintenance',
aliases: { stable: 'the_stable_url', repo1: 'the_repo1_url' },
},
})
).toMatchSnapshot([
{ file: { contents: 'New Chart.lock', name: 'Chart.lock' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
it('sets repositories from aliases with docker', async () => {
setGlobalConfig({ ...adminConfig, binarySource: 'docker' });
fs.readFile.mockResolvedValueOnce('Old Chart.lock' as never);
const execSnapshots = mockExecAll(exec);
fs.readFile.mockResolvedValueOnce('New Chart.lock' as never);
expect(
await helmv3.updateArtifacts({
packageFileName: 'Chart.yaml',
updatedDeps: [],
newPackageFileContent: '{}',
config: {
...config,
updateType: 'lockFileMaintenance',
aliases: { stable: 'the_stable_url', repo1: 'the_repo1_url' },
},
})
).toMatchSnapshot([
{ file: { contents: 'New Chart.lock', name: 'Chart.lock' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
});

View file

@ -10,9 +10,10 @@ import {
} from '../../util/fs';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
async function helmUpdate(manifestPath: string): Promise<void> {
const cmd = `helm dependency update ${quote(getSubDirectory(manifestPath))}`;
async function helmCommands(
manifestPath: string,
aliases?: Record<string, string>
): Promise<void> {
const execOptions: ExecOptions = {
docker: {
image: 'helm',
@ -21,6 +22,15 @@ async function helmUpdate(manifestPath: string): Promise<void> {
HELM_EXPERIMENTAL_OCI: '1',
},
};
const cmd = [];
if (aliases) {
Object.entries(aliases).forEach(([alias, url]) =>
cmd.push(`helm repo add ${quote(alias)} ${quote(url)}`)
);
}
cmd.push(`helm dependency update ${quote(getSubDirectory(manifestPath))}`);
await exec(cmd, execOptions);
}
@ -51,7 +61,7 @@ export async function updateArtifacts({
try {
await writeLocalFile(packageFileName, newPackageFileContent);
logger.debug('Updating ' + lockFileName);
await helmUpdate(packageFileName);
await helmCommands(packageFileName, config.aliases);
logger.debug('Returning updated Chart.lock');
const newHelmLockContent = await readLocalFile(lockFileName);
if (existingLockFileContent === newHelmLockContent) {

View file

@ -49,6 +49,7 @@ export interface UpdateArtifactsConfig {
newValue?: string;
newVersion?: string;
newMajor?: number;
aliases?: Record<string, string>;
}
export interface RangeConfig<T = Record<string, any>> extends ManagerData<T> {