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(flux): support kustomization #29224

Merged
merged 5 commits into from
May 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/modules/manager/flux/__fixtures__/kustomize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo
namespace: flux-system
spec:
images:
- name: podinfo
newName: my-registry/podinfo
newTag: v1
- name: podinfo
newTag: 1.8.0
- name: podinfo
newName: my-podinfo
- name: podinfo
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
62 changes: 62 additions & 0 deletions lib/modules/manager/flux/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,68 @@ describe('modules/manager/flux/extract', () => {
});
});

it('extracts Kustomization', () => {
const result = extractPackageFile(
codeBlock`
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo
namespace: flux-system
spec:
images:
- name: podinfo
newName: my-registry/podinfo
newTag: v1
- name: podinfo
newTag: 1.8.0
- name: podinfo
newName: my-podinfo
- name: podinfo
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
`,
'test.yaml',
);
expect(result).toEqual({
deps: [
{
autoReplaceStringTemplate:
'{{newValue}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: 'v1',
datasource: 'docker',
depName: 'my-registry/podinfo',
replaceString: 'v1',
},
{
autoReplaceStringTemplate:
'{{newValue}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: '1.8.0',
datasource: 'docker',
depName: 'podinfo',
replaceString: '1.8.0',
},
{
currentDigest: undefined,
currentValue: undefined,
datasource: 'docker',
depName: 'my-podinfo',
replaceString: 'my-podinfo',
},
{
currentDigest:
'sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3',
currentValue: undefined,
datasource: 'docker',
depName: 'podinfo',
replaceString:
'sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3',
},
],
});
});

it('ignores resources of an unknown kind', () => {
const result = extractPackageFile(
codeBlock`
Expand Down
11 changes: 11 additions & 0 deletions lib/modules/manager/flux/extract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { coerceArray } from '../../../util/array';
import { readLocalFile } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import { parseYaml } from '../../../util/yaml';
Expand All @@ -13,6 +14,7 @@ import { GitlabTagsDatasource } from '../../datasource/gitlab-tags';
import { HelmDatasource } from '../../datasource/helm';
import { getDep } from '../dockerfile/extract';
import { isOCIRegistry, removeOCIPrefix } from '../helmv3/oci';
import { extractImage } from '../kustomize/extract';
import type {
ExtractConfig,
PackageDependency,
Expand Down Expand Up @@ -226,6 +228,15 @@ function resolveResourceManifest(
deps.push(dep);
break;
}

case 'Kustomization': {
for (const image of coerceArray(resource.spec.images)) {
const dep = extractImage(image, registryAliases);
if (dep) {
deps.push(dep);
}
}
}
}
}
return deps;
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/flux/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Renovate can update `git` references from `GitRepository` resources.

The `flux` manager only updates `GitRepository` fields that have a `tag` or `commit` key.

### Kustomization support

Renovate can update `image`[^1] references from `Kustomization` resources.

### OCIRepository support

Renovate can update `oci` references from `OCIRepository` resources.
Expand Down Expand Up @@ -81,3 +85,5 @@ If instead you have all your Flux manifests inside a `flux/` directory, you woul
### Versioning

If you need to change the versioning format, read the [versioning](../../versioning/index.md) documentation to learn more.

[^1]: <https://fluxcd.io/flux/components/kustomize/kustomizations/#images>
20 changes: 19 additions & 1 deletion lib/modules/manager/flux/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,25 @@ export const OCIRepository = KubernetesResource.extend({
}),
});

export const Kustomization = KubernetesResource.extend({
apiVersion: z.string().startsWith('kustomize.toolkit.fluxcd.io/'),
kind: z.literal('Kustomization'),
spec: z.object({
images: z
.array(
z.object({
name: z.string(),
newName: z.string().optional(),
newTag: z.string().optional(),
digest: z.string().optional(),
}),
)
.optional(),
}),
});

export const FluxResource = HelmRelease.or(HelmRepository)
.or(GitRepository)
.or(OCIRepository);
.or(OCIRepository)
.or(Kustomization);
export type FluxResource = z.infer<typeof FluxResource>;
2 changes: 1 addition & 1 deletion lib/modules/manager/kustomize/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface Image {
name: string;
newTag: string;
newTag?: string;
newName?: string;
digest?: string;
}
Expand Down