Skip to content

Commit 436669e

Browse files
kvapsclaude
andcommitted
fix(store/k8s): ListByDefinition matches Spec, not labels
Resources created directly via kubectl apply / manifest YAML don't carry the blockstor.io/resource-definition label that the REST handler stamps on its own creates. The label-only filter therefore returned an empty list for those Resources, breaking: - tests/e2e/* scripts that apply Resources via raw YAML - any operator-managed Resource CRD landing through GitOps Switch to listing all Resources and filtering on Spec.ResourceDefinitionName in-process. Cluster Resource counts are small enough that the in-process filter is the right tradeoff for correctness. Stand regression: ResourceDefinitionReconciler logged `diskful: 0, diskless: 0` for an RD with 2 Resource CRDs because ListByDefinition returned empty — fixed. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent aac380a commit 436669e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pkg/store/k8s/resources.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,24 @@ func (s *resources) List(ctx context.Context) ([]apiv1.Resource, error) {
7171
func (s *resources) ListByDefinition(ctx context.Context, rdName string) ([]apiv1.Resource, error) {
7272
var crdList crdv1alpha1.ResourceList
7373

74-
err := s.c.List(ctx, &crdList,
75-
ctrlclient.MatchingLabels{LabelResourceDefinition: rdName})
74+
// List all Resources and filter by Spec.ResourceDefinitionName
75+
// in-process. We used to use a label selector, but Resources
76+
// created directly via kubectl/manifests (rather than through
77+
// the REST handler that sets labels) wouldn't be matched. Cluster
78+
// resource counts are small enough that the in-process filter is
79+
// the right tradeoff for correctness over hashed-label lookups.
80+
err := s.c.List(ctx, &crdList)
7681
if err != nil {
7782
return nil, errors.Wrapf(err, "list Resource CRDs for RD %q", rdName)
7883
}
7984

8085
out := make([]apiv1.Resource, 0, len(crdList.Items))
86+
8187
for i := range crdList.Items {
88+
if crdList.Items[i].Spec.ResourceDefinitionName != rdName {
89+
continue
90+
}
91+
8292
out = append(out, crdToWireResource(&crdList.Items[i]))
8393
}
8494

0 commit comments

Comments
 (0)