mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
fix(csi): refuse a replicationFactor beyond int32 (#1011)
Merge note (batch b5; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally): - One Test run (47198949595) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 22da3420 = main 5bf18d62 + #1011 #1012 in this order; these squash merges reproduce that tree, verified after the last one. - spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0. - Code review ACCEPT on 80f3b84a: a replicationFactor beyond int32 is refused as InvalidArgument before any conversion or provisioner call; MaxInt32 passes unchanged, MaxInt32+1 and larger make zero calls.
This commit is contained in:
1 parent
571a198ae7
commit
593cc8f87c
2 files changed
+32
-2
No files matched your search
@@ -280,11 +280,11 @@ func volumeSpecFromCreateRequest(req *csipb.CreateVolumeRequest) (VolumeSpec, er
|
||||
}
|
||||
rf := 1
|
||||
if raw := req.GetParameters()["replicationFactor"]; raw != "" {
|
||||
v, err := strconv.Atoi(raw)
|
||||
v, err := strconv.ParseInt(raw, 10, 32)
|
||||
if err != nil || v <= 0 {
|
||||
return VolumeSpec{}, status.Errorf(codes.InvalidArgument, "invalid replicationFactor %q", raw)
|
||||
}
|
||||
rf = v
|
||||
rf = int(v)
|
||||
}
|
||||
protocol, err := protocolFromParameters(req.GetParameters())
|
||||
if err != nil {
|
||||
|
||||
@@ -761,3 +761,33 @@ func authorityContextGuard(ctx map[string]string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestControllerCreateVolume_RefusesReplicationFactorBeyondInt32(t *testing.T) {
|
||||
create := func(raw string) (*stubProvisioner, error) {
|
||||
prov := &stubProvisioner{}
|
||||
s := NewControllerServerWithProvisioner(&stubLookup{}, prov)
|
||||
_, err := s.CreateVolume(context.Background(), &csipb.CreateVolumeRequest{
|
||||
Name: "pvc-a",
|
||||
CapacityRange: &csipb.CapacityRange{RequiredBytes: 1 << 30},
|
||||
Parameters: map[string]string{"replicationFactor": raw},
|
||||
VolumeCapabilities: []*csipb.VolumeCapability{testVolumeCapability()},
|
||||
})
|
||||
return prov, err
|
||||
}
|
||||
for _, raw := range []string{"4294967298", "2147483648"} {
|
||||
prov, err := create(raw)
|
||||
if status.Code(err) != codes.InvalidArgument {
|
||||
t.Fatalf("replicationFactor=%s: err=%v want InvalidArgument", raw, err)
|
||||
}
|
||||
if len(prov.calls) != 0 {
|
||||
t.Fatalf("replicationFactor=%s: provisioner calls=%d want 0", raw, len(prov.calls))
|
||||
}
|
||||
}
|
||||
prov, err := create("2147483647")
|
||||
if err != nil {
|
||||
t.Fatalf("replicationFactor=2147483647: %v", err)
|
||||
}
|
||||
if len(prov.calls) != 1 || prov.calls[0].ReplicationFactor != 2147483647 {
|
||||
t.Fatalf("replicationFactor=2147483647: calls=%+v", prov.calls)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user