refactor: collapse duplicate XPCommonAPIs constants and simplify crd_types template alias scheme
- Dominant language
- Go
- Stars
- 481
- Forks
- 131
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 11
Description
### Background
PR #664 migrated the common API imports to `github.com/crossplane/crossplane/apis/v2/core/v2`. As part of that migration, two constants in `pkg/types/reference.go` were intentionally kept separate for source-level backward compatibility — but they now hold identical values:
\`\`\`go
// Both resolve to the same package path since crossplane-runtime v2.3.0
PackagePathXPCommonAPIs = "github.com/crossplane/crossplane/apis/v2/core/v2"
PackagePathXPV2CommonAPIs = "github.com/crossplane/crossplane/apis/v2/core/v2"
\`\`\`
`crd_types.go.tmpl` also uses two separate alias template variables (`XPCommonAPIsPackageAlias` / `XPV2CommonAPIsPackageAlias`) that today resolve to the same import, because `typewriter`'s `UsePackage` deduplicates by path.
### Problem
The dual-constant, dual-alias scheme creates an invisible invariant: **both constants must remain identical** or one CRD scope's generated imports will silently diverge without a compile error (until downstream providers regenerate). The naming also implies a distinction between "v1 common APIs" and "v2 common APIs" that no longer exists.
### Proposed fix
1. Introduce a single replacement constant (e.g. `PackagePathXPCoreAPIs`) pointing to `github.com/crossplane/crossplane/apis/v2/core/v2`.
2. Deprecate `PackagePathXPCommonAPIs` and `PackagePathXPV2CommonAPIs` with a `// Deprecated:` comment redirecting to the new name.
3. Update `pkg/pipeline/crd.go` to pass the single constant for both template keys.
4. Simplify `crd_types.go.tmpl` to use one alias variable throughout.
### Severity
**Not urgent — no correctness issue today.** Generated code is correct because `UsePackage` deduplicates by path. The risk is a future maintainer who diverges only one constant and silently breaks one CRD scope's codegen.
Deferred from #664 to keep that PR focused in size.
Contributor guide
Research direction
Start in pkg/types/reference.go to inspect the duplicate constants, then follow their use in pkg/pipeline/crd.go and crd_types.go.tmpl. The work is done when one core API constant and one template alias replace the duplicate wiring, while the old constants remain deprecated with redirects to the new name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100