fix(manager/flux): fix system manifest artifacts (#13912)
This commit is contained in:
Родитель
73f9d8bf34
Коммит
b3810b5fc7
|
@ -1,15 +1,22 @@
|
|||
import { exec, mockExecAll } from '../../../test/exec-util';
|
||||
import { fs } from '../../../test/util';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import { updateArtifacts } from '.';
|
||||
|
||||
jest.mock('child_process');
|
||||
jest.mock('../../util/fs');
|
||||
|
||||
describe('manager/flux/artifacts', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
beforeAll(() => {
|
||||
GlobalConfig.set({
|
||||
localDir: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('replaces existing value', async () => {
|
||||
mockExecAll(exec, { stdout: 'test', stderr: '' });
|
||||
mockExecAll(exec, { stdout: '', stderr: '' });
|
||||
fs.readLocalFile.mockResolvedValueOnce('old');
|
||||
fs.readLocalFile.mockResolvedValueOnce('test');
|
||||
|
||||
const res = await updateArtifacts({
|
||||
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
|
@ -40,6 +47,19 @@ describe('manager/flux/artifacts', () => {
|
|||
expect(res).toBeNull();
|
||||
});
|
||||
|
||||
it('ignores unchanged system manifests', async () => {
|
||||
fs.readLocalFile.mockResolvedValueOnce('old');
|
||||
fs.readLocalFile.mockResolvedValueOnce('old');
|
||||
const res = await updateArtifacts({
|
||||
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
updatedDeps: [{ newVersion: '1.0.1' }],
|
||||
newPackageFileContent: undefined,
|
||||
config: {},
|
||||
});
|
||||
|
||||
expect(res).toBeNull();
|
||||
});
|
||||
|
||||
it('ignores system manifests without a new version', async () => {
|
||||
const res = await updateArtifacts({
|
||||
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
|
@ -51,7 +71,7 @@ describe('manager/flux/artifacts', () => {
|
|||
expect(res).toBeNull();
|
||||
});
|
||||
|
||||
it('failed to generate manifests', async () => {
|
||||
it('failed to generate system manifest', async () => {
|
||||
mockExecAll(exec, new Error('failed'));
|
||||
const res = await updateArtifacts({
|
||||
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
|
@ -60,8 +80,34 @@ describe('manager/flux/artifacts', () => {
|
|||
config: {},
|
||||
});
|
||||
|
||||
expect(res[0].artifactError.lockFile).toBe(
|
||||
'clusters/my-cluster/flux-system/gotk-components.yaml'
|
||||
);
|
||||
expect(res).toStrictEqual([
|
||||
{
|
||||
artifactError: {
|
||||
lockFile: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
stderr: 'failed',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('failed to read system manifest', async () => {
|
||||
mockExecAll(exec, { stdout: '', stderr: 'Error' });
|
||||
fs.readLocalFile.mockResolvedValueOnce('old');
|
||||
fs.readLocalFile.mockResolvedValueOnce('');
|
||||
const res = await updateArtifacts({
|
||||
packageFileName: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
updatedDeps: [{ newVersion: '1.0.1' }],
|
||||
newPackageFileContent: undefined,
|
||||
config: {},
|
||||
});
|
||||
|
||||
expect(res).toStrictEqual([
|
||||
{
|
||||
artifactError: {
|
||||
lockFile: 'clusters/my-cluster/flux-system/gotk-components.yaml',
|
||||
stderr: 'Error',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { quote } from 'shlex';
|
||||
import { logger } from '../../logger';
|
||||
import { exec } from '../../util/exec';
|
||||
import type { ExecOptions } from '../../util/exec/types';
|
||||
import { readLocalFile } from '../../util/fs';
|
||||
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
|
||||
import { isSystemManifest } from './common';
|
||||
|
||||
|
@ -11,9 +13,10 @@ export async function updateArtifacts({
|
|||
if (!isSystemManifest(packageFileName) || !updatedDeps[0]?.newVersion) {
|
||||
return null;
|
||||
}
|
||||
const existingFileContent = await readLocalFile(packageFileName);
|
||||
try {
|
||||
logger.debug(`Updating Flux system manifests`);
|
||||
const cmd = 'flux install --export';
|
||||
const cmd = `flux install --export > ${quote(packageFileName)}`;
|
||||
const execOptions: ExecOptions = {
|
||||
docker: {
|
||||
image: 'sidecar',
|
||||
|
@ -27,12 +30,29 @@ export async function updateArtifacts({
|
|||
};
|
||||
const result = await exec(cmd, execOptions);
|
||||
|
||||
const newFileContent = await readLocalFile(packageFileName);
|
||||
if (!newFileContent) {
|
||||
logger.debug('Cannot read new flux file content');
|
||||
return [
|
||||
{
|
||||
artifactError: {
|
||||
lockFile: packageFileName,
|
||||
stderr: result.stderr,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
if (newFileContent === existingFileContent) {
|
||||
logger.debug('Flux contents are unchanged');
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
file: {
|
||||
type: 'addition',
|
||||
path: packageFileName,
|
||||
contents: result.stdout,
|
||||
contents: newFileContent,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
Загрузка…
Ссылка в новой задаче