Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helmfile): lock update for multidoc YAML #31698

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions lib/modules/manager/helmfile/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,94 @@ describe('modules/manager/helmfile/artifacts', () => {
},
]);
});

it('updates lockfile with multidoc YAML', async () => {
const multidocYaml = codeBlock`
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: metallb
namespace: flux-system
spec:
interval: 30m
url: https://metallb.github.io/metallb
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: metallb
namespace: flux-system
spec:
interval: 5m
install:
createNamespace: true
targetNamespace: metallb-system
chart:
spec:
chart: metallb
version: 0.13.10
sourceRef:
kind: HelmRepository
name: metallb
namespace: flux-system
values:
controller:
image:
repository: quay.io/metallb/controller
tag: v0.13.10
speaker:
image:
repository: quay.io/metallb/speaker
tag: v0.13.10
frr:
enabled: false
`;
const lockFileMultidoc = codeBlock`
version: 0.151.0
dependencies:
- name: metallb
repository: https://metallb.github.io/metallb
version: 0.13.9
digest: sha256:e284706b71f37b757a536703da4cb148d67901afbf1ab431f7d60a9852ca6eef
generated: "2023-03-08T21:32:06.122276997+01:00"
`;
const lockFileMultidocUpdated = codeBlock`
version: 0.151.0
dependencies:
- name: metallb
repository: https://metallb.github.io/metallb
version: 0.13.10
digest: sha256:9d83889176d005effb86041d30c20361625561cbfb439cbd16d7243225bac17c
generated: "2023-03-08T21:30:48.273709455+01:00"
`;

git.getFile.mockResolvedValueOnce(lockFileMultidoc as never);
fs.getSiblingFileName.mockReturnValueOnce('helmfile.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce(lockFileMultidocUpdated as never);
fs.privateCacheDir.mockReturnValue(
'/tmp/renovate/cache/__renovate-private-cache',
);
fs.getParentDir.mockReturnValue('');
const updatedDeps = [{ depName: 'metallb' }];
expect(
await helmfile.updateArtifacts({
packageFileName: 'helmfile.yaml',
updatedDeps,
newPackageFileContent: multidocYaml,
config,
}),
).toEqual([
{
file: {
type: 'addition',
path: 'helmfile.lock',
contents: lockFileMultidocUpdated,
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'helmfile deps -f helmfile.yaml' },
]);
});
});
24 changes: 13 additions & 11 deletions lib/modules/manager/helmfile/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { getFile } from '../../../util/git';
import { regEx } from '../../../util/regex';
import { Result } from '../../../util/result';
import { parseSingleYaml } from '../../../util/yaml';
import { parseYaml } from '../../../util/yaml';
import { generateHelmEnvs } from '../helmv3/common';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
import { Doc, LockVersion } from './schema';
Expand Down Expand Up @@ -70,21 +70,23 @@ export async function updateArtifacts({
}

const cmd: string[] = [];
const doc = parseSingleYaml(newPackageFileContent, {
const docs = parseYaml(newPackageFileContent, {
removeTemplates: true,
customSchema: Doc,
rarkins marked this conversation as resolved.
Show resolved Hide resolved
});

for (const value of coerceArray(doc.repositories).filter(isOCIRegistry)) {
const loginCmd = await generateRegistryLoginCmd(
value.name,
`https://${value.url}`,
// this extracts the hostname from url like format ghcr.ip/helm-charts
value.url.replace(regEx(/\/.*/), ''),
);
for (const doc of docs) {
for (const value of coerceArray(doc.repositories).filter(isOCIRegistry)) {
const loginCmd = await generateRegistryLoginCmd(
value.name,
`https://${value.url}`,
// this extracts the hostname from url like format ghcr.ip/helm-charts
value.url.replace(regEx(/\/.*/), ''),
);

if (loginCmd) {
cmd.push(loginCmd);
if (loginCmd) {
cmd.push(loginCmd);
}
}
}

Expand Down