Skip to content

Commit 5f3c7d9

Browse files
committed
Set error code to indicate timeout in pvCSI
1 parent 52ccaa1 commit 5f3c7d9

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

pkg/csi/service/wcpguest/controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,11 @@ func (c *controller) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequ
469469

470470
log.Errorf("Last observed events on the pvc %q/%q in supervisor cluster: %+v",
471471
c.supervisorNamespace, pvc.Name, spew.Sdump(eventList.Items))
472-
return nil, csifault.CSIInternalFault, status.Error(codes.Internal, msg)
472+
// Note: Set the return code to codes.DeadlineExceeded if PVC is still not bound
473+
// to indicate that the volume provisioning has timed out
474+
// so that external-provisioner will keep retrying and won't leave
475+
// orphan volumes behind.
476+
return nil, csifault.CSIInternalFault, status.Error(codes.DeadlineExceeded, msg)
473477
}
474478
attributes := make(map[string]string)
475479
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)