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/kustomize): support HelmChartInflationGenerator #12628

Merged
merged 18 commits into from Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions lib/manager/kustomize/__fixtures__/kustomizeHelmChart.yaml
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

helmCharts:
- name: minecraft
includeCRDs: false
valuesInline:
minecraftServer:
eula: true
difficulty: hard
rcon:
enabled: true
releaseName: moria
version: 3.1.3
repo: https://itzg.github.io/minecraft-server-charts
38 changes: 38 additions & 0 deletions lib/manager/kustomize/extract.spec.ts
Expand Up @@ -2,9 +2,11 @@ import { loadFixture } from '../../../test/util';
import * as datasourceDocker from '../../datasource/docker';
import { GitTagsDatasource } from '../../datasource/git-tags';
import * as datasourceGitHubTags from '../../datasource/github-tags';
import { HelmDatasource } from '../../datasource/helm';
import { SkipReason } from '../../types';
import {
extractBase,
extractHelmChart,
extractImage,
extractPackageFile,
parseKustomize,
Expand All @@ -22,6 +24,7 @@ const kustomizeComponent = loadFixture('component.yaml');
const newTag = loadFixture('newTag.yaml');
const newName = loadFixture('newName.yaml');
const digest = loadFixture('digest.yaml');
const kustomizeHelmChart = loadFixture('kustomizeHelmChart.yaml');

describe('manager/kustomize/extract', () => {
it('should successfully parse a valid kustomize file', () => {
Expand Down Expand Up @@ -119,6 +122,31 @@ describe('manager/kustomize/extract', () => {
expect(pkg).toEqual(sample);
});
});
describe('extractHelmChart', () => {
it('should return null on a null input', () => {
const pkg = extractHelmChart({
name: null,
repo: null,
version: null,
});
expect(pkg).toBeNull();
});
it('should correctly extract a chart', () => {
const registryUrl = 'https://docs.renovatebot.com/helm-charts';
const sample = {
depName: 'renovate',
currentValue: '29.6.0',
registryUrls: [registryUrl],
datasource: HelmDatasource.id,
};
const pkg = extractHelmChart({
name: sample.depName,
version: sample.currentValue,
repo: registryUrl,
});
expect(pkg).toEqual(sample);
});
});
describe('image extraction', () => {
it('should return null on a null input', () => {
const pkg = extractImage({
Expand Down Expand Up @@ -344,5 +372,15 @@ describe('manager/kustomize/extract', () => {
],
});
});

it('parses helmChart field', () => {
const res = extractPackageFile(kustomizeHelmChart);
expect(res.deps[0].depType).toBe('HelmChart');
expect(res.deps[0].depName).toBe('minecraft');
expect(res.deps[0].currentValue).toBe('3.1.3');
expect(res.deps[0].registryUrls).toStrictEqual([
'https://itzg.github.io/minecraft-server-charts',
]);
andrein marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
32 changes: 30 additions & 2 deletions lib/manager/kustomize/extract.ts
Expand Up @@ -3,12 +3,13 @@ import { load } from 'js-yaml';
import * as datasourceDocker from '../../datasource/docker';
import { GitTagsDatasource } from '../../datasource/git-tags';
import * as datasourceGitHubTags from '../../datasource/github-tags';
import { HelmDatasource } from '../../datasource/helm';
import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { regEx } from '../../util/regex';
import { splitImageParts } from '../dockerfile/extract';
import type { PackageDependency, PackageFile } from '../types';
import type { Image, Kustomize } from './types';
import type { HelmChart, Image, Kustomize } from './types';

// URL specifications should follow the hashicorp URL format
// https://github.com/hashicorp/go-getter#url-format
Expand Down Expand Up @@ -106,6 +107,22 @@ export function extractImage(image: Image): PackageDependency | null {
return null;
}

export function extractHelmChart(
helmChart: HelmChart
): PackageDependency | null {
if (!helmChart.name) {
return null;
}

const dep: PackageDependency = {
depName: helmChart.name,
currentValue: helmChart.version,
registryUrls: [helmChart.repo],
datasource: HelmDatasource.id,
};
return dep;
}

export function parseKustomize(content: string): Kustomize | null {
let pkg = null;
try {
Expand All @@ -127,7 +144,7 @@ export function parseKustomize(content: string): Kustomize | null {
pkg.components || []
);
pkg.images = pkg.images || [];

pkg.helmCharts = pkg.helmCharts || [];
andrein marked this conversation as resolved.
Show resolved Hide resolved
return pkg;
}

Expand Down Expand Up @@ -162,6 +179,17 @@ export function extractPackageFile(content: string): PackageFile | null {
}
}

// grab the helm charts
for (const helmChart of pkg.helmCharts) {
andrein marked this conversation as resolved.
Show resolved Hide resolved
const dep = extractHelmChart(helmChart);
if (dep) {
deps.push({
...dep,
depType: 'HelmChart',
});
}
}

if (!deps.length) {
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/manager/kustomize/types.ts
Expand Up @@ -4,8 +4,16 @@ export interface Image {
newName?: string;
digest?: string;
}

export interface HelmChart {
name: string;
repo: string;
version: string;
}

export interface Kustomize {
kind: string;
bases: string[];
images: Image[];
helmCharts: HelmChart[];
andrein marked this conversation as resolved.
Show resolved Hide resolved
}