Skip to content

Commit

Permalink
Introduce Snapshot feature flag to disable/enable on demand (#150)
Browse files Browse the repository at this point in the history
* Introduce Snapshot feature flag to disable/enable on demand

* Introduce Snapshot feature flag to disable/enable on demand

* Introduce Snapshot feature flag to disable/enable on demand

* Review Comments

* Introduce Snapshot feature flag to disable/enable on demand

* Introduce Snapshot feature flag to disable/enable on demand
  • Loading branch information
sameshai committed Jun 21, 2023
1 parent d5c2c23 commit 48da04b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ verify:

.PHONY: test
test:
go test -v -race ./cmd/... ./pkg/...
go test -timeout 1800s -v -race ./cmd/... ./pkg/...

.PHONY: ut-coverage
ut-coverage:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/IBM/ibm-csi-common v1.1.7
github.com/IBM/ibmcloud-volume-interface v1.1.4
github.com/IBM/ibmcloud-volume-vpc v1.1.5
github.com/IBM/ibmcloud-volume-vpc v1.1.6
github.com/IBM/secret-utils-lib v1.1.4
github.com/container-storage-interface/spec v1.7.0
github.com/golang/glog v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/IBM/ibm-csi-common v1.1.7 h1:4QY86ZJ8rX1ghrhytgIY+VoEemeG+J2PbvzXTuYZ
github.com/IBM/ibm-csi-common v1.1.7/go.mod h1:TilE1H+F4rzhgnEHHDzdcJ9M+WcJB6QCBxwtGdCDv7A=
github.com/IBM/ibmcloud-volume-interface v1.1.4 h1:rEKAs0rASZTpKWjGPh19GDozpD7Agc21Jjyewo/14/Q=
github.com/IBM/ibmcloud-volume-interface v1.1.4/go.mod h1:I1ZVCvnk+NSNhncg2G06mw5X+jf5XyUP87sT6x1aLVo=
github.com/IBM/ibmcloud-volume-vpc v1.1.5 h1:dN/LxVxtkiK0g4JzDP2VnHoh+LfHwPyzB+TgUZbhVyU=
github.com/IBM/ibmcloud-volume-vpc v1.1.5/go.mod h1:+UTHGrGzjyA2VjaozhB1xOjAcJ1lsi9mFqfGsqmuCOQ=
github.com/IBM/ibmcloud-volume-vpc v1.1.6 h1:HU76slo59S6vPANtQxTDdco+Lu7EToQw7Ow28n5eZR0=
github.com/IBM/ibmcloud-volume-vpc v1.1.6/go.mod h1:+UTHGrGzjyA2VjaozhB1xOjAcJ1lsi9mFqfGsqmuCOQ=
github.com/IBM/secret-common-lib v1.1.4 h1:gKpKnaP45Y6u7VpSlFfXjjTAHpu4bz9Ofy+aR0t2RcI=
github.com/IBM/secret-common-lib v1.1.4/go.mod h1:0L/lLfwi5jwTTmNYE2246HzBIdGz0m6wu/5tXoRp/Lc=
github.com/IBM/secret-utils-lib v1.1.4 h1:8WPG9KBrLLRhGbQn34NWzrFKlyfIIaUfLeDg+iRJkes=
Expand Down
6 changes: 6 additions & 0 deletions pkg/ibmcsidriver/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const (

// Generation ... just for backward compatibility
Generation = "generation"

// DEFAULT_SNAPSHOT_CREATE_DELAY ...
DEFAULT_SNAPSHOT_CREATE_DELAY = 300 //300 seconds

// MAX_SNAPSHOT_CREATE_DELAY ... This is max timeout value for csi-snapshotter
MAX_SNAPSHOT_CREATE_DELAY = 900 //900 seconds
)

// SupportedFS the supported FS types
Expand Down
9 changes: 9 additions & 0 deletions pkg/ibmcsidriver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package ibmcsidriver

import (
"os"
"strings"
"time"

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

//Feature flag to enable/disable CreateSnapshot feature.
if strings.ToLower(os.Getenv("IS_SNAPSHOT_ENABLED")) == "false" {
ctxLogger.Warn("CreateSnapshot functionality is disabled.")
time.Sleep(10 * time.Minute) //To avoid multiple retries from kubernetes to CSI Driver
return nil, commonError.GetCSIError(ctxLogger, commonError.MethodUnimplemented, requestID, nil, "CreateSnapshot functionality is disabled.")
}

snapshotName := req.GetName()
if len(snapshotName) == 0 {
return nil, commonError.GetCSIError(ctxLogger, commonError.MissingSnapshotName, requestID, nil)
Expand Down Expand Up @@ -479,6 +487,7 @@ func (csiCS *CSIControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
snapshot, err = session.CreateSnapshot(sourceVolumeID, snapshotParameters)

if err != nil {
time.Sleep(time.Duration(getMaxDelaySnapshotCreate(ctxLogger)) * time.Second) //To avoid multiple retries from kubernetes to CSI Driver
return nil, commonError.GetCSIError(ctxLogger, commonError.InternalError, requestID, err, "creation")
}
return createCSISnapshotResponse(*snapshot), nil
Expand Down
25 changes: 25 additions & 0 deletions pkg/ibmcsidriver/controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ibmcsidriver

import (
"fmt"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -508,3 +509,27 @@ func getPrefedTopologyParams(topList []*csi.Topology) (map[string]string, error)
}
return nil, fmt.Errorf("preferred topologies specified but no segments")
}

/*
1.) IF user does not given the value DEFAULT_SNAPSHOT_CREATE_DELAY mins
2.) IF user has given more than MAX_SNAPSHOT_CREATE_DELAY default is MAX_SNAPSHOT_CREATE_DELAY
3.) In case of any invalid value DEFAULT_SNAPSHOT_CREATE_DELAY mins
*/
func getMaxDelaySnapshotCreate(ctxLogger *zap.Logger) int {
userDelayEnv := os.Getenv("CUSTOM_SNAPSHOT_CREATE_DELAY")
if userDelayEnv == "" {
return DEFAULT_SNAPSHOT_CREATE_DELAY
}

customSnapshotCreateDelay, err := strconv.Atoi(userDelayEnv)
if err != nil {
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))
return DEFAULT_SNAPSHOT_CREATE_DELAY // min 300 seconds default
}
if customSnapshotCreateDelay > MAX_SNAPSHOT_CREATE_DELAY {
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))
return MAX_SNAPSHOT_CREATE_DELAY // max 900 seconds
}

return customSnapshotCreateDelay
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ github.com/IBM/ibmcloud-volume-interface/lib/utils/reasoncode
github.com/IBM/ibmcloud-volume-interface/provider/auth
github.com/IBM/ibmcloud-volume-interface/provider/iam
github.com/IBM/ibmcloud-volume-interface/provider/local
# github.com/IBM/ibmcloud-volume-vpc v1.1.5
# github.com/IBM/ibmcloud-volume-vpc v1.1.6
## explicit; go 1.18
github.com/IBM/ibmcloud-volume-vpc/block/provider
github.com/IBM/ibmcloud-volume-vpc/block/utils
Expand Down

0 comments on commit 48da04b

Please sign in to comment.