PR Controller PoC#514
Merged
Merged
Conversation
✅ Deploy Preview for porch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
d54208d to
d023ed0
Compare
4b4c437 to
ae6a0c7
Compare
nagygergo
reviewed
Apr 10, 2026
Contributor
nagygergo
left a comment
There was a problem hiding this comment.
Some way through this. Not sure how much time I'll have next week, so posting a partial review.
| // which returns status: {} since status is a separate subresource. | ||
| savedStatus := crd.Status | ||
|
|
||
| patchOpts := []client.PatchOption{client.FieldOwner(fieldManagerRepoController)} |
Contributor
There was a problem hiding this comment.
If setting ownership for all the parameters, then how clients will be able to do SSA on their own?
Collaborator
Author
There was a problem hiding this comment.
Zero-value fields are excluded from the SSA payload. The repo controller only claims ownership of fields it explicitly sets — lifecycle, source, readinessGates etc. are omitted and remain unowned by this field manager.
515c094 to
b8d43af
Compare
liamfallon
reviewed
Apr 16, 2026
liamfallon
reviewed
Apr 16, 2026
bccddf6 to
9b8b75f
Compare
liamfallon
reviewed
Apr 16, 2026
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
liamfallon
previously approved these changes
Apr 29, 2026
4c5847e to
0dac197
Compare
Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
mozesl-nokia
approved these changes
Apr 29, 2026
|
liamfallon
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Title
v1alpha2 PackageRevision Controller & Supporting Infrastructure
Description
Overview
Introduces a new controller-runtime reconciler for v1alpha2
PackageRevisionCRDs, decoupling package lifecycle management (source execution, rendering, lifecycle transitions) from the API server's synchronous request path into an async reconciliation loop.Opt-in via
--repositories.create-v1alpha2-rpkg=trueon the controller andporch.kpt.dev/v1alpha2-migration: "true"annotation on Repository CRs.1. PackageRevision Controller (
controllers/packagerevisions/)~1470 lines production code, ~3000 lines tests. Watches v1alpha2
PackageRevisionCRDs and handles:source.go): init, clone, copy, upgrade — writes resources to git via the shared cache, tracked bystatus.creationSource.render.go): KRM function pipelines via fn-runner (gRPC). Triggered byrender-requestannotation (PRR push path) or post-source-execution. Bounded concurrency viarenderLimiter. Supportspush-on-render-failure.status.go): SSA with distinct field managers for controller state, render state, and Kptfile-derived fields. ReportsReadyandRenderedconditions.labels.go): Manageslatest-revision, ensuring only the highest published revision is marked latest.fieldindex.go): controller-runtime indexes for efficient lookup by repository, package, workspace.mergekey.go): Local copy of merge-key utilities to avoid v1alpha1-coupled imports.integration/): envtest-based, covering the full reconcile loop.Shared cache: The repo and PR controllers run in the same process, sharing a single cache instance. The repo controller creates it at startup; the PR controller accesses it via the
ContentCachewrapper — avoiding duplicated git state and ensuring a consistent view.Function runtime: Unlike the API server (synchronous render inside the request), the PR controller instantiates its own
MultiFunctionRuntime(builtin-first, gRPC fallback) directly in the controller binary, configured viaFUNCTION_RUNNER_ADDRESS. If unavailable, rendering is skipped.Wired in
controllers/main.gowith explicit ordering — repo controller first (initializes cache), then PR controller (receives cache, credential resolvers, function runtime).2. Content Cache & Interfaces (
pkg/cache/contentcache/,pkg/repository/content.go)Version-neutral abstraction layer between the PR controller and the existing cache, avoiding v1alpha1 type coupling:
ContentCache:GetPackageContent,UpdateLifecycle,CreateNewDraft,CreateDraftFromExisting,CloseDraft,DeletePackage— all plain strings.PackageContent: Read-only access to resources, Kptfile, locks, commit info.PackageRevisionDraftSlim: Minimal draft interface for resource/lifecycle updates.ExternalPackageFetcher: Fetches from external git repos (clone-from-upstream) with credential/CA resolution.wrappers.go): Adapt existingPackageRevision/PackageRevisionDraftto the new interfaces.contentcache.go: Backed bycachetypes.Cache, handles repo resolution, package lookup, lifecycle state machine.3. Existing Interface Changes (
pkg/repository/repository.go)GetCommitInfo() (time.Time, string): Added toPackageRevisioninterface. Implemented across git, OCI, fake, crcache, dbcache. Git backend now captures publish metadata (time + user email) atClosePackageRevisionDraft.IsLatestRevision() bool: Promoted from unexportedhasLatestRevisionInfoto a first-class interface method — eliminates type assertions in label generation.4. v1alpha2 API Types (
api/porch/v1alpha2/)ObservedGeneration, SSA-compatibleConditions(listType=map,listMapKey=type),PublishedAt→*metav1.Time,Revisionalways serialized.AnnotationRenderRequest,PushOnFnRenderFailureKey,ConditionRendered,ReasonRendered,ReasonRenderFailed.kptdata_conversion.go):KptfileToPackageConditions,KptfileToReadinessGates,KptfileToPackageMetadata,KptUpstreamLockToLocator— shared by repo controller (CRD sync) and PR controller (status).5. Repository Controller — CRD Sync (
controllers/repositories/)crdsync.go: When enabled, creates/updates/deletes v1alpha2PackageRevisionCRDs to match discovered packages. SSA with separate spec/status applies. Ownership split: repo controller owns identity/lock fields; PR controller owns lifecycle/render/publish fields.sync.go: CallssyncPackageRevisionCRDspost-sync. CRD failures are non-fatal.porch.kpt.dev/packagerevisionsandpackagerevisions/statuspermissions.6. API Server Changes (
pkg/registry/porch/,pkg/engine/)packagecommon.go): v1alpha2-annotated repos excluded from v1alpha1 list/get/update/watch.v1alpha2FilteringWatchersuppresses watch events.packagerevisionresources.go): v1alpha2 repos useUpdatePackageResourcesWithoutRender(no sync render), then patchrender-requestannotation to trigger async render. NewgetRepoPkgRevForResourceshandles both API versions.engine.go):UpdatePackageResourcesWithoutRender— writes resources and closes draft without render pipeline.7. porchctl CLI (
pkg/cli/commands/rpkg/,internal/cliutils/)--api-versionflag: Persistent onrpkg, also readsPORCHCTL_API_VERSIONenv. Defaults tov1alpha1.dispatch.go):WrapVersionDispatchroutesPreRunE/RunEto v1alpha2 implementations when flagged.v1alpha2.go+v1alpha2_test.go.client_v1alpha2.go): Custom REST mapper routingPackageRevisiontoporch.kpt.dev/v1alpha2(CRD) while keepingPackageRevisionResourcesatv1alpha1(API server).repo reg: Supports setting the v1alpha2 migration annotation on registration.8. Deployment & Build
run-in-kind-v1alpha2,run-in-kind-v1alpha2-no-controller(local dev).--create-v1alpha2-rpkgflag — installs CRD, flips controller flag, addspackagerevisionsreconciler.--repositories.create-v1alpha2-rpkg=falsedefault arg.CaDEngine,PackageRevision; newContentCache,ExternalPackageFetcher,PackageContent.9. porchconfig Annotation (
api/porchconfig/v1alpha1/types.go)AnnotationKeyV1Alpha2Migration/AnnotationValueMigrationEnabled— per-repository opt-in gating CRD sync and v1alpha2 filtering.Related Issue(s)
EPIC: Moving PackageRevision to CRD #811
PIP: PackageRevision CRD Migration #890
Type of Change
Checklist
Testing Instructions
Deploy with v1alpha2 enabled:
This builds all images, deploys to kind with DB cache, installs the v1alpha2
PackageRevisionCRD, enables thepackagerevisionsreconciler, and sets--repositories.create-v1alpha2-rpkg=trueon the controller.Register a v1alpha2-managed repository:
This sets the
porch.kpt.dev/v1alpha2-migration: "true"annotation on the Repository CR. The repo controller will sync packages and create v1alpha2PackageRevisionCRDs. Verify with:Use porchctl with v1alpha2:
Or set
export PORCHCTL_API_VERSION=v1alpha2to avoid repeating the flag.Local controller development (run controller outside the cluster):
Then run the controller locally with appropriate kubeconfig and
FUNCTION_RUNNER_ADDRESSpointing to the in-cluster fn-runner.VSCode: Use the Launch Controllers (repositories + packagerevisions v1alpha2) debug configuration in .vscode/launch.json. It starts both the repositories and packagerevisions reconcilers with --repositories.create-v1alpha2-rpkg=true, DB cache env vars, and FUNCTION_RUNNER_ADDRESS pre-configured. Adjust DB_HOST and FUNCTION_RUNNER_ADDRESS IPs if your kind network differs.
Additional Notes
Known issues:
v1alpha2FilteringWatcherinpackagecommon.godoes a live repo lookup per watch event — acceptable at current scale but may need caching if watch volume grows.Further improvements:
PackageRevisionSyncComplete=False) to surface partial CRD sync failures.r.cad.ListPackageRevisionsingetRepoPkgRevForResourceswith direct cache access once the engine dependency can be removed.Review notes:
mergekey.gois a deliberate duplication frompkg/taskto avoid pulling in v1alpha1 types into the controller package.NewGRPCFunctionRuntimewas renamed fromnewGRPCFunctionRuntime(exported) to allow the controller binary to instantiate its own runtime.🤖 AI Assistance Disclosure
This pull request was created with the assistance of generative AI tools. (AmazonQ Developer VSCode plugin)
All code and changes have been reviewed and validated by the author.