Skip to content

fix: fix different metric and hook snippets - #1998

Merged
oliverbaehler merged 42 commits into
projectcapsule:mainfrom
oliverbaehler:fix/minor-patches
Jul 3, 2026
Merged

fix: fix different metric and hook snippets#1998
oliverbaehler merged 42 commits into
projectcapsule:mainfrom
oliverbaehler:fix/minor-patches

Conversation

@oliverbaehler

Copy link
Copy Markdown
Collaborator

No description provided.

oliverbaehler and others added 30 commits December 10, 2025 06:50
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>
oliverbaehler and others added 7 commits July 2, 2026 10:13
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>
Copilot AI review requested due to automatic review settings July 3, 2026 08:39
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>

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 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 clusterScoped status flag and use it to build consistent processed-item keys (dropping namespace for cluster-scoped resources).
  • Refactor Processor.Reconcile into 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) {
Comment thread pkg/api/meta/reference.go
// +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>
Copilot AI review requested due to automatic review settings July 3, 2026 08:47

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

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) {
Comment thread pkg/api/meta/reference.go
// +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>
Copilot AI review requested due to automatic review settings July 3, 2026 11:25

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

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
@oliverbaehler
oliverbaehler merged commit 4b07463 into projectcapsule:main Jul 3, 2026
18 of 23 checks passed
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