Skip to content

Commit c068d0e

Browse files
committed
Update of fix for snapshot custom retry and snapshot enable/disable feature
1 parent b494df1 commit c068d0e

File tree

8 files changed

+47
-5
lines changed

8 files changed

+47
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ verify:
8888

8989
.PHONY: test
9090
test:
91-
go test -v -race ./cmd/... ./pkg/...
91+
go test -timeout 1800s -v -race ./cmd/... ./pkg/...
9292

9393
.PHONY: ut-coverage
9494
ut-coverage:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/IBM/ibm-csi-common v1.1.7
77
github.com/IBM/ibmcloud-volume-interface v1.1.4
8-
github.com/IBM/ibmcloud-volume-vpc v1.1.5
8+
github.com/IBM/ibmcloud-volume-vpc v1.1.6
99
github.com/IBM/secret-utils-lib v1.1.4
1010
github.com/container-storage-interface/spec v1.7.0
1111
github.com/golang/glog v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ github.com/IBM/ibm-csi-common v1.1.7 h1:4QY86ZJ8rX1ghrhytgIY+VoEemeG+J2PbvzXTuYZ
4343
github.com/IBM/ibm-csi-common v1.1.7/go.mod h1:TilE1H+F4rzhgnEHHDzdcJ9M+WcJB6QCBxwtGdCDv7A=
4444
github.com/IBM/ibmcloud-volume-interface v1.1.4 h1:rEKAs0rASZTpKWjGPh19GDozpD7Agc21Jjyewo/14/Q=
4545
github.com/IBM/ibmcloud-volume-interface v1.1.4/go.mod h1:I1ZVCvnk+NSNhncg2G06mw5X+jf5XyUP87sT6x1aLVo=
46-
github.com/IBM/ibmcloud-volume-vpc v1.1.5 h1:dN/LxVxtkiK0g4JzDP2VnHoh+LfHwPyzB+TgUZbhVyU=
47-
github.com/IBM/ibmcloud-volume-vpc v1.1.5/go.mod h1:+UTHGrGzjyA2VjaozhB1xOjAcJ1lsi9mFqfGsqmuCOQ=
46+
github.com/IBM/ibmcloud-volume-vpc v1.1.6 h1:HU76slo59S6vPANtQxTDdco+Lu7EToQw7Ow28n5eZR0=
47+
github.com/IBM/ibmcloud-volume-vpc v1.1.6/go.mod h1:+UTHGrGzjyA2VjaozhB1xOjAcJ1lsi9mFqfGsqmuCOQ=
4848
github.com/IBM/secret-common-lib v1.1.4 h1:gKpKnaP45Y6u7VpSlFfXjjTAHpu4bz9Ofy+aR0t2RcI=
4949
github.com/IBM/secret-common-lib v1.1.4/go.mod h1:0L/lLfwi5jwTTmNYE2246HzBIdGz0m6wu/5tXoRp/Lc=
5050
github.com/IBM/secret-utils-lib v1.1.4 h1:8WPG9KBrLLRhGbQn34NWzrFKlyfIIaUfLeDg+iRJkes=

pkg/ibmcsidriver/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ const (
115115

116116
// Generation ... just for backward compatibility
117117
Generation = "generation"
118+
119+
// DEFAULT_SNAPSHOT_CREATE_DELAY ...
120+
DEFAULT_SNAPSHOT_CREATE_DELAY = 300 //300 seconds
121+
122+
// MAX_SNAPSHOT_CREATE_DELAY ... This is max timeout value for csi-snapshotter
123+
MAX_SNAPSHOT_CREATE_DELAY = 900 //900 seconds
118124
)
119125

120126
// SupportedFS the supported FS types

pkg/ibmcsidriver/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package ibmcsidriver
1919

2020
import (
21+
"os"
2122
"strings"
2223
"time"
2324

@@ -439,6 +440,13 @@ func (csiCS *CSIControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
439440
ctxLogger.Info("CSIControllerServer-CreateSnapshot... ", zap.Reflect("Request", *req))
440441
defer metrics.UpdateDurationFromStart(ctxLogger, "CreateSnapshot", time.Now())
441442

443+
//Feature flag to enable/disable CreateSnapshot feature.
444+
if strings.ToLower(os.Getenv("IS_SNAPSHOT_ENABLED")) == "false" {
445+
ctxLogger.Warn("CreateSnapshot functionality is disabled.")
446+
time.Sleep(10 * time.Minute) //To avoid multiple retries from kubernetes to CSI Driver
447+
return nil, commonError.GetCSIError(ctxLogger, commonError.MethodUnimplemented, requestID, nil, "CreateSnapshot functionality is disabled.")
448+
}
449+
442450
snapshotName := req.GetName()
443451
if len(snapshotName) == 0 {
444452
return nil, commonError.GetCSIError(ctxLogger, commonError.MissingSnapshotName, requestID, nil)
@@ -479,6 +487,7 @@ func (csiCS *CSIControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
479487
snapshot, err = session.CreateSnapshot(sourceVolumeID, snapshotParameters)
480488

481489
if err != nil {
490+
time.Sleep(time.Duration(getMaxDelaySnapshotCreate(ctxLogger)) * time.Second) //To avoid multiple retries from kubernetes to CSI Driver
482491
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err, "creation")
483492
}
484493
return createCSISnapshotResponse(*snapshot), nil

pkg/ibmcsidriver/controller_helper.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ibmcsidriver
1919

2020
import (
2121
"fmt"
22+
"os"
2223
"strconv"
2324
"strings"
2425

@@ -508,3 +509,27 @@ func getPrefedTopologyParams(topList []*csi.Topology) (map[string]string, error)
508509
}
509510
return nil, fmt.Errorf("preferred topologies specified but no segments")
510511
}
512+
513+
/*
514+
1.) IF user does not given the value DEFAULT_SNAPSHOT_CREATE_DELAY mins
515+
2.) IF user has given more than MAX_SNAPSHOT_CREATE_DELAY default is MAX_SNAPSHOT_CREATE_DELAY
516+
3.) In case of any invalid value DEFAULT_SNAPSHOT_CREATE_DELAY mins
517+
*/
518+
func getMaxDelaySnapshotCreate(ctxLogger *zap.Logger) int {
519+
userDelayEnv := os.Getenv("CUSTOM_SNAPSHOT_CREATE_DELAY")
520+
if userDelayEnv == "" {
521+
return DEFAULT_SNAPSHOT_CREATE_DELAY
522+
}
523+
524+
customSnapshotCreateDelay, err := strconv.Atoi(userDelayEnv)
525+
if err != nil {
526+
ctxLogger.Warn("Error while processing CUSTOM_SNAPSHOT_CREATE_DELAY value.Expecting integer value in seconds", zap.Any("CUSTOM_SNAPSHOT_CREATE_DELAY", customSnapshotCreateDelay), zap.Any("Considered value", DEFAULT_SNAPSHOT_CREATE_DELAY), zap.Error(err))
527+
return DEFAULT_SNAPSHOT_CREATE_DELAY // min 300 seconds default
528+
}
529+
if customSnapshotCreateDelay > MAX_SNAPSHOT_CREATE_DELAY {
530+
ctxLogger.Warn("CUSTOM_SNAPSHOT_CREATE_DELAY value cannot exceed the limits", zap.Any("CUSTOM_SNAPSHOT_CREATE_DELAY", customSnapshotCreateDelay), zap.Any("Limit value", MAX_SNAPSHOT_CREATE_DELAY))
531+
return MAX_SNAPSHOT_CREATE_DELAY // max 900 seconds
532+
}
533+
534+
return customSnapshotCreateDelay
535+
}

vendor/github.com/IBM/ibmcloud-volume-vpc/block/provider/util.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode
2929
github.com/IBM/ibmcloud-volume-interface/provider/auth
3030
github.com/IBM/ibmcloud-volume-interface/provider/iam
3131
github.com/IBM/ibmcloud-volume-interface/provider/local
32-
# github.com/IBM/ibmcloud-volume-vpc v1.1.5
32+
# github.com/IBM/ibmcloud-volume-vpc v1.1.6
3333
## explicit; go 1.18
3434
github.com/IBM/ibmcloud-volume-vpc/block/provider
3535
github.com/IBM/ibmcloud-volume-vpc/block/utils

0 commit comments

Comments
 (0)