Skip to content

Commit 4e8fc16

Browse files
committed
Fix return error code in pvCSI
1 parent d07b175 commit 4e8fc16

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

pkg/csi/service/wcpguest/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func (c *controller) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequ
473473
// to indicate that the volume provisioning has timed out
474474
// so that external-provisioner will keep retrying and won't leave
475475
// orphan volumes behind.
476-
return nil, csifault.CSIInternalFault, status.Errorf(codes.DeadlineExceeded, msg)
476+
return nil, csifault.CSIInternalFault, status.Error(codes.DeadlineExceeded, msg)
477477
}
478478
attributes := make(map[string]string)
479479
if commonco.ContainerOrchestratorUtility.IsFSSEnabled(ctx, common.FileVolume) && isFileVolumeRequest {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package wcpguest
18+
19+
import (
20+
"testing"
21+
22+
"google.golang.org/grpc/codes"
23+
"google.golang.org/grpc/status"
24+
)
25+
26+
// TestCreateVolumeTimeoutReturnsDeadlineExceeded verifies that when a PVC fails to bind
27+
// within the provision timeout, the CreateVolume operation returns codes.DeadlineExceeded
28+
// instead of codes.Internal to allow external-provisioner to retry and prevent orphan volumes.
29+
func TestCreateVolumeTimeoutReturnsDeadlineExceeded(t *testing.T) {
30+
t.Log("Testing timeout error code behavior")
31+
t.Log("")
32+
33+
// Simulate what the code does when timeout occurs
34+
msg := "failed to create volume on namespace: test-ns in supervisor cluster. reason: provisioning timeout"
35+
err := status.Error(codes.DeadlineExceeded, msg)
36+
37+
// Verify we can extract the correct code
38+
st, ok := status.FromError(err)
39+
if !ok {
40+
t.Fatalf("Expected to extract gRPC status from error")
41+
}
42+
43+
if st.Code() != codes.DeadlineExceeded {
44+
t.Fatalf("Expected codes.DeadlineExceeded, got: %v", st.Code())
45+
}
46+
47+
t.Logf("Timeout errors return codes.DeadlineExceeded")
48+
}

0 commit comments

Comments
 (0)