Skip to content

Commit aab68a1

Browse files
kvapsclaude
andcommitted
fix(controller): re-enqueue Resources when parent RD changes
Volume-resize via PUT /v1/.../volume-definitions/{vn} updated RD.Spec.VolumeDefinitions but never re-fired the Resource reconcile, so the satellite kept dispatching the stale size and the underlying loop / LV stayed at the original capacity. linstor-csi expand-volume hit this end-to-end. Wire Watches(&RD{}, EnqueueRequestsFromMapFunc(...)) so every Resource referencing the modified RD gets re-reconciled and the dispatcher pushes the new VolumeDefinitions to the satellite. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 1cf7e16 commit aab68a1

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

internal/controller/resource_controller.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ import (
2323

2424
"k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/runtime"
26+
"k8s.io/apimachinery/pkg/types"
2627
ctrl "sigs.k8s.io/controller-runtime"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
29+
"sigs.k8s.io/controller-runtime/pkg/handler"
2830
logf "sigs.k8s.io/controller-runtime/pkg/log"
31+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2932

3033
blockstoriov1alpha1 "github.com/cozystack/blockstor/api/v1alpha1"
3134
apiv1 "github.com/cozystack/blockstor/pkg/api/v1"
@@ -624,9 +627,47 @@ func (r *ResourceReconciler) EnsureDRBDIDsForTest(ctx context.Context, target *b
624627
}
625628

626629
// SetupWithManager sets up the controller with the Manager.
630+
//
631+
// We Watch ResourceDefinitions too — every replica's dispatch reads
632+
// the parent RD's VolumeDefinitions for the satellite render, so an
633+
// RD-side change (volume size, prop bag, encryption passphrase) must
634+
// re-fire every replica's reconcile. Without this watch, `linstor
635+
// volume-definition modify --size` updates Spec.VolumeDefinitions but
636+
// the satellite never gets the new size.
627637
func (r *ResourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
628638
return ctrl.NewControllerManagedBy(mgr).
629639
For(&blockstoriov1alpha1.Resource{}).
640+
Watches(&blockstoriov1alpha1.ResourceDefinition{},
641+
handler.EnqueueRequestsFromMapFunc(r.enqueueResourcesForRD)).
630642
Named("resource").
631643
Complete(r)
632644
}
645+
646+
// enqueueResourcesForRD maps an RD event to every Resource that
647+
// references it via Spec.ResourceDefinitionName.
648+
func (r *ResourceReconciler) enqueueResourcesForRD(ctx context.Context, obj client.Object) []reconcile.Request {
649+
rd, ok := obj.(*blockstoriov1alpha1.ResourceDefinition)
650+
if !ok {
651+
return nil
652+
}
653+
654+
var resList blockstoriov1alpha1.ResourceList
655+
656+
if err := r.List(ctx, &resList); err != nil {
657+
return nil
658+
}
659+
660+
out := make([]reconcile.Request, 0, len(resList.Items))
661+
662+
for i := range resList.Items {
663+
if resList.Items[i].Spec.ResourceDefinitionName != rd.Name {
664+
continue
665+
}
666+
667+
out = append(out, reconcile.Request{
668+
NamespacedName: types.NamespacedName{Name: resList.Items[i].Name},
669+
})
670+
}
671+
672+
return out
673+
}

0 commit comments

Comments
 (0)