Skip to content

Add UpdateSchemas to pkg/project and export the dependency subcommands - #560

Merged
haarchri merged 2 commits into
crossplane:mainfrom
haarchri:feat/pkg-project-update-schemas
Nov 19, 2026
Merged

haarchri merged 2 commits into
crossplane:mainfrom
haarchri:feat/pkg-project-update-schemas

Conversation

@haarchri

Copy link
Copy Markdown
Member

Description of your changes

An other cli that generates additional schemas of its own wants update-cache to produce them too, wrapping the exported UpdateCacheCmd and appending its own generation step keeps one user-facing command that leaves the project's models complete

Two additions to the embedding surface, one motivation: hosts need the dependency update-cache behavior available as a library.

  • pkg/project.UpdateSchemas, resolves the project's dependencies and generates language schemas for them and for the project's own APIs into the project's schemas directory, the same work crossplane dependency update-cache does. Options cover the cache directory, git authentication/proxy settings, an optional event channel for progress, and a Refresh toggle (re-resolve and refetch vs. use the cache). The update-cache command now delegates to it, so there is one implementation.
  • Exported dependency subcommand types (AddCmd, UpdateCacheCmd, CleanCacheCmd), the same treatment the project subcommands received: hosts can mount them in their own kong command trees and wrap them.

Fixes #

I have:

Need help with this checklist? See the cheat sheet.

Expose resolving a project's dependencies and generating language
schemas for them and the project's own APIs - the work dependency
update-cache does - so hosts can regenerate a project's models without
shelling out. The update-cache command now delegates to it.

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
Host CLIs embedding the dependency commands can mount them in their own
command trees and wrap them, e.g. update-cache to generate additional
schemas after the update, the same way the project subcommands are
exported.

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
@haarchri
haarchri requested review from a team, jcogilvie and tampakrap as code owners November 19, 2026 20:57
@haarchri
haarchri requested review from negz and removed request for a team November 19, 2026 20:57
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The project package adds an API for dependency updates and schema generation. Dependency command types become exported. The cache update command delegates dependency refresh and project API schema generation to the new API.

Changes: Dependency commands and schema updates

Layer / File(s) Summary
Project schema update API
pkg/project/project.go
Adds UpdateSchemasOptions and UpdateSchemas. The function configures dependency handling, refreshes or adds dependencies, and generates project API schemas when the API directory exists.
Exported dependency commands and cache update
cmd/crossplane/dependency/add.go, cmd/crossplane/dependency/cache.go, cmd/crossplane/dependency/dependency.go, cmd/crossplane/dependency/dependency_test.go
Exports AddCmd, UpdateCacheCmd, and CleanCacheCmd and uses them in Cmd and Git-authentication tests. UpdateCacheCmd calls project.UpdateSchemas with refresh enabled and the cache and Git options.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant UpdateCacheCmd
  participant project.UpdateSchemas
  participant xpkgClient
  participant dependencyManager
  participant schemaGenerator
  UpdateCacheCmd->>project.UpdateSchemas: pass refresh and Git options
  project.UpdateSchemas->>xpkgClient: create client
  project.UpdateSchemas->>dependencyManager: refresh dependencies
  dependencyManager-->>project.UpdateSchemas: return dependency result
  project.UpdateSchemas->>schemaGenerator: generate project API schemas
Loading

Possibly related PRs

  • crossplane/cli#544: Introduces the pkg/project facade and exports project command types, which this change extends with UpdateSchemas and exported dependency command types.

Suggested reviewers: adamwg

Merge Risk: Minimal · up to fa8b4

This change adds a project schema update API and exports the dependency commands, with update-cache delegating to the new API. No concrete behavioral regression was found. The one remaining note is about error wording that was already present before this change.

Pre-merge checks: Passed 6

Check name Status Explanation
Title check Passed The title is 70 characters, under the 72-character limit. It names the two main parts of the changeset: the new pkg/project UpdateSchemas API and the export of the dependency subcommand types. It is d…
Description check Passed The description explains the motivation (hosts need dependency update-cache behavior as a library). It covers the new pkg/project.UpdateSchemas API, its options, the delegation from update-cache, and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Breaking Changes Passed The check fails only for changes that remove or rename public fields or flags, add required public fields or flags, or remove behavior under apis/** or cmd/**. The PR does none of these. Changed f…
Feature Gate Requirement Passed Thank you, haarchri, for the clear description and the test coverage. The check fails only when new experimental features that affect apis/**, or that significantly change behavior, ship without a f…
Full details: Title check

Explanation

The title is 70 characters, under the 72-character limit. It names the two main parts of the changeset: the new pkg/project UpdateSchemas API and the export of the dependency subcommand types. It is descriptive and matches the raw summary and objectives.

Full details: Description check

Explanation

The description explains the motivation (hosts need dependency update-cache behavior as a library). It covers the new pkg/project.UpdateSchemas API, its options, the delegation from update-cache, and the exported AddCmd, UpdateCacheCmd, and CleanCacheCmd types. It is related to the changeset, though the 'Fixes #' line is left blank and the checklist is filled in.

Full details: Breaking Changes

Explanation

The check fails only for changes that remove or rename public fields or flags, add required public fields or flags, or remove behavior under apis/** or cmd/**. The PR does none of these. Changed files (from the review range): cmd/crossplane/dependency/{add.go,cache.go,dependency.go,dependency_test.go} and pkg/project/project.go. No apis/** files changed. - Renames: addCmd, updateCacheCmd, and cleanCacheCmd become AddCmd, UpdateCacheCmd, and CleanCacheCmd. These types were unexported before. Exporting them adds to the public surface and removes nothing. - Fields and flags: The struct fields and their kong tags (arg, help, name, short, env, default) are unchanged in all three command types. Cmd keeps the same field names. Only the field types changed, and those types are now exported. - Behavior of update-cache: The logic moved into pkg/project.UpdateSchemas and is equivalent: - Same xpkg client and cache dir resolution. - Same generator filtering from proj.Spec.Schemas.GetLanguages() and cfg.Features. - Same git options. Auth applies only when GitToken is set. Proxy and insecure host key apply under the same conditions as common.GitFlags.ManagerOptions(). - Refresh: true maps to RefreshAll, as before. - Project API schema generation runs under the same condition and sends the same events. - WithProjectFile: The new code passes FileName where the old code passed c.ProjectFile. This does not change update-cache output. RefreshAll uses addDependencyNoWrite, which does not write the project file, so m.projFile is not read on this path. - Removed code: The old cache.go dependency-manager and schema-generation setup was moved, not dropped. I could not read PR labels with the available tools. The label check does not apply here, because no breaking behavior or public-surface break was found.

Full details: Feature Gate Requirement

Explanation

Thank you, haarchri, for the clear description and the test coverage. The check fails only when new experimental features that affect apis/**, or that significantly change behavior, ship without a feature flag. This PR does not meet that condition. Evidence: - The changed files are cmd/crossplane/dependency/{add.go,cache.go,dependency.go,dependency_test.go} and pkg/project/project.go. No file under apis/ changes. - pkg/project.UpdateSchemas moves the existing update-cache logic into a library function. The command now delegates to it with Refresh: true. The same dependency manager, xpkg client, schema-generator filter, Git options, and project API schema step run as before. - The generator filter still reads cfg.Features.GenerateGoModelAccessors and cfg.Features.GenerateGoRuntimeObjects. Existing feature flags therefore still apply to the new path. - The other changes export existing types (AddCmd, UpdateCacheCmd, CleanCacheCmd) and rename receivers. They do not alter command behavior. - The new options and function carry no alpha or beta maturity marker. The diff contains no new feature flag. Notes for follow-up, not failure conditions: - add.go and cache.go now pass FileName to WithProjectFile in the library path, where the command previously passed c.ProjectFile. Please confirm this is intended when a custom -f path is used. - UpdateSchemas adds a public library API. Could you state its maturity level in the docs? Maintainers may want an explicit alpha label if the API can change.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

pkg/project/project.go-242-242: 1

242-242: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Describe the failed user operation in this error.

If the cache directory is not writable, this path reports “cannot create xpkg client”. That wording exposes an internal implementation detail. Please identify schema generation and dependency-cache preparation instead. For a cache-creation failure, include guidance to check directory permissions or select another cache directory. Preserve the underlying error. (raw.githubusercontent.com)

As per path instructions, error messages must “avoid technical jargon” and “include context about what the user was trying to do”.

Source: Path instructions

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b0b62c0 and fa8b4c3.

Files selected for processing: 5

  • cmd/crossplane/dependency/add.go
  • cmd/crossplane/dependency/cache.go
  • cmd/crossplane/dependency/dependency.go
  • cmd/crossplane/dependency/dependency_test.go
  • pkg/project/project.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.85%. Comparing base (cd703a0) to head (fa8b4c3).
⚠️ Report is 23 commits behind head on main.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haarchri
haarchri merged commit b9f4b44 into crossplane:main Nov 19, 2026
12 checks passed
@haarchri
haarchri deleted the feat/pkg-project-update-schemas branch November 19, 2026 22:18
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.

2 participants