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

Introduce Snapshot feature flag to disable/enable on demand #150

Merged
merged 6 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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"

// MIN_DELAY_SNAPSHOT_CREATE ...
MIN_DELAY_SNAPSHOT_CREATE = 300 //300 seconds

// MAX_DELAY_SNAPSHOT_CREATE ...
MAX_DELAY_SNAPSHOT_CREATE = 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
20 changes: 20 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,22 @@ func getPrefedTopologyParams(topList []*csi.Topology) (map[string]string, error)
}
return nil, fmt.Errorf("preferred topologies specified but no segments")
}

func getMaxDelaySnapshotCreate(ctxLogger *zap.Logger) int {
maxDelaySnapshotCreate := MIN_DELAY_SNAPSHOT_CREATE // min 300 seconds default
sameshai marked this conversation as resolved.
Show resolved Hide resolved
maxDelayEnv := os.Getenv("MAX_DELAY_SNAPSHOT_CREATE")
if maxDelayEnv != "" {
var err error
maxDelaySnapshotCreate, err = strconv.Atoi(maxDelayEnv)
if err != nil {
maxDelaySnapshotCreate = MIN_DELAY_SNAPSHOT_CREATE // min 300 seconds default
ctxLogger.Warn("Error while processing MAX_DELAY_SNAPSHOT_CREATE variable. MAX_DELAY_SNAPSHOT_CREATE expects integer value in seconds, continuing with default minimum value 300", zap.Any("MAX_DELAY_SNAPSHOT_CREATE", maxDelayEnv), zap.Any("Considered value", maxDelaySnapshotCreate), zap.Error(err))
}
if maxDelaySnapshotCreate > MAX_DELAY_SNAPSHOT_CREATE {
maxDelaySnapshotCreate = MAX_DELAY_SNAPSHOT_CREATE // max 900 seconds default
ctxLogger.Warn("MAX_DELAY_SNAPSHOT_CREATE variable expects integer value which can be maximum 900 seconds, continuing with default maximum value 900", zap.Any("MAX_DELAY_SNAPSHOT_CREATE", maxDelayEnv), zap.Any("Considered value", maxDelaySnapshotCreate), zap.Error(err))

}
}
return maxDelaySnapshotCreate
}

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