Skip to content

feat: implement clusterrolebinding primitive#36

Merged
sourcehawk merged 27 commits intomainfrom
feature/clusterrolebinding-primitive
Mar 25, 2026
Merged

feat: implement clusterrolebinding primitive#36
sourcehawk merged 27 commits intomainfrom
feature/clusterrolebinding-primitive

Conversation

@sourcehawk
Copy link
Owner

Implements the clusterrolebinding Kubernetes resource primitive following the pattern established by the existing ConfigMap and Deployment primitives.

Summary

  • Adds clusterrolebinding primitive package under pkg/primitives/clusterrolebinding/
  • Implements required lifecycle interfaces
  • Includes editors, mutator, flavors, and builder

Checklist

  • Compiles cleanly
  • Tests pass
  • Follows naming conventions in CONTEXT.md
  • Does not modify shared files

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new clusterrolebinding primitive to the operator-component-framework, extending the existing primitives system to support Kubernetes ClusterRoleBinding resources with the same builder/mutation/flavor/data-extraction patterns used elsewhere in the framework.

Changes:

  • Introduces pkg/primitives/clusterrolebinding with builder, resource wrapper, mutator, and field-application flavors (plus tests).
  • Adds a new shared mutation editor BindingSubjectsEditor for typed .subjects mutations (plus tests).
  • Adds an end-to-end example and new primitive documentation page for clusterrolebinding.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/primitives/clusterrolebinding/resource.go Implements the primitive Resource wrapper and DefaultFieldApplicator (roleRef immutability handling).
pkg/primitives/clusterrolebinding/builder.go Provides a fluent builder API for configuring mutations/flavors/extractors for ClusterRoleBinding.
pkg/primitives/clusterrolebinding/mutator.go Adds a plan-and-apply mutator supporting metadata + subjects edits with feature boundaries.
pkg/primitives/clusterrolebinding/flavors.go Exposes label/annotation preservation flavors for post-baseline field application.
pkg/primitives/clusterrolebinding/*_test.go Adds unit tests for builder, mutator ordering, and flavor behavior.
pkg/mutation/editors/bindingsubjects.go Adds a shared editor for typed RoleBinding/ClusterRoleBinding subjects mutations.
pkg/mutation/editors/bindingsubjects_test.go Adds unit tests for BindingSubjectsEditor behavior.
examples/clusterrolebinding-primitive/** Adds a runnable example showing builder usage, feature mutations, and extractors.
docs/primitives/clusterrolebinding.md Adds user-facing documentation for the new primitive.

Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated 3 comments.

Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated 2 comments.

@sourcehawk
Copy link
Owner Author

Claude Review Cycle 1 Complete

Addressed:

  • ResourceVersion preservation in DefaultFieldApplicator (resource.go:20): The applicator was saving resourceVersion but not restoring it after DeepCopy. Now restores both roleRef and resourceVersion when the object already exists. Added test assertion for ResourceVersion preservation on updates.

Intentionally ignored:

  • Markdown table format (clusterrolebinding.md:15): The capabilities table already uses standard single-pipe markdown format (| ... | ... |), consistent with other primitive docs. The comment describes a || format that is not present in the file.

Copilot AI review requested due to automatic review settings March 22, 2026 19:51
Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated 2 comments.

@sourcehawk
Copy link
Owner Author

Approved

@sourcehawk sourcehawk force-pushed the feature/clusterrolebinding-primitive branch from 8ae0393 to 65a6d28 Compare March 23, 2026 00:47
Copilot AI review requested due to automatic review settings March 23, 2026 03:00
Copy link

Copilot AI left a comment

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 39 out of 40 changed files in this pull request and generated 4 comments.

@sourcehawk
Copy link
Owner Author

Claude Review Cycle 1 Complete

Addressed:

  • builder.go:25 — Refactored builder to wrap generic.NewStaticBuilder with MarkClusterScoped(), matching the ConfigMap pattern. Eliminates duplicated validation and framework wiring.
  • controller.go:7 — Updated package and struct comments to reflect current framework behavior: owner references are automatically skipped for cluster-scoped resources with namespace-scoped owners, with a note about GC implications.
  • clusterrolebinding.md:14 — Updated capabilities table to clarify that Build() validates Name and requires metadata.namespace to be empty (errors if set).

Intentionally ignored:

  • create.go:39 — This comment is about updating the PR description/checklist, not a code change. Additionally, pkg/component/create.go is not modified in this PR (the diff shows only new files). The shared infrastructure changes referenced (owner reference handling, server-managed metadata) were merged to main separately and are not part of this PR's diff.

<!-- claude-review-cycle -->

Copilot AI review requested due to automatic review settings March 23, 2026 16:00
Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 23, 2026 16:58
@sourcehawk
Copy link
Owner Author

Claude Review Cycle 1 Complete

Addressed:

  • Added clusterrolebinding-primitive to the Makefile run-examples target so CI exercises it alongside other examples
  • Added clusterrolebinding to the Built-in Primitives table in docs/primitives.md
  • Added BindingSubjectsEditor to the Mutation Editors table in docs/primitives.md

Intentionally ignored:
None

<!-- claude-review-cycle -->

Copy link

Copilot AI left a comment

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 18 out of 18 changed files in this pull request and generated 1 comment.

sourcehawk and others added 4 commits March 23, 2026 20:17
Provides typed mutations for the .subjects field of binding resources:
Add, Remove, EnsureServiceAccount, RemoveServiceAccount, and Raw.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Static, cluster-scoped primitive with custom validation (name only,
no namespace). DefaultFieldApplicator preserves immutable roleRef on
updates. Mutator supports metadata and subjects edits via plan-and-apply.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Demonstrates building and mutating a ClusterRoleBinding through
multiple spec variations with feature-gated subject mutations,
version labels, and field application flavors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sourcehawk sourcehawk requested review from Copilot and removed request for Copilot March 25, 2026 16:03
@sourcehawk sourcehawk requested review from Copilot and removed request for Copilot March 25, 2026 16:05
@sourcehawk sourcehawk requested review from Copilot and removed request for Copilot March 25, 2026 16:07
Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated 5 comments.

…rovements

- Lazily initialize feature plan in EditObjectMetadata/EditSubjects to
  prevent nil dereference when BeginFeature() has not been called
- Remove side-effect from BindingSubjectsEditor.Raw() (no longer converts
  nil slice to empty slice on read)
- Use safe type assertions (comma-ok + require.True) in resource tests
- Add test exercising EditSubjects without prior BeginFeature call
- Use EnsureServiceAccount instead of Add in example for idempotency

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sourcehawk
Copy link
Owner Author

Claude Review Cycle 1 Complete

Addressed:

  • Mutator nil dereference (mutator.go lines 58, 73): Added ensureActive() helper that lazily calls BeginFeature() when m.active == nil, making EditObjectMetadata and EditSubjects safe to call without prior BeginFeature(). Added test TestMutator_EditSubjects_WithoutBeginFeature.
  • Raw() side-effect (bindingsubjects.go line 34): Removed nil-to-empty-slice initialization from Raw(), making it a pure read operation. append works correctly with nil slices so no initialization is needed.
  • Unsafe type assertion in test (resource_test.go line 61): Changed bare type assertion to comma-ok form with require.True(t, ok) in both TestResource_Mutate and TestResource_Mutate_WithMutation.
  • Example using Add instead of EnsureServiceAccount (mutations.go line 41): Replaced e.Add(rbacv1.Subject{...}) with e.EnsureServiceAccount("monitoring-agent", "monitoring") for idempotent, best-practice example code.

Intentionally ignored:
None

<!-- claude-review-cycle -->

@sourcehawk sourcehawk requested review from Copilot and removed request for Copilot March 25, 2026 16:16
Copy link

Copilot AI left a comment

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 16 out of 16 changed files in this pull request and generated no new comments.

Resolve conflicts in BindingSubjectsEditor by adopting main's improved
base (nil-pointer safety, upsert semantics, zeroing on remove) and
retaining this branch's convenience methods (EnsureServiceAccount,
RemoveServiceAccount). Update docs/primitives.md to include both
PolicyRulesEditor and BindingSubjectsEditor, and both clusterrole and
clusterrolebinding primitives.
@sourcehawk sourcehawk merged commit 5d8ce33 into main Mar 25, 2026
2 checks passed
@sourcehawk sourcehawk deleted the feature/clusterrolebinding-primitive branch March 25, 2026 18:11
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