fix: fix different metric and hook snippets - #1998
Merged
oliverbaehler merged 42 commits intoJul 3, 2026
Merged
Conversation
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes TenantResource/GlobalTenantResource “processed items” keying for cluster-scoped resources (so admission/indexing uses the correct key), refactors the Processor reconcile flow to better handle cluster-scoped objects, and updates related webhook/helm snippets and tests.
Changes:
- Introduce a
clusterScopedstatus flag and use it to build consistent processed-item keys (dropping namespace for cluster-scoped resources). - Refactor
Processor.Reconcileinto smaller helpers, add RESTMapper-based scope resolution, and extend unit/e2e coverage for admission update-guard behavior. - Clean up metric deletion helpers and adjust helm chart defaults/schema/docs for webhook namespace selectors.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/runtime/indexers/tenantresource/namespaced_items.go | Switch index key generation to processedItemKey to handle cluster-scoped items correctly. |
| pkg/runtime/indexers/tenantresource/namespaced_created_items.go | Use processedItemKey for created-items index to align admission lookups. |
| pkg/runtime/indexers/tenantresource/global_items.go | Use processedItemKey for global processed-items index. |
| pkg/runtime/indexers/tenantresource/global_created_items.go | Use processedItemKey for global created-items index. |
| pkg/runtime/indexers/tenantresource/items.go | Add processedItemKey helper that drops namespace for cluster-scoped references. |
| pkg/runtime/indexers/tenantresource/items_test.go | Add unit tests validating cluster-scoped key behavior and namespace retention for namespaced items. |
| pkg/api/processor/processor_func.go | Refactor reconcile flow; add cluster-scope handling and isClusterScoped; centralize error recording. |
| pkg/api/processor/processor_func_test.go | Add tests for objectForProcessedItem and failAndRecord. |
| pkg/api/meta/reference.go | Add ClusterScoped field to processed item status condition. |
| charts/capsule/crds/capsule.clastix.io_tenantresources.yaml | Extend CRD schema with status.clusterScoped. |
| charts/capsule/crds/capsule.clastix.io_globaltenantresources.yaml | Extend CRD schema with status.clusterScoped. |
| internal/webhook/generic/replications.go | Ensure delete path runs replication admission handler; remove tenant-by-namespace gating. |
| e2e/replications_tenantresource_test.go | Add e2e coverage for “only managing TR service account can update created objects”; add SA impersonation helpers. |
| e2e/replications_globaltenantresource_test.go | Add e2e coverage for update-guard on namespaced + cluster-scoped resources under GTR; add cluster RBAC binder helper. |
| internal/controllers/rulestatus/manager.go | Fix incorrect variable checked after patchHelper.Patch call. |
| internal/metrics/tenantresource_recorder.go | Remove redundant gauge deletion in DeleteMetrics (delegates to DeleteConditionMetrics). |
| internal/metrics/tenantowner_recorder.go | Remove redundant gauge deletion in DeleteMetrics. |
| internal/metrics/rulestatus_recorder.go | Remove redundant gauge deletion in DeleteMetrics. |
| internal/metrics/config_recorder.go | Remove redundant gauge deletion in DeleteMetrics. |
| internal/metrics/global_tenantresource_recorder.go | Remove //nolint:dupl marker. |
| internal/metrics/tenantresource_recorder.go | Keep partial-match deletion centralized in DeleteConditionMetrics. |
| Makefile | Make dev-setup depend on dev-setup-cert-manager. |
| hack/distro/capsule/example-setup/resource.yaml | Adjust example setup resource snippet (remove dependsOn / scope: None). |
| charts/capsule/values.yaml | Change webhook namespaceSelector defaults for specific hooks. |
| charts/capsule/values.schema.json | Update schema shape for namespaceSelector where defaults now include matchExpressions. |
| charts/capsule/README.md | Update documented default values for affected webhook selectors. |
|
|
||
| if failAndContinue(i, "disowning failed for item: ", err) { | ||
| continue | ||
| if failAndRecord(processed, itemErrors, item, "removing metdata failed for item: ", err) { |
| // +optional | ||
| LastApply metav1.Time `json:"lastApply,omitempty,omitzero" protobuf:"bytes,8,opt,name=lastApply"` | ||
|
|
||
| // Indicates wether the resource was created or adopted |
| cluster-scoped. | ||
| type: boolean | ||
| created: | ||
| description: Indicates wether the resource was created or |
| cluster-scoped. | ||
| type: boolean | ||
| created: | ||
| description: Indicates wether the resource was created or |
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Comment on lines
40
to
45
| func (h *replicaHandler) OnDelete( | ||
| _ client.Client, | ||
| c client.Client, | ||
| reader client.Reader, | ||
| _ admission.Decoder, | ||
| recorder events.EventRecorder, | ||
| ) handlers.Func { |
|
|
||
| if failAndContinue(i, "disowning failed for item: ", err) { | ||
| continue | ||
| if failAndRecord(processed, itemErrors, item, "removing metdata failed for item: ", err) { |
| // +optional | ||
| LastApply metav1.Time `json:"lastApply,omitempty,omitzero" protobuf:"bytes,8,opt,name=lastApply"` | ||
|
|
||
| // Indicates wether the resource was created or adopted |
Comment on lines
+1039
to
+1040
| # @schema type: object | ||
| # @schema additionalProperties: true |
Comment on lines
+1043
to
+1044
| # @schema type: object | ||
| # @schema additionalProperties: true |
Comment on lines
3
to
4
|
|
||
| //nolint:dupl | ||
| package metrics |
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Comment on lines
1
to
5
| // Copyright 2020-2026 Project Capsule Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //nolint:dupl | ||
| package metrics | ||
|
|
Comment on lines
151
to
+154
| } | ||
|
|
||
| if failAndContinue(i, "disowning failed for item: ", err) { | ||
| continue | ||
| if failAndRecord(processed, itemErrors, item, "removing metdata failed for item: ", err) { | ||
| return |
Comment on lines
+1039
to
+1040
| # @schema type: object | ||
| # @schema additionalProperties: true |
Comment on lines
+1043
to
+1044
| # @schema type: object | ||
| # @schema additionalProperties: true |
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.
No description provided.