mirror of
https://github.com/lukaszraczylo/kubemirror.git
synced 2026-07-07 23:44:55 +00:00
improvements jan2025 (#6)
* feat(controller): add lazy watcher, improve resource usage and add pattern validation - [x] Add cache sync health check for readiness probe verification - [x] Create namespace lister with API reader support for fresh label queries - [x] Add pattern validation with warning logs for invalid glob patterns - [x] Implement lazy watcher initialization mode to scan for active resources - [x] Add requeue delay to namespace reconciler for cache settlement - [x] Replace custom containsString with slices.Contains from stdlib - [x] Add structured logging context to reconcilers (kind, group, version) - [x] Improve error variable naming for clarity in nested conditions - [x] Add nil-safe label access in namespace reconciler setup - [x] Add APIReader to namespace and source reconcilers for fresh data - [x] Improve type assertions with proper error handling in mirror operations - [x] Reorder struct fields for consistency and readability - [x] Add comprehensive pattern validation tests and validation API * feat(controller): add lazy watcher, improve resource usage and add pattern validation - [x] Add circuit breaker for reconciliation failure tracking and prevention - [x] Implement granular registration state tracking (not-registered, source-only, fully-registered) - [x] Add lazy controller initialization for active resource types only - [x] Consolidate namespace listing into single API call for efficiency - [x] Add mirror creation verification to catch webhook rejections - [x] Implement high-cardinality resource detection and warnings - [x] Add source deletion check in mirror reconciler to prevent races - [x] Preserve transformation annotations on errors in mirror reconciliation - [x] Expand constants documentation with labels vs annotations design rationale - [x] Add comprehensive test coverage for circuit breaker and registration states - [x] Add mutation-safety tests for hash computation * fixup! feat(controller): add lazy watcher, improve resource usage and add pattern validation
This commit is contained in:
@@ -24,7 +24,13 @@ type MirrorReconciler struct {
|
||||
|
||||
// Reconcile checks if a mirrored resource's source still exists, and deletes the mirror if orphaned.
|
||||
func (r *MirrorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||
logger := log.FromContext(ctx)
|
||||
logger := log.FromContext(ctx).WithValues(
|
||||
"mirrorNamespace", req.Namespace,
|
||||
"mirrorName", req.Name,
|
||||
"kind", r.GVK.Kind,
|
||||
"group", r.GVK.Group,
|
||||
"version", r.GVK.Version,
|
||||
)
|
||||
|
||||
// Fetch the mirror resource
|
||||
mirror := &unstructured.Unstructured{}
|
||||
@@ -73,9 +79,10 @@ func (r *MirrorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
|
||||
"sourceName", sourceName,
|
||||
"sourceUID", sourceUID)
|
||||
|
||||
if err := r.Delete(ctx, mirror); err != nil {
|
||||
logger.Error(err, "failed to delete orphaned mirror")
|
||||
return ctrl.Result{}, err
|
||||
deleteErr := r.Delete(ctx, mirror)
|
||||
if deleteErr != nil {
|
||||
logger.Error(deleteErr, "failed to delete orphaned mirror")
|
||||
return ctrl.Result{}, deleteErr
|
||||
}
|
||||
|
||||
logger.Info("orphaned mirror deleted successfully",
|
||||
@@ -91,6 +98,16 @@ func (r *MirrorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
// Check if source is being deleted - if so, let the SourceReconciler handle cleanup
|
||||
// This prevents race conditions where both reconcilers try to delete mirrors
|
||||
if !source.GetDeletionTimestamp().IsZero() {
|
||||
logger.V(1).Info("source is being deleted, skipping mirror check (SourceReconciler will handle cleanup)",
|
||||
"mirror", req.NamespacedName,
|
||||
"sourceNamespace", sourceNs,
|
||||
"sourceName", sourceName)
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// Source exists - verify UID matches
|
||||
actualUID := string(source.GetUID())
|
||||
if actualUID != sourceUID {
|
||||
|
||||
Reference in New Issue
Block a user