Skip to content

Commit 779a0e7

Browse files
kvapsclaude
andcommitted
test(dispatcher): pin OriginalName lookup for slugified nodes
Locks in the dispatcher's slug-aware endpoint resolution: when the LINSTOR-side node name has been rewritten to a DNS-1123 slug at write time, Apply must read the original-name annotation, not metadata.Name. Without this test the regression would only surface in a rare non-RFC1123 deploy. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 6d9c367 commit 779a0e7

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

pkg/dispatcher/dispatcher_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
blockstoriov1alpha1 "github.com/cozystack/blockstor/api/v1alpha1"
2828
"github.com/cozystack/blockstor/pkg/dispatcher"
2929
satellitepb "github.com/cozystack/blockstor/pkg/satellite/proto"
30+
"github.com/cozystack/blockstor/pkg/store/k8s"
3031
"google.golang.org/grpc"
3132
)
3233

@@ -183,6 +184,49 @@ func TestApplyDialError(t *testing.T) {
183184
_ = stub
184185
}
185186

187+
// TestApplyMatchesSlugifiedNode: when the LINSTOR-side node name was
188+
// slugified at write time, the CRD's metadata.Name differs from
189+
// target.Spec.NodeName. Apply must still resolve the SatelliteEndpoint
190+
// by reading the original-name annotation rather than metadata.Name.
191+
func TestApplyMatchesSlugifiedNode(t *testing.T) {
192+
stub := &fakeSatelliteClient{
193+
resp: &satellitepb.ApplyResourcesResponse{
194+
Results: []*satellitepb.ResourceApplyResult{{Name: "pvc-1", NodeName: "MixedCaseNode", Ok: true}},
195+
},
196+
}
197+
dialer := &fakeDialer{stub: stub}
198+
d := dispatcher.New(dialer)
199+
200+
target := &blockstoriov1alpha1.Resource{
201+
Spec: blockstoriov1alpha1.ResourceSpec{
202+
ResourceDefinitionName: "pvc-1",
203+
NodeName: "MixedCaseNode",
204+
},
205+
}
206+
207+
meta := metav1.ObjectMeta{
208+
Name: "abcd1234-mixedcasenode",
209+
Annotations: map[string]string{k8s.AnnotationLinstorName: "MixedCaseNode"},
210+
}
211+
212+
nodes := []blockstoriov1alpha1.Node{{
213+
ObjectMeta: meta,
214+
Spec: blockstoriov1alpha1.NodeSpec{
215+
Type: "SATELLITE",
216+
Props: map[string]string{"SatelliteEndpoint": "10.244.1.7:7000"},
217+
},
218+
}}
219+
220+
_, err := d.Apply(t.Context(), target, nil, nodes, nil)
221+
if err != nil {
222+
t.Fatalf("Apply: %v", err)
223+
}
224+
225+
if dialer.endpoint != "10.244.1.7:7000" {
226+
t.Errorf("dialed %q, want 10.244.1.7:7000", dialer.endpoint)
227+
}
228+
}
229+
186230
// errDialer always fails — used to assert the dialErr path.
187231
type errDialer struct{ err error }
188232

0 commit comments

Comments
 (0)