diff --git a/lib/sharding/utils.go b/lib/sharding/utils.go index c59cac0..3f7a3dd 100644 --- a/lib/sharding/utils.go +++ b/lib/sharding/utils.go @@ -106,6 +106,29 @@ func RegisterClusterShard(ctx context.Context, c client.Client, component libsve return false, nil } +// UnregisterClusterShard removes the cluster entry from the shard-tracking ConfigMap. +// Call this when a cluster is fully deleted so stale entries do not accumulate. +func UnregisterClusterShard(ctx context.Context, c client.Client, component libsveltosv1beta1.Component, + feature, clusterNamespace, clusterName string, clusterType libsveltosv1beta1.ClusterType) error { + + cm, err := getConfigMap(ctx, c, component, feature) + if err != nil { + return err + } + + if cm.Data == nil { + return nil + } + + clusterId := fmt.Sprintf("%s-%s-%s", clusterType, clusterNamespace, clusterName) + if _, ok := cm.Data[clusterId]; !ok { + return nil + } + + delete(cm.Data, clusterId) + return updateConfigMap(ctx, c, cm) +} + const ( configMapName = "clustersharding" configMapNamespace = "projectsveltos"