Skip to content

feat: add status subresource to ConstraintTemplatePodStatus CRD#4655

Open
a7i wants to merge 1 commit into
open-policy-agent:masterfrom
a7i:feat/ct-podstatus-status-subresource
Open

feat: add status subresource to ConstraintTemplatePodStatus CRD#4655
a7i wants to merge 1 commit into
open-policy-agent:masterfrom
a7i:feat/ct-podstatus-status-subresource

Conversation

@a7i

@a7i a7i commented Jul 3, 2026

Copy link
Copy Markdown

What this PR does / why we need it:

  • Adds +kubebuilder:subresource:status to ConstraintTemplatePodStatus and updates CRD/manifests in config/crd/bases and manifest_staging only.
  • Switches the ConstraintTemplate reconciler to write pod status via Status().Update instead of full-object Update.
  • Persists initial pod status (ID, Operations) with a follow-up Status().Update after Create, since the apiserver strips .status on create once the subresource is enabled.
  • Grants the manager ClusterRole explicit patch/update on constrainttemplatepodstatuses/status (in config/rbac and manifest_staging only).
  • Adds envtest integration tests (podstatus_subresource_test.go) verifying initial status persists after create and is returned on subsequent getOrCreatePodStatus calls.

Separate from #4596: this changes the write API path to the conventional status subresource. It does not address stale informer cache conflicts on its own; that still needs the retry/refetch logic in #4596.

Which issue(s) this PR fixes:

Related to #4595

Special notes for your reviewer:

  • CRD change is additive (subresources.status: {}); existing stored objects are unchanged.
  • Root deploy/ and charts/ are not edited; those are promoted from manifest_staging at release time. Helm installs from the root charts/ directory pick up the CRD/RBAC subresource changes at the next release promotion.
  • After both PRs land, fix: recover from stale-cache conflict on ConstraintTemplatePodStatus update #4596's retry helper should use Status().Update instead of Update.

Copilot AI review requested due to automatic review settings July 3, 2026 20:46

Copilot AI 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.

Pull request overview

This PR converts the ConstraintTemplatePodStatus CRD to use the conventional Kubernetes status subresource and updates the ConstraintTemplate reconciler to write per-pod status through Status().Update instead of a full-object Update. It is a precursor to #4596 (which addresses the stale-cache 409 conflicts) and does not by itself change the stale-cache retry behavior.

Changes:

  • Adds +kubebuilder:subresource:status to the ConstraintTemplatePodStatus type and regenerates the CRD manifests (subresources.status: {}).
  • Switches the three PodStatus write call sites in constrainttemplate_controller.go (Reconcile, reportErrorOnCTStatus, handleUpdate) from r.Update to r.Status().Update.
  • Updates several CRD manifest copies (including root deploy/ and charts/ artifacts).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apis/status/v1beta1/constrainttemplatepodstatus_types.go Adds the +kubebuilder:subresource:status marker enabling the status subresource.
pkg/controller/constrainttemplate/constrainttemplate_controller.go Switches 3 pod-status writes to Status().Update; create path in getOrCreatePodStatus still uses r.Create, which no longer persists the initial Status.ID/Operations.
config/crd/bases/status.gatekeeper.sh_constrainttemplatepodstatuses.yaml Regenerated CRD base adding the status subresource.
manifest_staging/deploy/gatekeeper.yaml Staging deploy manifest updated with the status subresource (correct location).
manifest_staging/charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml Staging chart CRD updated (correct location).
deploy/gatekeeper.yaml Root/promoted manifest edited manually — deviates from the manifest_staging promotion workflow.
charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml Root/promoted chart CRD edited manually — deviates from the manifest_staging promotion workflow.

Comment thread pkg/controller/constrainttemplate/constrainttemplate_controller.go
Comment thread deploy/gatekeeper.yaml Outdated
Comment thread charts/gatekeeper/crds/constrainttemplatepodstatus-customresourcedefinition.yaml Outdated
@a7i a7i force-pushed the feat/ct-podstatus-status-subresource branch from 2df38d0 to 6aae81c Compare July 4, 2026 13:52
@a7i a7i marked this pull request as ready for review July 4, 2026 15:34
@a7i a7i requested a review from a team as a code owner July 4, 2026 15:34
Copilot AI review requested due to automatic review settings July 4, 2026 15:34
@a7i a7i force-pushed the feat/ct-podstatus-status-subresource branch from 6aae81c to fd11c6f Compare July 4, 2026 15:35

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread apis/status/v1beta1/constrainttemplatepodstatus_types.go
Copilot AI review requested due to automatic review settings July 4, 2026 15:42

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread charts/gatekeeper/templates/gatekeeper-manager-role-clusterrole.yaml Outdated
Comment thread charts/gatekeeper/templates/gatekeeper-manager-role-clusterrole.yaml Outdated
Comment thread pkg/controller/constrainttemplate/constrainttemplate_controller.go
Declare a Kubernetes status subresource on ConstraintTemplatePodStatus and
switch the ConstraintTemplate reconciler to write pod status via
Status().Update instead of a full-object Update.

Persist initial pod status fields (ID, Operations) with a follow-up
Status().Update after Create, since the apiserver strips .status on create
once the subresource is enabled.

Grant the manager ClusterRole explicit patch/update on
constrainttemplatepodstatuses/status so Status().Update is authorized.

Add envtest integration tests verifying initial status persists after
create and is returned on subsequent getOrCreatePodStatus calls.

Manifest changes are limited to config/crd/bases and manifest_staging; root
deploy/ and charts/ are promoted at release time.

This aligns the write path with other Gatekeeper status subresources. It does
not replace the stale-cache conflict retry in open-policy-agent#4596; Status().Update still
requires a current resourceVersion.

Signed-off-by: Amir Alavi <amiralavi7@gmail.com>
@a7i a7i force-pushed the feat/ct-podstatus-status-subresource branch from fd11c6f to 113dd59 Compare July 4, 2026 16:58
@a7i

a7i commented Jul 4, 2026

Copy link
Copy Markdown
Author

Addressed all review feedback in 113dd59dd:

  • Post-Create status persist: getOrCreatePodStatus calls Status().Update immediately after Create so ID/Operations survive early reconcile returns.
  • Integration tests: podstatus_subresource_test.go (envtest) asserts freshly created PodStatus retains ID/Operations and that subsequent getOrCreatePodStatus returns them.
  • Promotion workflow: root deploy/ and charts/ are unchanged; CRD/RBAC updates are in config/crd/bases, config/rbac, and manifest_staging/ only.

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