feat(builders): variadic WithMutation for slice-returning factories#124
Open
sourcehawk wants to merge 5 commits into
Open
feat(builders): variadic WithMutation for slice-returning factories#124sourcehawk wants to merge 5 commits into
sourcehawk wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR widens the builder API across the framework to allow registering multiple mutations in a single fluent call by making WithMutation variadic, enabling direct composition with slice-returning mutation factories (e.g. WithMutation(factory()...)).
Changes:
- Updated generic builders (
BaseBuilder, and the workload/static/task/integration wrappers) soWithMutationaccepts...Mutationand preserves registration order (with zero-arg as a no-op). - Updated primitive builders (typed primitives + unstructured wrappers) so
WithMutationaccepts...Mutationand registers mutations in argument order. - Added/updated documentation and tests to cover variadic registration, slice spreading, ordering, and the zero-arg no-op.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/primitives/unstructured/workload/builder.go | Make WithMutation variadic for unstructured workload builder. |
| pkg/primitives/unstructured/task/builder.go | Make WithMutation variadic for unstructured task builder. |
| pkg/primitives/unstructured/static/builder.go | Make WithMutation variadic for unstructured static builder and update method docs. |
| pkg/primitives/unstructured/integration/builder.go | Make WithMutation variadic for unstructured integration builder. |
| pkg/primitives/statefulset/builder.go | Make WithMutation variadic for StatefulSet builder. |
| pkg/primitives/statefulset/builder_test.go | Add tests for variadic ordering, slice spread, and zero-arg no-op. |
| pkg/primitives/serviceaccount/builder.go | Make WithMutation variadic for ServiceAccount builder. |
| pkg/primitives/service/builder.go | Make WithMutation variadic for Service builder. |
| pkg/primitives/secret/builder.go | Make WithMutation variadic for Secret builder. |
| pkg/primitives/rolebinding/builder.go | Make WithMutation variadic for RoleBinding builder. |
| pkg/primitives/role/builder.go | Make WithMutation variadic for Role builder. |
| pkg/primitives/replicaset/builder.go | Make WithMutation variadic for ReplicaSet builder. |
| pkg/primitives/pvc/builder.go | Make WithMutation variadic for PVC builder. |
| pkg/primitives/pv/builder.go | Make WithMutation variadic for PV builder. |
| pkg/primitives/pod/builder.go | Make WithMutation variadic for Pod builder. |
| pkg/primitives/pdb/builder.go | Make WithMutation variadic for PodDisruptionBudget builder. |
| pkg/primitives/networkpolicy/builder.go | Make WithMutation variadic for NetworkPolicy builder. |
| pkg/primitives/job/builder.go | Make WithMutation variadic for Job builder. |
| pkg/primitives/ingress/builder.go | Make WithMutation variadic for Ingress builder. |
| pkg/primitives/hpa/builder.go | Make WithMutation variadic for HPA builder. |
| pkg/primitives/deployment/builder.go | Make WithMutation variadic for Deployment builder. |
| pkg/primitives/daemonset/builder.go | Make WithMutation variadic for DaemonSet builder. |
| pkg/primitives/cronjob/builder.go | Make WithMutation variadic for CronJob builder. |
| pkg/primitives/configmap/builder.go | Make WithMutation variadic for ConfigMap builder. |
| pkg/primitives/clusterrolebinding/builder.go | Make WithMutation variadic for ClusterRoleBinding builder. |
| pkg/primitives/clusterrole/builder.go | Make WithMutation variadic for ClusterRole builder. |
| pkg/generic/builder_workload.go | Propagate variadic WithMutation through generic workload builder wrapper. |
| pkg/generic/builder_task.go | Propagate variadic WithMutation through generic task builder wrapper. |
| pkg/generic/builder_static.go | Propagate variadic WithMutation through generic static builder wrapper. |
| pkg/generic/builder_static_test.go | Add tests for variadic mutation registration semantics on generic static builder. |
| pkg/generic/builder_integration.go | Propagate variadic WithMutation through generic integration builder wrapper. |
| pkg/generic/builder_base.go | Implement variadic WithMutation in the generic base builder (append in order; zero args no-op). |
| docs/primitives.md | Document variadic WithMutation, ordering, and slice spread pattern for primitives. |
| docs/custom-resource.md | Update custom resource wrapper docs to show variadic WithMutation and slice-returning factories. |
Comment on lines
+59
to
64
| // WithMutation registers one or more typed feature mutations for the resource. | ||
| // Mutations are appended in the order provided; calling it with no arguments is | ||
| // a no-op. | ||
| func (b *BaseBuilder[T, M]) WithMutation(ms ...Mutation[M]) { | ||
| b.BaseRes.Mutations = append(b.BaseRes.Mutations, ms...) | ||
| } |
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.
Description
Closes #123
WithMutationnow accepts a variadic list of mutations, so mutation factories thatreturn
[]Mutationcompose directly inside a fluent builder chain instead of forcinga
for _, m := range factory() { b = b.WithMutation(m) }break. The change is a purewidening: every existing single-argument
WithMutation(x)call compiles and behavesexactly as before, and no methods are added or removed.
Changes
WithMutationtoWithMutation(ms ...Mutation)on all 5 generic builders(base, static, workload, task, integration).
WithMutationon all 25 primitive builders (21 typed primitives + 4unstructured wrappers); mutations register in argument order, and
WithMutation()with no arguments is a no-op.
WithMutation(factory()...)spread pattern) indocs/primitives.mdanddocs/custom-resource.md.Testing
pkg/generic/builder_static_test.go) andstatefulset subtests (
pkg/primitives/statefulset/builder_test.go) coveringmulti-argument registration order, slice spread, and the zero-argument no-op.
make all(build, lint, format,go test ./...) andmake build-examplesboth pass.