Skip to content

Commit cebf0c1

Browse files
scotwellsclaude
andcommitted
feat: hub-side referenced-data companion cleanup (Components 3+4+5)
Remove the cell-side CompanionGCReconciler — deleting a Karmada-owned cell copy directly causes a permanent delete/recreate thrash because the Work object immediately re-applies the manifest. Hub-side cleanup is the only correct layer. Component 5: Delete companion_gc_controller.go and its test, and remove the --enable-cell-controllers registration block from cmd/main.go. Component 3: After deleting a hub companion (ref-count reaches zero), the downstreamCompanionWriter now also deletes the companion's Karmada ResourceBinding via hubClient. RB name follows the Karmada binding-controller convention: "{companionName}-{configmap|secret}". Deleting the RB cascades: binding-controller removes the Work, execution-controller removes the cell copy permanently. IgnoreNotFound tolerates Karmada beating us to it. localCompanionWriter (single-cluster dev mode) is a no-op. Component 4: New OrphanRBReconciler runs on the Karmada hub federation manager (alongside InstanceProjector). It watches ResourceBindings and deletes any that are orphaned companion RBs — name ends with "-configmap" or "-secret" AND propagationpolicy.karmada.io/name starts with "city-" AND the hub companion no longer exists. WD RBs (suffix "-workloaddeployment") and non-city-PP RBs are never touched. A periodic sweep Runnable fires every 5 minutes to catch RBs orphaned before the controller started, which will automatically clean the existing stranded lab RBs on first deployment. RBAC: add delete to work.karmada.io/resourcebindings in downstream-rbac (hub ClusterRole). karmada-io/api work/v1alpha2 types added to global scheme so the federation client can serialize ResourceBinding objects. Tests: unit tests for Component 3 (RB teardown fires on ConfigMap/Secret companion deletion, tolerates NotFound, no-op on localCompanionWriter) and Component 4 (orphan detection, skip live/terminating companions, tight scope guards against WD RBs and non-city-PP RBs, name pattern parsing). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> (cherry picked from commit ac25bf7)
1 parent 8a283d5 commit cebf0c1

9 files changed

Lines changed: 917 additions & 1526 deletions

cmd/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636

3737
karmadaclusterv1alpha1 "github.com/karmada-io/api/cluster/v1alpha1"
3838
karmadapolicyv1alpha1 "github.com/karmada-io/api/policy/v1alpha1"
39+
karmadaworkv1alpha2 "github.com/karmada-io/api/work/v1alpha2"
3940
computev1alpha "go.datum.net/compute/api/v1alpha"
4041
"go.datum.net/compute/internal/config"
4142
"go.datum.net/compute/internal/controller"
@@ -83,6 +84,7 @@ func init() {
8384
utilruntime.Must(quotav1alpha1.AddToScheme(scheme))
8485
utilruntime.Must(karmadapolicyv1alpha1.Install(scheme))
8586
utilruntime.Must(karmadaclusterv1alpha1.Install(scheme))
87+
utilruntime.Must(karmadaworkv1alpha2.Install(scheme))
8688

8789
// +kubebuilder:scaffold:scheme
8890
}
@@ -315,13 +317,6 @@ func main() {
315317
}
316318
}
317319

318-
if enableCellControllers {
319-
if err = (&controller.CompanionGCReconciler{}).SetupWithManager(mgr); err != nil {
320-
setupLog.Error(err, "unable to create controller", "controller", "CompanionGC")
321-
os.Exit(1)
322-
}
323-
}
324-
325320
// WorkloadDeploymentFederator and InstanceProjector are management-plane
326321
// controllers that run on the control-plane cluster. The fail-loud guard above
327322
// ensures federationRestConfig is non-nil when enableManagementControllers is
@@ -535,6 +530,15 @@ func setupManagementControllers(mgr mcmanager.Manager, federationClient client.C
535530
return nil, fmt.Errorf("InstanceProjector: %w", err)
536531
}
537532

533+
// OrphanRBReconciler sweeps Karmada ResourceBindings whose hub companion is
534+
// gone, ensuring Works and cell copies are cleaned up even when Karmada's
535+
// event-driven cascade misses the companion-deletion event (e.g. PP deleted
536+
// before binding-controller reconcile completed). Runs on the hub federation
537+
// manager alongside InstanceProjector.
538+
if err = controller.SetupOrphanRBWithManager(federationMgr, federationClient); err != nil {
539+
return nil, fmt.Errorf("OrphanRBReconciler: %w", err)
540+
}
541+
538542
return []manager.Runnable{federationMgr}, nil
539543
}
540544

config/base/downstream-rbac/rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rules:
2424
verbs: ["get", "list", "watch"]
2525
- apiGroups: ["work.karmada.io"]
2626
resources: ["resourcebindings", "clusterresourcebindings"]
27-
verbs: ["get", "list", "watch"]
27+
verbs: ["get", "list", "watch", "delete"]
2828
- apiGroups: ["config.karmada.io"]
2929
resources: ["resourceinterpreterwebhookconfigurations", "resourceinterpretercustomizations"]
3030
verbs: ["get", "list", "watch"]

0 commit comments

Comments
 (0)