mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 16:46:25 +00:00
fix(manager:helmfile): remove go templating strings on a best effort basis for yaml parsing (#15106)
Signed-off-by: Jack Andersen <jandersen@plaid.com> Co-authored-by: Rhys Arkins <rhys@arkins.net> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
173ab07013
commit
2af3717baf
4 changed files with 170 additions and 3 deletions
39
lib/modules/manager/helmfile/__fixtures__/go-template.yaml
Normal file
39
lib/modules/manager/helmfile/__fixtures__/go-template.yaml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
repositories:
|
||||||
|
- name: incubator
|
||||||
|
url: https://charts.helm.sh/incubator/
|
||||||
|
- name: bitnami
|
||||||
|
url: https://charts.bitnami.com/bitnami
|
||||||
|
- name: prometheus-community
|
||||||
|
url: https://prometheus-community.github.io/helm-charts
|
||||||
|
|
||||||
|
releases:
|
||||||
|
- name: "{{ requiredEnv \"RELEASE_NAME\" }}"
|
||||||
|
namespace: default
|
||||||
|
chart: ./foo
|
||||||
|
- name: {{ requiredEnv "RELEASE_NAME" }}
|
||||||
|
namespace: default
|
||||||
|
chart: ./foo
|
||||||
|
{{ if .Values.nginx.intranet.enabled }}
|
||||||
|
- name: nginx-intranet
|
||||||
|
chart: ingress-nginx/ingress-nginx
|
||||||
|
version: 3.37.0
|
||||||
|
{{ end }}
|
||||||
|
- name: example
|
||||||
|
{{- if neq .Values.example.version "" }}
|
||||||
|
version: {{ .Values.example.version }}
|
||||||
|
{{- else }}
|
||||||
|
version: 6.0.0
|
||||||
|
{{- end }}
|
||||||
|
chart: bitnami/memcached
|
||||||
|
- name: example-internal
|
||||||
|
version: 1.30.0
|
||||||
|
chart: stable/example
|
||||||
|
- name: example-private
|
||||||
|
version: {{ .Values.example.version }}
|
||||||
|
chart: prometheus-community/kube-prometheus-stack
|
||||||
|
- name: example-external
|
||||||
|
version: 1.48.0
|
||||||
|
chart: {{ .Values.example.repository }}
|
||||||
|
- name: example-public
|
||||||
|
version: 2.0.0
|
||||||
|
chart: stable/external-dns
|
|
@ -116,7 +116,7 @@ Object {
|
||||||
"deps": Array [
|
"deps": Array [
|
||||||
Object {
|
Object {
|
||||||
"currentValue": "1.0.0",
|
"currentValue": "1.0.0",
|
||||||
"depName": "{{\`{{ .Release.Name }}\`}}",
|
"depName": "!!!!--!",
|
||||||
"registryUrls": Array [
|
"registryUrls": Array [
|
||||||
"https://charts.helm.sh/stable",
|
"https://charts.helm.sh/stable",
|
||||||
],
|
],
|
||||||
|
|
|
@ -68,7 +68,7 @@ describe('modules/manager/helmfile/extract', () => {
|
||||||
releases:
|
releases:
|
||||||
- name: example
|
- name: example
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
chart: stable/{{\`{{ .Release.Name }}\`}}
|
chart: stable/!!!!--!
|
||||||
- name: example-internal
|
- name: example-internal
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
chart: stable/example
|
chart: stable/example
|
||||||
|
@ -202,5 +202,128 @@ describe('modules/manager/helmfile/extract', () => {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses a chart with a go templating', () => {
|
||||||
|
const content = `
|
||||||
|
repositories:
|
||||||
|
- name: kiwigrid
|
||||||
|
url: https://kiwigrid.github.io
|
||||||
|
releases:
|
||||||
|
- name: example
|
||||||
|
{{- if neq .Values.example.version "" }}
|
||||||
|
version: {{ .Values.example.version }}
|
||||||
|
{{- else }}
|
||||||
|
version: 1.0.0
|
||||||
|
{{- end }}
|
||||||
|
chart: stable/example
|
||||||
|
- name: example-internal
|
||||||
|
version: 1.0.0
|
||||||
|
chart: stable/example
|
||||||
|
`;
|
||||||
|
const fileName = 'helmfile.yaml';
|
||||||
|
const result = extractPackageFile(content, fileName, {
|
||||||
|
aliases: {
|
||||||
|
stable: 'https://charts.helm.sh/stable',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
datasource: 'helm',
|
||||||
|
deps: [
|
||||||
|
{
|
||||||
|
currentValue: '1.0.0',
|
||||||
|
depName: 'example',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currentValue: '1.0.0',
|
||||||
|
depName: 'example',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses a chart with empty strings for template values', () => {
|
||||||
|
const content = `
|
||||||
|
repositories:
|
||||||
|
- name: kiwigrid
|
||||||
|
url: https://kiwigrid.github.io
|
||||||
|
releases:
|
||||||
|
- name: example
|
||||||
|
version: {{ .Values.example.version }}
|
||||||
|
chart: stable/example
|
||||||
|
- name: example-external
|
||||||
|
version: 1.0.0
|
||||||
|
chart: {{ .Values.example.repository }}
|
||||||
|
- name: example-internal
|
||||||
|
version: 1.0.0
|
||||||
|
chart: stable/example
|
||||||
|
`;
|
||||||
|
const fileName = 'helmfile.yaml';
|
||||||
|
const result = extractPackageFile(content, fileName, {
|
||||||
|
aliases: {
|
||||||
|
stable: 'https://charts.helm.sh/stable',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
datasource: 'helm',
|
||||||
|
deps: [
|
||||||
|
{
|
||||||
|
skipReason: 'invalid-version',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipReason: 'invalid-name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
currentValue: '1.0.0',
|
||||||
|
depName: 'example',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses and replaces templating strings', () => {
|
||||||
|
const filename = 'helmfile.yaml';
|
||||||
|
const result = extractPackageFile(
|
||||||
|
Fixtures.get('go-template.yaml'),
|
||||||
|
filename,
|
||||||
|
{
|
||||||
|
aliases: {
|
||||||
|
stable: 'https://charts.helm.sh/stable',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
datasource: 'helm',
|
||||||
|
deps: [
|
||||||
|
{
|
||||||
|
depName: '{{ requiredEnv "RELEASE_NAME" }}',
|
||||||
|
skipReason: 'local-chart',
|
||||||
|
},
|
||||||
|
{ depName: null, skipReason: 'local-chart' },
|
||||||
|
{
|
||||||
|
depName: 'ingress-nginx',
|
||||||
|
currentValue: '3.37.0',
|
||||||
|
registryUrls: [],
|
||||||
|
skipReason: 'unknown-registry',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
depName: 'memcached',
|
||||||
|
currentValue: '6.0.0',
|
||||||
|
registryUrls: ['https://charts.bitnami.com/bitnami'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
depName: 'example',
|
||||||
|
currentValue: '1.30.0',
|
||||||
|
registryUrls: ['https://charts.helm.sh/stable'],
|
||||||
|
},
|
||||||
|
{ depName: 'kube-prometheus-stack', skipReason: 'invalid-version' },
|
||||||
|
{ depName: 'example-external', skipReason: 'invalid-name' },
|
||||||
|
{
|
||||||
|
depName: 'external-dns',
|
||||||
|
currentValue: '2.0.0',
|
||||||
|
registryUrls: ['https://charts.helm.sh/stable'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,11 @@ import type { Doc } from './types';
|
||||||
const isValidChartName = (name: string | undefined): boolean =>
|
const isValidChartName = (name: string | undefined): boolean =>
|
||||||
!!name && !regEx(/[!@#$%^&*(),.?":{}/|<>A-Z]/).test(name);
|
!!name && !regEx(/[!@#$%^&*(),.?":{}/|<>A-Z]/).test(name);
|
||||||
|
|
||||||
|
function extractYaml(content: string): string {
|
||||||
|
// regex remove go templated ({{ . }}) values
|
||||||
|
return content.replace(/(^|:)\s*{{.+}}\s*$/gm, '$1');
|
||||||
|
}
|
||||||
|
|
||||||
export function extractPackageFile(
|
export function extractPackageFile(
|
||||||
content: string,
|
content: string,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
|
@ -18,7 +23,7 @@ export function extractPackageFile(
|
||||||
let docs: Doc[];
|
let docs: Doc[];
|
||||||
const aliases: Record<string, string> = {};
|
const aliases: Record<string, string> = {};
|
||||||
try {
|
try {
|
||||||
docs = loadAll(content, null, { json: true }) as Doc[];
|
docs = loadAll(extractYaml(content), null, { json: true }) as Doc[];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.debug({ err, fileName }, 'Failed to parse helmfile helmfile.yaml');
|
logger.debug({ err, fileName }, 'Failed to parse helmfile helmfile.yaml');
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue