From 808855f262a770041405adf5764509f42ba39a63 Mon Sep 17 00:00:00 2001 From: Alexander Backlund Date: Thu, 3 Mar 2022 14:34:35 +0000 Subject: [PATCH 1/5] feat(argocd): support applicationsets --- .../__fixtures__/validApplicationSet.yml | 75 +++++++++++++++++++ .../argocd/__snapshots__/extract.spec.ts.snap | 34 +++++++++ lib/manager/argocd/extract.spec.ts | 11 +++ lib/manager/argocd/extract.ts | 12 ++- lib/manager/argocd/types.ts | 30 ++++++-- 5 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 lib/manager/argocd/__fixtures__/validApplicationSet.yml diff --git a/lib/manager/argocd/__fixtures__/validApplicationSet.yml b/lib/manager/argocd/__fixtures__/validApplicationSet.yml new file mode 100644 index 00000000000000..8103f266a3225b --- /dev/null +++ b/lib/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: gs://helm-charts-internal + targetRevision: 0.0.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 diff --git a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap index c5c2f9abf557f0..ab8d2b8a51ddb5 100644 --- a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap @@ -25,3 +25,37 @@ Array [ }, ] `; + +exports[`manager/argocd/extract extractPackageFile() supports applicationsets 1`] = ` +Array [ + Object { + "currentValue": "2.4.1", + "datasource": "helm", + "depName": "kube-state-metrics", + "registryUrls": Array [ + "https://prometheus-community.github.io/helm-charts", + ], + }, + Object { + "currentValue": "0.0.2", + "datasource": "helm", + "depName": "traefik", + "registryUrls": Array [ + "gs://helm-charts-internal", + ], + }, + Object { + "currentValue": "v1.2.0", + "datasource": "git-tags", + "depName": "https://git.example.com/foo/bar.git", + }, + Object { + "currentValue": "6.0.0", + "datasource": "helm", + "depName": "podinfo", + "registryUrls": Array [ + "https://stefanprodan.github.io/podinfo", + ], + }, +] +`; diff --git a/lib/manager/argocd/extract.spec.ts b/lib/manager/argocd/extract.spec.ts index 86c1eaec1ff9e4..ef3c0035adbb64 100644 --- a/lib/manager/argocd/extract.spec.ts +++ b/lib/manager/argocd/extract.spec.ts @@ -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('manager/argocd/extract', () => { describe('extractPackageFile()', () => { @@ -30,5 +31,15 @@ describe('manager/argocd/extract', () => { expect(result.deps).toBeArrayOfSize(3); expect(result.deps).toMatchSnapshot(); }); + + it('supports applicationsets', () => { + const result = extractPackageFile( + validApplicationSet, + 'applicationsets.yml' + ); + expect(result).not.toBeNull(); + expect(result.deps).toBeArrayOfSize(4); + expect(result.deps).toMatchSnapshot(); + }); }); }); diff --git a/lib/manager/argocd/extract.ts b/lib/manager/argocd/extract.ts index b4b0839fc2260f..06d8fb796a4a6b 100644 --- a/lib/manager/argocd/extract.ts +++ b/lib/manager/argocd/extract.ts @@ -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 || diff --git a/lib/manager/argocd/types.ts b/lib/manager/argocd/types.ts index 8a84291575d077..95420e8c0fd59f 100644 --- a/lib/manager/argocd/types.ts +++ b/lib/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; From 985101d4f02afc944aeb7da9b4ae4541036595b3 Mon Sep 17 00:00:00 2001 From: Alexander Backlund Date: Thu, 3 Mar 2022 15:14:40 +0000 Subject: [PATCH 2/5] fixup! feat(argocd): support applicationsets --- lib/manager/argocd/__fixtures__/validApplicationSet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/manager/argocd/__fixtures__/validApplicationSet.yml b/lib/manager/argocd/__fixtures__/validApplicationSet.yml index 8103f266a3225b..e17a7e7bdc7fc7 100644 --- a/lib/manager/argocd/__fixtures__/validApplicationSet.yml +++ b/lib/manager/argocd/__fixtures__/validApplicationSet.yml @@ -33,8 +33,8 @@ spec: service: spec: loadBalancerIP: 1.2.3.4 - repoURL: gs://helm-charts-internal - targetRevision: 0.0.2 + repoURL: https://helm.traefik.io/traefik + targetRevision: 10.14.2 --- apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet From fd3687bf14de12b6bfac953ec5a062a55be30373 Mon Sep 17 00:00:00 2001 From: Alexander Backlund Date: Thu, 3 Mar 2022 15:20:18 +0000 Subject: [PATCH 3/5] fixup! feat(argocd): support applicationsets --- lib/manager/argocd/__snapshots__/extract.spec.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap index ab8d2b8a51ddb5..a6f176db6306b1 100644 --- a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap @@ -37,11 +37,11 @@ Array [ ], }, Object { - "currentValue": "0.0.2", + "currentValue": "10.14.2", "datasource": "helm", "depName": "traefik", "registryUrls": Array [ - "gs://helm-charts-internal", + "https://helm.traefik.io/traefik", ], }, Object { From d31165f1680d12cf721a37849174973f3bf24b7f Mon Sep 17 00:00:00 2001 From: Alexander Backlund Date: Thu, 3 Mar 2022 16:00:33 +0000 Subject: [PATCH 4/5] fixup! feat(argocd): support applicationsets --- .../argocd/__snapshots__/extract.spec.ts.snap | 34 ------------------- lib/manager/argocd/extract.spec.ts | 32 +++++++++++++++-- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap index a6f176db6306b1..c5c2f9abf557f0 100644 --- a/lib/manager/argocd/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/argocd/__snapshots__/extract.spec.ts.snap @@ -25,37 +25,3 @@ Array [ }, ] `; - -exports[`manager/argocd/extract extractPackageFile() supports applicationsets 1`] = ` -Array [ - Object { - "currentValue": "2.4.1", - "datasource": "helm", - "depName": "kube-state-metrics", - "registryUrls": Array [ - "https://prometheus-community.github.io/helm-charts", - ], - }, - Object { - "currentValue": "10.14.2", - "datasource": "helm", - "depName": "traefik", - "registryUrls": Array [ - "https://helm.traefik.io/traefik", - ], - }, - Object { - "currentValue": "v1.2.0", - "datasource": "git-tags", - "depName": "https://git.example.com/foo/bar.git", - }, - Object { - "currentValue": "6.0.0", - "datasource": "helm", - "depName": "podinfo", - "registryUrls": Array [ - "https://stefanprodan.github.io/podinfo", - ], - }, -] -`; diff --git a/lib/manager/argocd/extract.spec.ts b/lib/manager/argocd/extract.spec.ts index ef3c0035adbb64..efe46b1d6a72fb 100644 --- a/lib/manager/argocd/extract.spec.ts +++ b/lib/manager/argocd/extract.spec.ts @@ -37,9 +37,35 @@ describe('manager/argocd/extract', () => { validApplicationSet, 'applicationsets.yml' ); - expect(result).not.toBeNull(); - expect(result.deps).toBeArrayOfSize(4); - expect(result.deps).toMatchSnapshot(); + 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'], + }, + ], + }); }); }); }); From 675c8acfc9a857a7c2adf1a212dbf502e20c33b1 Mon Sep 17 00:00:00 2001 From: Alexander Backlund Date: Fri, 4 Mar 2022 10:30:15 +0000 Subject: [PATCH 5/5] fixup! feat(argocd): support applicationsets --- .../manager/argocd/__fixtures__/validApplicationSet.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{ => modules}/manager/argocd/__fixtures__/validApplicationSet.yml (100%) diff --git a/lib/manager/argocd/__fixtures__/validApplicationSet.yml b/lib/modules/manager/argocd/__fixtures__/validApplicationSet.yml similarity index 100% rename from lib/manager/argocd/__fixtures__/validApplicationSet.yml rename to lib/modules/manager/argocd/__fixtures__/validApplicationSet.yml