Skip to content

Commit

Permalink
feat(argocd): support applicationsets (#14496)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
3 people committed Mar 14, 2022
1 parent 72acc8b commit b90584c
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 7 deletions.
75 changes: 75 additions & 0 deletions lib/modules/manager/argocd/__fixtures__/validApplicationSet.yml
@@ -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
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
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
@@ -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;

0 comments on commit b90584c

Please sign in to comment.