refactor(controller): extract shared mirror-deletion and naming helpers

Replace the triplicated ownership-verified delete guard with deleteOwnedMirror, and hand-built controller-name strings with gvkControllerName. Use constants.Domain/ControllerName over magic strings and maps.Copy/Clone for plain copy loops. Behaviour-preserving; tests green.
This commit is contained in:
2026-06-21 13:26:23 +01:00
parent c8ca8c41b6
commit 3628929871
4 changed files with 95 additions and 27 deletions
+18
View File
@@ -0,0 +1,18 @@
// Package controller implements the kubemirror reconciliation logic.
package controller
import "k8s.io/apimachinery/pkg/runtime/schema"
// gvkControllerName builds the unique controller-runtime controller name for a
// GVK. Including version and group avoids collisions across API versions, e.g.
// "HorizontalPodAutoscaler.v1.autoscaling" or "Secret.v1." (empty group for
// core resources). Source and mirror reconcilers for the same GVK must differ,
// so mirror controllers get a "-mirror" suffix. This is the single source of
// truth for the convention shared by both reconcilers.
func gvkControllerName(gvk schema.GroupVersionKind, mirror bool) string {
name := gvk.Kind + "." + gvk.Version + "." + gvk.Group
if mirror {
name += "-mirror"
}
return name
}