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

feat(manager/helmfile): use the specific helmfile version that specified in the helmfile.lock. #22904

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/modules/manager/helmfile/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ describe('modules/manager/helmfile/artifacts', () => {
'bash -l -c "' +
'install-tool helm v3.7.2' +
' && ' +
'install-tool helmfile v0.129.0' +
'install-tool helmfile 0.151.0' +
' && ' +
'install-tool kustomize 5.0.0' +
' && ' +
Expand All @@ -338,7 +338,7 @@ describe('modules/manager/helmfile/artifacts', () => {
binarySource: 'install',
expectedCommands: [
{ cmd: 'install-tool helm v3.7.2' },
{ cmd: 'install-tool helmfile v0.129.0' },
{ cmd: 'install-tool helmfile 0.151.0' },
{ cmd: 'install-tool kustomize 5.0.0' },
{ cmd: 'helmfile deps -f helmfile.yaml' },
],
Expand All @@ -359,9 +359,6 @@ describe('modules/manager/helmfile/artifacts', () => {
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v3.7.2' }],
});
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v0.129.0' }],
});
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '5.0.0' }],
});
Expand Down
10 changes: 8 additions & 2 deletions lib/modules/manager/helmfile/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { getFile } from '../../../util/git';
import { regEx } from '../../../util/regex';
import { generateHelmEnvs } from '../helmv3/common';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
import { generateRegistryLoginCmd, isOCIRegistry, parseDoc } from './utils';
import {
generateRegistryLoginCmd,
isOCIRegistry,
parseDoc,
parseLock,
} from './utils';

export async function updateArtifacts({
packageFileName,
Expand Down Expand Up @@ -44,14 +49,15 @@ export async function updateArtifacts({
try {
await writeLocalFile(packageFileName, newPackageFileContent);

const helmfileVersion = parseLock(existingLockFileContent).version;
mugioka marked this conversation as resolved.
Show resolved Hide resolved
const toolConstraints: ToolConstraint[] = [
{
toolName: 'helm',
constraint: config.constraints?.helm,
},
{
toolName: 'helmfile',
constraint: config.constraints?.helmfile,
constraint: config.constraints?.helmfile ?? helmfileVersion,
},
];
const needKustomize = updatedDeps.some(
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/manager/helmfile/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ export const DocSchema = z.object({
releases: z.array(ReleaseSchema).optional(),
repositories: z.array(RepositorySchema).optional(),
});

export const LockSchema = z.object({
version: z.string(),
});
9 changes: 8 additions & 1 deletion lib/modules/manager/helmfile/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { z } from 'zod';

import type { DocSchema, ReleaseSchema, RepositorySchema } from './schema';
import type {
DocSchema,
LockSchema,
ReleaseSchema,
RepositorySchema,
} from './schema';

export type Release = z.infer<typeof ReleaseSchema>;

export type Repository = z.infer<typeof RepositorySchema>;

export type Doc = z.infer<typeof DocSchema>;

export type Lock = z.infer<typeof LockSchema>;
9 changes: 7 additions & 2 deletions lib/modules/manager/helmfile/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { DockerDatasource } from '../../datasource/docker';
import { generateLoginCmd } from '../helmv3/common';
import type { RepositoryRule } from '../helmv3/types';

import { DocSchema } from './schema';
import type { Doc, Release, Repository } from './types';
import { DocSchema, LockSchema } from './schema';
import type { Doc, Lock, Release, Repository } from './types';

/** Returns true if a helmfile release contains kustomize specific keys **/
export function kustomizationsKeysUsed(release: Release): boolean {
Expand Down Expand Up @@ -36,6 +36,11 @@ export function parseDoc(packageFileContent: string): Doc {
return DocSchema.parse(doc);
}

export function parseLock(lockFileContent: string): Lock {
const lock = yaml.load(lockFileContent);
return LockSchema.parse(lock);
}

export function isOCIRegistry(repository: Repository): boolean {
return repository.oci === true;
}
Expand Down