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(argocd): support applicationsets #14496

Merged
merged 8 commits into from
Mar 14, 2022
75 changes: 75 additions & 0 deletions lib/modules/manager/argocd/__fixtures__/validApplicationSet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
template:
spec:
source:
chart: kube-state-metrics
repoURL: https://prometheus-community.github.io/helm-charts
targetRevision: 2.4.1
---
# applicationset with helm values
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
template:
spec:
source:
chart: {{ .Values.chart }}
repoURL: {{ .Values.repoUrl}}
targetRevision: {{ .Values.targetRevision }}
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
template:
spec:
source:
chart: traefik
helm:
values: |
traefik:
service:
spec:
loadBalancerIP: 1.2.3.4
repoURL: https://helm.traefik.io/traefik
targetRevision: 10.14.2
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
template:
spec:
source:
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
---
# malformed applicationset as the source section is missing
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
template:
spec:
target:
namespace: testing
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: podinfo
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-podinfo'
spec:
project: default
source:
repoURL: https://stefanprodan.github.io/podinfo
targetRevision: 6.0.0
chart: podinfo
destination:
name: '{{server}}'
namespace: podinfo
37 changes: 37 additions & 0 deletions lib/modules/manager/argocd/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { extractPackageFile } from './extract';
const validApplication = Fixtures.get('validApplication.yml');
const malformedApplication = Fixtures.get('malformedApplications.yml');
const randomManifest = Fixtures.get('randomManifest.yml');
const validApplicationSet = Fixtures.get('validApplicationSet.yml');

describe('modules/manager/argocd/extract', () => {
describe('extractPackageFile()', () => {
Expand All @@ -30,5 +31,41 @@ describe('modules/manager/argocd/extract', () => {
expect(result.deps).toBeArrayOfSize(3);
expect(result.deps).toMatchSnapshot();
});

it('supports applicationsets', () => {
const result = extractPackageFile(
validApplicationSet,
'applicationsets.yml'
);
expect(result).toEqual({
deps: [
{
currentValue: '2.4.1',
datasource: 'helm',
depName: 'kube-state-metrics',
registryUrls: [
'https://prometheus-community.github.io/helm-charts',
],
},
{
currentValue: '10.14.2',
datasource: 'helm',
depName: 'traefik',
registryUrls: ['https://helm.traefik.io/traefik'],
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '6.0.0',
datasource: 'helm',
depName: 'podinfo',
registryUrls: ['https://stefanprodan.github.io/podinfo'],
},
],
});
});
});
});
12 changes: 10 additions & 2 deletions lib/modules/manager/argocd/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { loadAll } from 'js-yaml';
import { GitTagsDatasource } from '../../datasource/git-tags';
import { HelmDatasource } from '../../datasource/helm';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import type { ApplicationDefinition } from './types';
import type { ApplicationDefinition, ApplicationSource } from './types';
import { fileTestRegex } from './util';

function createDependency(
definition: ApplicationDefinition
): PackageDependency {
const source = definition?.spec?.source;
let source: ApplicationSource;
switch (definition.kind) {
case 'Application':
source = definition?.spec?.source;
break;
case 'ApplicationSet':
source = definition?.spec?.template?.spec?.source;
break;
}

if (
!source ||
Expand Down
30 changes: 25 additions & 5 deletions lib/modules/manager/argocd/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
export interface ApplicationDefinition {
export interface KubernetesResource {
apiVersion: string;
}

export interface ApplicationSource {
chart?: string;
repoURL: string;
targetRevision: string;
}

export interface Application extends KubernetesResource {
kind: 'Application';
spec: {
source: ApplicationSource;
};
}

export interface ApplicationSet extends KubernetesResource {
kind: 'ApplicationSet';
spec: {
source: {
chart?: string;
repoURL: string;
targetRevision: string;
template: {
spec: {
source: ApplicationSource;
};
};
};
}

export type ApplicationDefinition = Application | ApplicationSet;