mirror of
https://github.com/lukaszraczylo/kubemirror.git
synced 2026-07-08 04:34:43 +00:00
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:
@@ -149,7 +149,7 @@ func (r *MirrorReconciler) SetupWithManager(mgr ctrl.Manager, gvk schema.GroupVe
|
||||
return false
|
||||
}
|
||||
managedBy, exists := labels[constants.LabelManagedBy]
|
||||
return exists && managedBy == "kubemirror"
|
||||
return exists && managedBy == constants.ControllerName
|
||||
})
|
||||
|
||||
// Convert GVK to resource object for watching
|
||||
@@ -157,9 +157,7 @@ func (r *MirrorReconciler) SetupWithManager(mgr ctrl.Manager, gvk schema.GroupVe
|
||||
gv := schema.GroupVersion{Group: gvk.Group, Version: gvk.Version}
|
||||
obj.SetGroupVersionKind(gv.WithKind(gvk.Kind))
|
||||
|
||||
// Set custom controller name to avoid conflicts with source reconciler and multiple API versions
|
||||
// Include group and version to make it truly unique
|
||||
controllerName := gvk.Kind + "." + gvk.Version + "." + gvk.Group + "-mirror"
|
||||
controllerName := gvkControllerName(gvk, true)
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(obj).
|
||||
|
||||
Reference in New Issue
Block a user