Skip to content

Commit

Permalink
bugfix: get capacity grpc request should have timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bai3shuo4 committed Dec 13, 2021
1 parent 61e5b2d commit e0bdab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var (
workerThreads = flag.Uint("worker-threads", 100, "Number of provisioner worker threads, in other words nr. of simultaneous CSI calls.")
finalizerThreads = flag.Uint("cloning-protection-threads", 1, "Number of simultaneously running threads, handling cloning finalizer removal")
capacityThreads = flag.Uint("capacity-threads", 1, "Number of simultaneously running threads, handling CSIStorageCapacity objects")
operationTimeout = flag.Duration("timeout", 10*time.Second, "Timeout for waiting for creation or deletion of a volume")
operationTimeout = flag.Duration("timeout", 10*time.Second, "Timeout for waiting for volume operation (creation, deletion, capacity queries)")

enableLeaderElection = flag.Bool("leader-election", false, "Enables leader election. If leader election is enabled, additional RBAC rules are required. Please refer to the Kubernetes CSI documentation for instructions on setting up these RBAC rules.")

Expand Down Expand Up @@ -475,6 +475,7 @@ func main() {
factoryForNamespace.Storage().V1beta1().CSIStorageCapacities(),
*capacityPollInterval,
*capacityImmediateBinding,
*operationTimeout,
)
legacyregistry.CustomMustRegister(capacityController)

Expand Down
7 changes: 6 additions & 1 deletion pkg/capacity/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Controller struct {
cInformer storageinformersv1beta1.CSIStorageCapacityInformer
pollPeriod time.Duration
immediateBinding bool
timeout time.Duration

// capacities contains one entry for each object that is
// supposed to exist. Entries that exist on the API server
Expand Down Expand Up @@ -164,6 +165,7 @@ func NewCentralCapacityController(
cInformer storageinformersv1beta1.CSIStorageCapacityInformer,
pollPeriod time.Duration,
immediateBinding bool,
timeout time.Duration,
) *Controller {
c := &Controller{
csiController: csiController,
Expand All @@ -178,6 +180,7 @@ func NewCentralCapacityController(
cInformer: cInformer,
pollPeriod: pollPeriod,
immediateBinding: immediateBinding,
timeout: timeout,
capacities: map[workItem]*storagev1beta1.CSIStorageCapacity{},
}

Expand Down Expand Up @@ -596,7 +599,9 @@ func (c *Controller) syncCapacity(ctx context.Context, item workItem) error {
Segments: item.segment.GetLabelMap(),
}
}
resp, err := c.csiController.GetCapacity(ctx, req)
syncCtx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
resp, err := c.csiController.GetCapacity(syncCtx, req)
if err != nil {
return fmt.Errorf("CSI GetCapacity for %+v: %v", item, err)
}
Expand Down

0 comments on commit e0bdab2

Please sign in to comment.