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/argocd): added support for argocd multisource #20648

Merged
merged 18 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/modules/manager/argocd/__fixtures__/malformedApplications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ spec:
# malformed application as the source section is missing
apiVersion: argoproj.io/v1alpha1
kind: Application
---
# malformed application as the sources array is empty
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
sources: []
---
# malformed application as the source is null
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
source: null
52 changes: 52 additions & 0 deletions lib/modules/manager/argocd/__fixtures__/validApplication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,55 @@ spec:
chart: some/image3
repoURL: somecontainer.registry.io:443/
targetRevision: 1.0.0
---
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
sources:
- chart: some/image3
repoURL: somecontainer.registry.io:443/
targetRevision: 1.0.0
---
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
sources:
- ref: foo
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
- chart: some/image3
repoURL: somecontainer.registry.io:443/
targetRevision: 1.0.0

---
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
sources:
- ref: foo
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
path: bar
- chart: traefik
repoURL: gs://helm-charts-internal
targetRevision: 0.0.2
helm:
valueFiles:
- $foo/values.yaml

---
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
sources:
- ref: foo
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
path: bar
- chart: somechart
repoURL: https://foo.io/repo
targetRevision: 0.0.2
helm:
valueFiles:
- $foo/values.yaml

70 changes: 70 additions & 0 deletions lib/modules/manager/argocd/__fixtures__/validApplicationSet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,73 @@ spec:
destination:
name: '{{server}}'
namespace: podinfo
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: podinfo
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-podinfo'
spec:
project: default
sources:
- chart: some/image3
repoURL: somecontainer.registry.io:443/
targetRevision: 1.0.0
destination:
name: '{{server}}'
namespace: podinfo
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: podinfo
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-podinfo'
spec:
project: default
sources:
- ref: foo
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
- chart: some/image3
repoURL: somecontainer.registry.io:443/
targetRevision: 1.0.0
destination:
name: '{{server}}'
namespace: podinfo
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: podinfo
spec:
generators:
- clusters: {}
template:
metadata:
name: '{{name}}-podinfo'
spec:
project: default
sources:
- ref: foo
repoURL: https://git.example.com/foo/bar.git
targetRevision: v1.2.0
path: bar
- chart: somechart
repoURL: https://foo.io/repo
targetRevision: 0.0.2
helm:
valueFiles:
- $foo/values.yaml
destination:
name: '{{server}}'
namespace: podinfo
63 changes: 63 additions & 0 deletions lib/modules/manager/argocd/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ describe('modules/manager/argocd/extract', () => {
datasource: 'docker',
depName: 'somecontainer.registry.io:443/some/image3',
},
{
currentValue: '1.0.0',
datasource: 'docker',
depName: 'somecontainer.registry.io:443/some/image3',
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '1.0.0',
datasource: 'docker',
depName: 'somecontainer.registry.io:443/some/image3',
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '0.0.2',
datasource: 'helm',
depName: 'traefik',
registryUrls: ['gs://helm-charts-internal'],
piximos marked this conversation as resolved.
Show resolved Hide resolved
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '0.0.2',
datasource: 'helm',
depName: 'somechart',
registryUrls: ['https://foo.io/repo'],
},
],
});
});
Expand Down Expand Up @@ -110,6 +147,32 @@ describe('modules/manager/argocd/extract', () => {
depName: 'podinfo',
registryUrls: ['https://stefanprodan.github.io/podinfo'],
},
{
currentValue: '1.0.0',
datasource: 'docker',
depName: 'somecontainer.registry.io:443/some/image3',
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '1.0.0',
datasource: 'docker',
depName: 'somecontainer.registry.io:443/some/image3',
},
{
currentValue: 'v1.2.0',
datasource: 'git-tags',
depName: 'https://git.example.com/foo/bar.git',
},
{
currentValue: '0.0.2',
datasource: 'helm',
depName: 'somechart',
registryUrls: ['https://foo.io/repo'],
},
],
});
});
Expand Down
77 changes: 46 additions & 31 deletions lib/modules/manager/argocd/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import is from '@sindresorhus/is';
import { loadAll } from 'js-yaml';
import { logger } from '../../../logger';
import { coerceArray } from '../../../util/array';
import { trimTrailingSlash } from '../../../util/url';
import { DockerDatasource } from '../../datasource/docker';
import { GitTagsDatasource } from '../../datasource/git-tags';
Expand All @@ -10,22 +11,37 @@ import type {
PackageDependency,
PackageFileContent,
} from '../types';
import type { ApplicationDefinition, ApplicationSource } from './types';
import type {
ApplicationDefinition,
ApplicationSource,
ApplicationSpec,
} from './types';
import { fileTestRegex } from './util';

function createDependency(
definition: ApplicationDefinition
): PackageDependency | null {
let source: ApplicationSource;
switch (definition.kind) {
case 'Application':
source = definition?.spec?.source;
break;
case 'ApplicationSet':
source = definition?.spec?.template?.spec?.source;
break;
export function extractPackageFile(
content: string,
fileName: string,
_config?: ExtractConfig
): PackageFileContent | null {
// check for argo reference. API version for the kind attribute is used
if (fileTestRegex.test(content) === false) {
return null;
}

let definitions: ApplicationDefinition[];
try {
definitions = loadAll(content) as ApplicationDefinition[];
} catch (err) {
logger.debug({ err, fileName }, 'Failed to parse ArgoCD definition.');
return null;
}

const deps = definitions.filter(is.plainObject).flatMap(processAppSpec);

return deps.length ? { deps } : null;
}

function processSource(source: ApplicationSource): PackageDependency | null {
if (
!source ||
!is.nonEmptyString(source.repoURL) ||
Expand Down Expand Up @@ -66,28 +82,27 @@ function createDependency(
};
}

export function extractPackageFile(
content: string,
fileName: string,
_config?: ExtractConfig
): PackageFileContent | null {
// check for argo reference. API version for the kind attribute is used
if (fileTestRegex.test(content) === false) {
return null;
function processAppSpec(
definition: ApplicationDefinition
): PackageDependency[] {
const spec: ApplicationSpec | null | undefined =
definition.kind === 'Application'
? definition?.spec
: definition?.spec?.template?.spec;

if (is.nullOrUndefined(spec)) {
return [];
}

let definitions: ApplicationDefinition[];
try {
definitions = loadAll(content) as ApplicationDefinition[];
} catch (err) {
logger.debug({ err, fileName }, 'Failed to parse ArgoCD definition.');
return null;
const deps: (PackageDependency | null)[] = [];

if (is.nonEmptyObject(spec.source)) {
deps.push(processSource(spec.source));
}

const deps = definitions
.filter(is.plainObject)
.map((definition) => createDependency(definition))
.filter(is.truthy);
for (const source of coerceArray(spec.sources)) {
deps.push(processSource(source));
}

return deps.length ? { deps } : null;
return deps.filter(is.truthy);
}
13 changes: 7 additions & 6 deletions lib/modules/manager/argocd/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ export interface ApplicationSource {
targetRevision: string;
}

export interface ApplicationSpec {
source?: ApplicationSource;
sources?: ApplicationSource[];
}

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

export interface ApplicationSet extends KubernetesResource {
kind: 'ApplicationSet';
spec: {
template: {
spec: {
source: ApplicationSource;
};
spec: ApplicationSpec;
};
};
}
Expand Down