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: add support for git refs for vendir #28084

Merged
merged 14 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/modules/manager/vendir/__fixtures__/invalid-vendir.yaml
@@ -0,0 +1,12 @@
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: vendor
contents:
- path: github.com/cloudfoundry/cf-k8s-networking
test:
# http or ssh urls are supported (required)
url: https://github.com/cloudfoundry/cf-k8s-networking
# branch, tag, commit; origin is the name of the remote (required)
# optional if refSelection is specified (available in v0.11.0+)
ref: origin/master
5 changes: 5 additions & 0 deletions lib/modules/manager/vendir/__fixtures__/valid-contents.yaml
Expand Up @@ -31,3 +31,8 @@ directories:
version: "7.10.1"
repository:
url: oci://test
# Normal Git Repo
- path: custom-repo-custom-version
git:
url: https://github.com/test/test
ref: "7.10.1"
38 changes: 38 additions & 0 deletions lib/modules/manager/vendir/__fixtures__/valid-vendir.yaml
@@ -0,0 +1,38 @@
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: vendor
contents:
# Normal Helm Chart
- path: custom-repo-custom-version
helmChart:
name: contour
version: "7.10.1"
repository:
url: https://charts.bitnami.com/bitnami
# Normal Helm Chart 2 for handling lists
- path: thing
helmChart:
name: test
version: "7.10.1"
repository:
url: https://charts.bitnami.com/bitnami
# Normal Git Repo
- path: custom-repo-custom-version
git:
url: https://github.com/test/test
ref: "7.10.1"
# OCI Helm Chart
- path: custom-repo-custom-version
helmChart:
name: contour
version: "7.10.1"
repository:
url: oci://charts.bitnami.com/bitnami
# Aliased OCI Helm Chart
- path: custom-repo-custom-version
helmChart:
name: oci
version: "7.10.1"
repository:
url: oci://test
1 change: 0 additions & 1 deletion lib/modules/manager/vendir/artifacts.spec.ts
Expand Up @@ -462,7 +462,6 @@ describe('modules/manager/vendir/artifacts', () => {
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile1);
fs.getSiblingFileName.mockReturnValueOnce('vendir.lock.yml');
fs.readLocalFile.mockResolvedValueOnce(vendirLockFile2);
fs.readLocalFile.mockResolvedValueOnce('0.35.0');
knechtionscoding marked this conversation as resolved.
Show resolved Hide resolved
const execSnapshots = mockExecAll();
fs.privateCacheDir.mockReturnValue(
'/tmp/renovate/cache/__renovate-private-cache',
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/vendir/extract.spec.ts
Expand Up @@ -72,6 +72,12 @@ describe('modules/manager/vendir/extract', () => {
packageName: 'quay.example.com/organization/aliased-oci-chart',
pinDigests: false,
},
{
currentValue: '7.10.1',
depName: 'https://github.com/test/test',
packageName: 'https://github.com/test/test',
datasource: 'git-refs',
},
],
});
});
Expand Down
41 changes: 34 additions & 7 deletions lib/modules/manager/vendir/extract.ts
@@ -1,5 +1,7 @@
import { logger } from '../../../logger';
import { getHttpUrl } from '../../../util/git/url';
import { parseSingleYaml } from '../../../util/yaml';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { HelmDatasource } from '../../datasource/helm';
import { getDep } from '../dockerfile/extract';
import { isOCIRegistry } from '../helmv3/utils';
Expand All @@ -8,7 +10,12 @@ import type {
PackageDependency,
PackageFileContent,
} from '../types';
import { HelmChartDefinition, Vendir, VendirDefinition } from './schema';
import {
GitRefDefinition,
HelmChartDefinition,
Vendir,
VendirDefinition,
} from './schema';

// TODO: Add support for other vendir types (like git tags, github releases, etc.)
// Recommend looking at the kustomize manager for more information on support.
Expand All @@ -27,6 +34,7 @@ export function extractHelmChart(
...dep,
depName: helmChart.name,
packageName: dep.depName,
depType: 'HelmChart',
// https://github.com/helm/helm/issues/10312
// https://github.com/helm/helm/issues/10678
pinDigests: false,
Expand All @@ -35,11 +43,26 @@ export function extractHelmChart(
return {
depName: helmChart.name,
currentValue: helmChart.version,
depType: 'HelmChart',
registryUrls: [helmChart.repository.url],
datasource: HelmDatasource.id,
};
}

export function extractGitSource(
gitSource: GitRefDefinition,
): PackageDependency | null {
const httpUrl = getHttpUrl(gitSource.url);
return {
depName: httpUrl,
packageName: httpUrl,
depType: 'GitSource',
currentValue: gitSource.ref,
registryUrls: [httpUrl],
datasource: GitRefsDatasource.id,
};
}

export function parseVendir(
content: string,
packageFile?: string,
Expand Down Expand Up @@ -71,12 +94,16 @@ export function extractPackageFile(
// grab the helm charts
const contents = pkg.directories.flatMap((directory) => directory.contents);
for (const content of contents) {
const dep = extractHelmChart(content.helmChart, config.registryAliases);
if (dep) {
deps.push({
...dep,
depType: 'HelmChart',
});
if ('helmChart' in content && content.helmChart) {
const dep = extractHelmChart(content.helmChart, config.registryAliases);
if (dep) {
deps.push(dep);
}
} else if ('git' in content && content.git) {
const dep = extractGitSource(content.git);
if (dep) {
deps.push(dep);
}
}
}

Expand Down
30 changes: 28 additions & 2 deletions lib/modules/manager/vendir/readme.md
@@ -1,8 +1,10 @@
Renovate supports updating Helm Chart references in vendir.yml via the [vendir](https://carvel.dev/vendir/) tool. Renovate requires the presence of a [vendir lock file](https://carvel.dev/vendir/docs/v0.40.x/vendir-lock-spec/) which is generated by vendir and should be stored in source code.
Renovate supports updating Helm Chart references and git references in vendir.yml via the [vendir](https://carvel.dev/vendir/) tool. Renovate requires the presence of a [vendir lock file](https://carvel.dev/vendir/docs/v0.40.x/vendir-lock-spec/) which is generated by vendir and should be stored in source code.

### Helm Charts

It supports both https and oci helm chart repositories.

```yaml title="Example vendir.yml"
```yaml title="Example helm chart vendir.yml"
apiVersion: vendir.k14s.io/v1alpha1
kind: Config

Expand Down Expand Up @@ -32,3 +34,27 @@ directories:
#### OCI

Aliases for OCI registries are supported via the dockerfile/docker manager

### Git

Renovates supporting explicit refs in for git references in vendir.yml

```yaml title="Example git vendir.yml"
apiVersion: vendir.k14s.io/v1alpha1
kind: Config

# one or more directories to manage with vendir
directories:
- path: config/_ytt_lib
contents:
path: github.com/cloudfoundry/cf-k8s-networking
git:
# http or ssh urls are supported (required)
url: https://github.com/cloudfoundry/cf-k8s-networking
# branch, tag, commit; origin is the name of the remote (required)
# optional if refSelection is specified (available in v0.11.0+)
ref: origin/master
# depth of commits to fetch; 0 (default) means everything (optional; v0.29.0+)
depth: 1
...
```
16 changes: 15 additions & 1 deletion lib/modules/manager/vendir/schema.ts
Expand Up @@ -6,6 +6,12 @@ export const VendirResource = z.object({
kind: z.literal('Config'),
});

export const GitRef = z.object({
ref: z.string(),
url: z.string().regex(/^(?:ssh|https?):\/\/.+/),
depth: z.number().optional(),
});

export const HelmChart = z.object({
name: z.string(),
version: z.string(),
Expand All @@ -14,11 +20,18 @@ export const HelmChart = z.object({
}),
});

export const Contents = z.object({
export const HelmChartContent = z.object({
path: z.string(),
helmChart: HelmChart,
});

export const GitRefContent = z.object({
path: z.string(),
git: GitRef,
});

export const Contents = z.union([HelmChartContent, GitRefContent]);

export const Vendir = VendirResource.extend({
directories: z.array(
z.object({
Expand All @@ -30,3 +43,4 @@ export const Vendir = VendirResource.extend({

export type VendirDefinition = z.infer<typeof Vendir>;
export type HelmChartDefinition = z.infer<typeof HelmChart>;
export type GitRefDefinition = z.infer<typeof GitRef>;