Skip to content

Commit

Permalink
feat(manager/helmfile): Detect kustomization.yaml (#21111)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
nikolaik and viceice committed Apr 12, 2023
1 parent 5538ffd commit b1424dd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 54 deletions.
4 changes: 2 additions & 2 deletions lib/modules/manager/helmfile/__fixtures__/go-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ releases:
chart: ./foo
- name: "{{ requiredEnv \"RELEASE_NAME\" }}"
namespace: default
chart: ../bar
chart: ../repo/bar
- name: "{{ requiredEnv \"RELEASE_NAME\" }}"
namespace: default
chart: /baz
chart: /tmp/github/some/repo/baz
- name: {{ requiredEnv "RELEASE_NAME" }}
namespace: default
chart: ./foo
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/manager/helmfile/__fixtures__/multidoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ repositories:
url: https://charts.bitnami.com/bitnami
- name: prometheus-community
url: https://prometheus-community.github.io/helm-charts
- name: incubator
url: https://charts.helm.sh/incubator/

templates:
external-chart: &external-chart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ exports[`modules/manager/helmfile/extract extractPackageFile() parses multidoc y
{
"currentValue": "0.1.0",
"depName": "raw",
"managerData": {
"needKustomize": true,
},
"registryUrls": [
"https://charts.helm.sh/incubator/",
],
},
],
"managerData": {
"needKustomize": true,
},
}
`;

Expand Down
67 changes: 39 additions & 28 deletions lib/modules/manager/helmfile/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import { extractPackageFile } from '.';

jest.mock('../../../util/fs');

describe('modules/manager/helmfile/extract', () => {
describe('extractPackageFile()', () => {
beforeEach(() => {
GlobalConfig.set({ localDir: '/tmp/github/some/repo' });
jest.resetAllMocks();
});

it('returns null if no releases', () => {
it('returns null if no releases', async () => {
const content = `
repositories:
- name: kiwigrid
url: https://kiwigrid.github.io
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});

it('do not crash on invalid helmfile.yaml', () => {
it('do not crash on invalid helmfile.yaml', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -31,15 +36,15 @@ describe('modules/manager/helmfile/extract', () => {
releases: [
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});

it('skip if repository details are not specified', () => {
it('skip if repository details are not specified', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -50,7 +55,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: experimental/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -60,7 +65,7 @@ describe('modules/manager/helmfile/extract', () => {
expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy();
});

it('skip templetized release with invalid characters', () => {
it('skip templetized release with invalid characters', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -74,7 +79,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: stable/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -94,7 +99,7 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('skip local charts', () => {
it('skip local charts', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -105,7 +110,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: ./charts/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -115,7 +120,7 @@ describe('modules/manager/helmfile/extract', () => {
expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy();
});

it('skip chart with unknown repository', () => {
it('skip chart with unknown repository', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -126,7 +131,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -136,7 +141,7 @@ describe('modules/manager/helmfile/extract', () => {
expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy();
});

it('skip chart with special character in the name', () => {
it('skip chart with special character in the name', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -150,7 +155,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: kiwigrid/example?example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -160,7 +165,7 @@ describe('modules/manager/helmfile/extract', () => {
expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy();
});

it('skip chart that does not have specified version', () => {
it('skip chart that does not have specified version', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -170,7 +175,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: stable/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -180,9 +185,9 @@ describe('modules/manager/helmfile/extract', () => {
expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy();
});

it('parses multidoc yaml', () => {
it('parses multidoc yaml', async () => {
const fileName = 'helmfile.yaml';
const result = extractPackageFile(
const result = await extractPackageFile(
Fixtures.get('multidoc.yaml'),
fileName,
{
Expand All @@ -199,12 +204,13 @@ describe('modules/manager/helmfile/extract', () => {
{ depName: 'kube-prometheus-stack', currentValue: '13.7' },
{ depName: 'invalid', skipReason: 'invalid-name' },
{ depName: 'external-dns', skipReason: 'invalid-version' },
{ depName: 'raw', managerData: { needKustomize: true } },
{ depName: 'raw' },
],
managerData: { needKustomize: true },
});
});

it('parses a chart with a go templating', () => {
it('parses a chart with a go templating', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -222,7 +228,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: stable/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -242,7 +248,7 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('parses a chart with empty strings for template values', () => {
it('parses a chart with empty strings for template values', async () => {
const content = `
repositories:
- name: kiwigrid
Expand All @@ -259,7 +265,7 @@ describe('modules/manager/helmfile/extract', () => {
chart: stable/example
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -281,7 +287,7 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('parses a chart with an oci repository and non-oci one', () => {
it('parses a chart with an oci repository and non-oci one', async () => {
const content = `
repositories:
- name: oci-repo
Expand All @@ -299,7 +305,7 @@ describe('modules/manager/helmfile/extract', () => {
version: 3.3.0
`;
const fileName = 'helmfile.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -321,9 +327,10 @@ describe('modules/manager/helmfile/extract', () => {
});
});

it('parses and replaces templating strings', () => {
it('parses and replaces templating strings', async () => {
const filename = 'helmfile.yaml';
const result = extractPackageFile(
fs.localPathExists.mockReturnValue(Promise.resolve(true));
const result = await extractPackageFile(
Fixtures.get('go-template.yaml'),
filename,
{
Expand All @@ -347,7 +354,10 @@ describe('modules/manager/helmfile/extract', () => {
depName: '',
skipReason: 'local-chart',
},
{ depName: null, skipReason: 'local-chart' },
{
depName: null,
skipReason: 'local-chart',
},
{
depName: 'ingress-nginx',
currentValue: '3.37.0',
Expand All @@ -372,6 +382,7 @@ describe('modules/manager/helmfile/extract', () => {
registryUrls: ['https://charts.helm.sh/stable'],
},
],
managerData: { needKustomize: true },
});
});
});
Expand Down

0 comments on commit b1424dd

Please sign in to comment.