Add groupSnapshotNamePrefix and groupSnapshotNameUUIDLength CLI options
This commit is contained in:
@@ -87,6 +87,9 @@ var (
|
||||
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
|
||||
enableNodeDeployment = flag.Bool("node-deployment", false, "Enables deploying the sidecar controller together with a CSI driver on nodes to manage snapshots for node-local volumes.")
|
||||
enableVolumeGroupSnapshots = flag.Bool("enable-volume-group-snapshots", false, "Enables the volume group snapshot feature, allowing the user to create snapshots of groups of volumes.")
|
||||
|
||||
groupSnapshotNamePrefix = flag.String("groupsnapshot-name-prefix", "groupsnapshot", "Prefix to apply to the name of a created group snapshot")
|
||||
groupSnapshotNameUUIDLength = flag.Int("groupsnapshot-name-uuid-length", -1, "Length in characters for the generated uuid of a created group snapshot. Defaults behavior is to NOT truncate.")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -227,6 +230,10 @@ func main() {
|
||||
var groupSnapshotter group_snapshotter.GroupSnapshotter
|
||||
if *enableVolumeGroupSnapshots {
|
||||
groupSnapshotter = group_snapshotter.NewGroupSnapshotter(csiConn)
|
||||
if len(*groupSnapshotNamePrefix) == 0 {
|
||||
klog.Error("group snapshot name prefix cannot be of length 0")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
ctrl := controller.NewCSISnapshotSideCarController(
|
||||
@@ -241,6 +248,8 @@ func main() {
|
||||
*resyncPeriod,
|
||||
*snapshotNamePrefix,
|
||||
*snapshotNameUUIDLength,
|
||||
*groupSnapshotNamePrefix,
|
||||
*groupSnapshotNameUUIDLength,
|
||||
*extraCreateMetadata,
|
||||
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
|
||||
*enableVolumeGroupSnapshots,
|
||||
|
@@ -40,11 +40,13 @@ type Handler interface {
|
||||
|
||||
// csiHandler is a handler that calls CSI to create/delete volume snapshot.
|
||||
type csiHandler struct {
|
||||
snapshotter snapshotter.Snapshotter
|
||||
groupSnapshotter group_snapshotter.GroupSnapshotter
|
||||
timeout time.Duration
|
||||
snapshotNamePrefix string
|
||||
snapshotNameUUIDLength int
|
||||
snapshotter snapshotter.Snapshotter
|
||||
groupSnapshotter group_snapshotter.GroupSnapshotter
|
||||
timeout time.Duration
|
||||
snapshotNamePrefix string
|
||||
snapshotNameUUIDLength int
|
||||
groupSnapshotNamePrefix string
|
||||
groupSnapshotNameUUIDLength int
|
||||
}
|
||||
|
||||
// NewCSIHandler returns a handler which includes the csi connection and Snapshot name details
|
||||
@@ -54,13 +56,17 @@ func NewCSIHandler(
|
||||
timeout time.Duration,
|
||||
snapshotNamePrefix string,
|
||||
snapshotNameUUIDLength int,
|
||||
groupSnapshotNamePrefix string,
|
||||
groupSnapshotNameUUIDLength int,
|
||||
) Handler {
|
||||
return &csiHandler{
|
||||
snapshotter: snapshotter,
|
||||
groupSnapshotter: groupSnapshotter,
|
||||
timeout: timeout,
|
||||
snapshotNamePrefix: snapshotNamePrefix,
|
||||
snapshotNameUUIDLength: snapshotNameUUIDLength,
|
||||
snapshotter: snapshotter,
|
||||
groupSnapshotter: groupSnapshotter,
|
||||
timeout: timeout,
|
||||
snapshotNamePrefix: snapshotNamePrefix,
|
||||
snapshotNameUUIDLength: snapshotNameUUIDLength,
|
||||
groupSnapshotNamePrefix: groupSnapshotNamePrefix,
|
||||
groupSnapshotNameUUIDLength: groupSnapshotNameUUIDLength,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +158,7 @@ func (handler *csiHandler) CreateGroupSnapshot(content *crdv1alpha1.VolumeGroupS
|
||||
return "", "", nil, time.Time{}, false, fmt.Errorf("cannot create group snapshot. PVCs to be snapshotted not found in group snapshot content %s", content.Name)
|
||||
}
|
||||
|
||||
groupSnapshotName, err := makeGroupSnapshotName(handler.snapshotNamePrefix, string(content.Spec.VolumeGroupSnapshotRef.UID))
|
||||
groupSnapshotName, err := handler.makeGroupSnapshotName(string(content.Spec.VolumeGroupSnapshotRef.UID))
|
||||
if err != nil {
|
||||
return "", "", nil, time.Time{}, false, err
|
||||
}
|
||||
@@ -181,9 +187,13 @@ func (handler *csiHandler) GetGroupSnapshotStatus(groupSnapshotContent *crdv1alp
|
||||
return csiSnapshotStatus, timestamp, nil
|
||||
}
|
||||
|
||||
func makeGroupSnapshotName(groupSnapshotUID string) (string, error) {
|
||||
func (handler *csiHandler) makeGroupSnapshotName(groupSnapshotUID string) (string, error) {
|
||||
if len(groupSnapshotUID) == 0 {
|
||||
return "", fmt.Errorf("group snapshot object is missing UID")
|
||||
}
|
||||
return fmt.Sprintf("groupsnapshot-%s", strings.Replace(groupSnapshotUID, "-", "", -1)), nil
|
||||
if handler.groupSnapshotNameUUIDLength == -1 {
|
||||
return fmt.Sprintf("%s-%s", handler.groupSnapshotNamePrefix, groupSnapshotUID), nil
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s-%s", handler.groupSnapshotNamePrefix, strings.Replace(groupSnapshotUID, "-", "", -1)[0:handler.groupSnapshotNameUUIDLength]), nil
|
||||
}
|
||||
|
@@ -85,6 +85,8 @@ func NewCSISnapshotSideCarController(
|
||||
resyncPeriod time.Duration,
|
||||
snapshotNamePrefix string,
|
||||
snapshotNameUUIDLength int,
|
||||
groupSnapshotNamePrefix string,
|
||||
groupSnapshotNameUUIDLength int,
|
||||
extraCreateMetadata bool,
|
||||
contentRateLimiter workqueue.RateLimiter,
|
||||
enableVolumeGroupSnapshots bool,
|
||||
@@ -103,7 +105,7 @@ func NewCSISnapshotSideCarController(
|
||||
client: client,
|
||||
driverName: driverName,
|
||||
eventRecorder: eventRecorder,
|
||||
handler: NewCSIHandler(snapshotter, groupSnapshotter, timeout, snapshotNamePrefix, snapshotNameUUIDLength),
|
||||
handler: NewCSIHandler(snapshotter, groupSnapshotter, timeout, snapshotNamePrefix, snapshotNameUUIDLength, groupSnapshotNamePrefix, groupSnapshotNameUUIDLength),
|
||||
resyncPeriod: resyncPeriod,
|
||||
contentStore: cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc),
|
||||
contentQueue: workqueue.NewNamedRateLimitingQueue(contentRateLimiter, "csi-snapshotter-content"),
|
||||
|
Reference in New Issue
Block a user