Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(argocd): implement manager (#9771)
- Loading branch information
Showing
11 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# malformed application as the source section is missing | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
spec: | ||
target: | ||
namespace: testing | ||
--- | ||
# malformed application as the source section is missing | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
labels: | ||
app: nginx | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
spec: | ||
source: | ||
chart: kube-state-metrics | ||
repoURL: https://prometheus-community.github.io/helm-charts | ||
targetRevision: 2.4.1 | ||
--- | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
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: Application | ||
spec: | ||
source: | ||
repoURL: https://git.example.com/foo/bar.git | ||
targetRevision: v1.2.0 | ||
--- | ||
# malformed application as the source section is missing | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
spec: | ||
target: | ||
namespace: testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`manager/argocd/extract extractPackageFile() full test 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", | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getName, loadFixture } from '../../../test/util'; | ||
import { extractPackageFile } from './extract'; | ||
|
||
const validApplication = loadFixture('validApplication.yml'); | ||
const malformedApplication = loadFixture('malformedApplications.yml'); | ||
const randomManifest = loadFixture('randomManifest.yml'); | ||
|
||
describe(getName(), () => { | ||
describe('extractPackageFile()', () => { | ||
it('returns null for empty', () => { | ||
expect(extractPackageFile('nothing here', 'applications.yml')).toBeNull(); | ||
}); | ||
|
||
it('return null for kubernetes manifest', () => { | ||
const result = extractPackageFile(randomManifest, 'applications.yml'); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('return null if deps array would be empty', () => { | ||
const result = extractPackageFile( | ||
malformedApplication, | ||
'applications.yml' | ||
); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('full test', () => { | ||
const result = extractPackageFile(validApplication, 'applications.yml'); | ||
expect(result).not.toBeNull(); | ||
expect(result.deps).toBeArrayOfSize(3); | ||
expect(result.deps).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { safeLoadAll } from 'js-yaml'; | ||
import * as gitTags from '../../datasource/git-tags'; | ||
import * as helm from '../../datasource/helm'; | ||
import type { ExtractConfig, PackageDependency, PackageFile } from '../types'; | ||
import type { ApplicationDefinition } from './types'; | ||
import { fileTestRegex } from './util'; | ||
|
||
function createDependency( | ||
definition: ApplicationDefinition | ||
): PackageDependency { | ||
const source = definition.spec?.source; | ||
|
||
if (source == null) { | ||
return null; | ||
} | ||
|
||
// a chart variable is defined this is helm declaration | ||
if (source.chart) { | ||
return { | ||
depName: source.chart, | ||
registryUrls: [source.repoURL], | ||
currentValue: source.targetRevision, | ||
datasource: helm.id, | ||
}; | ||
} | ||
return { | ||
depName: source.repoURL, | ||
currentValue: source.targetRevision, | ||
datasource: gitTags.id, | ||
}; | ||
} | ||
|
||
export function extractPackageFile( | ||
content: string, | ||
fileName: string, | ||
config?: ExtractConfig | ||
): PackageFile | null { | ||
// check for argo reference. API version for the kind attribute is used | ||
if (fileTestRegex.test(content) === false) { | ||
return null; | ||
} | ||
|
||
const definitions: ApplicationDefinition[] = safeLoadAll(content); | ||
|
||
const deps = definitions | ||
.map((definition) => createDependency(definition)) | ||
.filter(Boolean); | ||
|
||
return deps.length ? { deps } : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { extractPackageFile } from './extract'; | ||
|
||
export const defaultConfig = { | ||
fileMatch: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
The `argocd` manager has no `fileMatch` default patterns, so it won't match any files until you configure it with a pattern. This is because there is no commonly accepted file/directory naming convention for argocd YAML files and we don't want to check every single `*.yaml` file in repositories just in case any of them contain ArgoCD definitions. | ||
|
||
If most `.yaml` files in your repository are argocd ones, then you could add this to your config: | ||
|
||
```json | ||
{ | ||
"argocd": { | ||
"fileMatch": ["\\.yaml$"] | ||
} | ||
} | ||
``` | ||
|
||
If instead you have them all inside a `argocd/` directory, you would add this: | ||
|
||
```json | ||
{ | ||
"argocd": { | ||
"fileMatch": ["argocd/.+\\.yaml$"] | ||
} | ||
} | ||
``` | ||
|
||
Or if it's just a single file then something like this: | ||
|
||
```json | ||
{ | ||
"argocd": { | ||
"fileMatch": ["^config/applications\\.yaml$"] | ||
} | ||
} | ||
``` | ||
|
||
If you need to change the versioning format, read the [versioning](https://docs.renovatebot.com/modules/versioning/) documentation to learn more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface ApplicationDefinition { | ||
spec: { | ||
source: { | ||
chart?: string; | ||
repoURL: string; | ||
targetRevision: string; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const keyValueExtractionRegex = /^\s*(?<key>[^\s]+):\s+"?(?<value>[^"\s]+)"?\s*$/; | ||
// looks for `apiVersion: argoproj.io/ | ||
export const fileTestRegex = /\s*apiVersion:\s*argoproj.io\/\s*/; |