Skip to content

fix(import): aggregate CRD imports from same API group#3798

Open
mateo-moon wants to merge 1 commit intocdk8s-team:2.xfrom
mateo-moon:fix/aggregate-crd-imports-by-api-group
Open

fix(import): aggregate CRD imports from same API group#3798
mateo-moon wants to merge 1 commit intocdk8s-team:2.xfrom
mateo-moon:fix/aggregate-crd-imports-by-api-group

Conversation

@mateo-moon
Copy link

Summary

This PR fixes an issue where importing multiple CRD files from the same Kubernetes API group would cause earlier imports to be overwritten by later ones.

The Problem

When importing multiple CRD files from the same API group (e.g., compute.gcp.upbound.io) using separate entries:

imports:
  - https://example.com/compute.gcp.upbound.io_networks.yaml
  - https://example.com/compute.gcp.upbound.io_subnetworks.yaml

Only Subnetwork (from the second import) would be available in the generated module. The Network class from the first import was overwritten.

The Solution

  • Aggregate all unprefixed CRD imports before processing
  • Download all manifests and combine them with YAML document separators (---)
  • Process combined manifest as a single ImportCustomResourceDefinition
  • CRD imports with moduleNamePrefix are still processed individually (preserves user intent)

Changes

  • src/import/dispatch.ts: Added categorizeImports() function to group imports by type, then process unprefixed CRDs together
  • src/import/crd.ts: Added fromSpecs() and fromManifest() static methods
  • test/import/import-crd.test.ts: Added 3 test cases for the aggregation behavior
  • test/import/fixtures/: Added test fixture files for same-group CRD testing

Use Case

This is especially important when importing Crossplane provider CRDs, where each managed resource type is in its own CRD file but shares the same API group.

Fixes #3797


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

When importing multiple CRD files from the same Kubernetes API group
(e.g., `compute.gcp.upbound.io`) using separate entries in `cdk8s.yaml`,
all CRDs should be consolidated into a single module. Previously, each
import was processed independently, causing later imports to overwrite
earlier ones from the same API group.

This change aggregates all unprefixed CRD imports, downloads all their
manifests, combines them with YAML document separators, and processes
them together. This ensures CRDs from the same API group are properly
consolidated regardless of whether they come from the same file or
different files/URLs.

CRD imports with a `moduleNamePrefix` continue to be processed
individually to preserve the user's intent for separate modules.

Fixes cdk8s-team#3797

Signed-off-by: OP <op@cicd.ninja>
auto-merge was automatically disabled February 3, 2026 01:19

Head branch was pushed to by a user without write access

@mateo-moon mateo-moon force-pushed the fix/aggregate-crd-imports-by-api-group branch from c80f2b5 to a43bb74 Compare February 3, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple CRD imports from same API group overwrite each other

1 participant