Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default detach retry limit to 100 & enable unlimit option #185

Merged
merged 1 commit into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions cmd/disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package main

import (
"flag"
"math/rand"
"os"
"time"

"github.com/yunify/qingcloud-csi/pkg/cloud"
"github.com/yunify/qingcloud-csi/pkg/common"
"github.com/yunify/qingcloud-csi/pkg/disk/driver"
"github.com/yunify/qingcloud-csi/pkg/disk/rpcserver"
"k8s.io/klog"
"math/rand"
"os"
"time"
)

const (
Expand All @@ -35,13 +36,13 @@ const (
)

var (
configPath = flag.String("config", defaultConfigPath, "server config file path")
driverName = flag.String("drivername", defaultProvisionName, "name of the driver")
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
maxVolume = flag.Int64("maxvolume", 10, "Maximum number of volumes that controller can publish to the node.")
nodeId = flag.String("nodeid", "", "If driver cannot get instance ID from /etc/qingcloud/instance-id, we would use this flag.")
retryIntervalMax = flag.Duration("retry-interval-max", 2*time.Minute, "Maximum retry interval of failed deletion.")
retryTimesMax = flag.Int("retry-times-max", 10, "Maximum retry times of failed detach volume.")
configPath = flag.String("config", defaultConfigPath, "server config file path")
driverName = flag.String("drivername", defaultProvisionName, "name of the driver")
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
maxVolume = flag.Int64("maxvolume", 10, "Maximum number of volumes that controller can publish to the node.")
nodeId = flag.String("nodeid", "", "If driver cannot get instance ID from /etc/qingcloud/instance-id, we would use this flag.")
retryIntervalMax = flag.Duration("retry-interval-max", 2*time.Minute, "Maximum retry interval of failed deletion.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove retryIntervalMax? ie. remove the retries and hand over the control to csi sidecar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it should be removed, I'll do that in another PR.

retryDetachTimesMax = flag.Int("retry-detach-times-max", 100, "Maximum retry times of failed detach volume. Set to 0 to disable the limit.")
)

func main() {
Expand Down Expand Up @@ -88,5 +89,5 @@ func handle() {
mounter := common.NewSafeMounter()
driver := driver.GetDiskDriver()
driver.InitDiskDriver(diskDriverInput)
rpcserver.Run(driver, cloud, mounter, *endpoint, rt, *retryTimesMax)
rpcserver.Run(driver, cloud, mounter, *endpoint, rt, *retryDetachTimesMax)
}
7 changes: 4 additions & 3 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package common
import (
"fmt"
"hash/fnv"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"sync"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
)

// EntryFunction print timestamps
Expand Down Expand Up @@ -84,7 +85,7 @@ func (r *retryLimiter) Add(id string) {
func (r *retryLimiter) Try(id string) bool {
r.mux.RLock()
defer r.mux.RUnlock()
return r.record[id] <= r.maxRetry
return r.maxRetry == 0 || r.record[id] <= r.maxRetry
}

func (r *retryLimiter) GetMaxRetryTimes() int {
Expand Down
15 changes: 15 additions & 0 deletions pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,18 @@ func TestRetryLimiter(t *testing.T) {
t.Errorf("expect false but actually true")
}
}

func TestUnlimitedRetryLimiter(t *testing.T) {
r := NewRetryLimiter(0)
key := "key"
for i := 1; i <= 5; i++ {
r.Add(key)
current := r.GetCurrentRetryTimes(key)
if current != i {
t.Errorf("expect %d but actually %d", i, current)
}
if r.Try(key) != true {
t.Errorf("expect true but actually false")
}
}
}