Skip to content

Commit 917d9e7

Browse files
authored
Merge pull request #694 from RaunakShah/cp-controller-sourcemode
[Cherry-pick] Changes to snapshot controller to add SourceVolumeMode to VolumeSnapshotContents
2 parents c46c467 + da516a5 commit 917d9e7

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

cmd/snapshot-controller/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var (
7070
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed volume snapshot creation or deletion. It doubles with each failure, up to retry-interval-max. Default is 1 second.")
7171
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
7272
enableDistributedSnapshotting = flag.Bool("enable-distributed-snapshotting", false, "Enables each node to handle snapshotting for the local volumes created on that node")
73+
preventVolumeModeConversion = flag.Bool("prevent-volume-mode-conversion", false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
7374
)
7475

7576
var (
@@ -187,6 +188,7 @@ func main() {
187188
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
188189
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
189190
*enableDistributedSnapshotting,
191+
*preventVolumeModeConversion,
190192
)
191193

192194
if err := ensureCustomResourceDefinitionsExist(snapClient); err != nil {

pkg/common-controller/framework_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
844844
workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Minute),
845845
workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Minute),
846846
false,
847+
false,
847848
)
848849

849850
ctrl.eventRecorder = record.NewFakeRecorder(1000)

pkg/common-controller/snapshot_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,13 @@ func (ctrl *csiSnapshotCommonController) createSnapshotContent(snapshot *crdv1.V
684684
}
685685
}
686686

687+
if ctrl.preventVolumeModeConversion {
688+
if volume.Spec.VolumeMode != nil {
689+
snapshotContent.Spec.SourceVolumeMode = volume.Spec.VolumeMode
690+
klog.V(5).Infof("snapcontent %s has volume mode %s", snapshotContent.Name, *snapshotContent.Spec.SourceVolumeMode)
691+
}
692+
}
693+
687694
// Set AnnDeletionSecretRefName and AnnDeletionSecretRefNamespace
688695
if snapshotterSecretRef != nil {
689696
klog.V(5).Infof("createSnapshotContent: set annotation [%s] on content [%s].", utils.AnnDeletionSecretRefName, snapshotContent.Name)

pkg/common-controller/snapshot_controller_base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type csiSnapshotCommonController struct {
6868
resyncPeriod time.Duration
6969

7070
enableDistributedSnapshotting bool
71+
preventVolumeModeConversion bool
7172
}
7273

7374
// NewCSISnapshotController returns a new *csiSnapshotCommonController
@@ -84,6 +85,7 @@ func NewCSISnapshotCommonController(
8485
snapshotRateLimiter workqueue.RateLimiter,
8586
contentRateLimiter workqueue.RateLimiter,
8687
enableDistributedSnapshotting bool,
88+
preventVolumeModeConversion bool,
8789
) *csiSnapshotCommonController {
8890
broadcaster := record.NewBroadcaster()
8991
broadcaster.StartLogging(klog.Infof)
@@ -138,6 +140,8 @@ func NewCSISnapshotCommonController(
138140
ctrl.nodeListerSynced = nodeInformer.Informer().HasSynced
139141
}
140142

143+
ctrl.preventVolumeModeConversion = preventVolumeModeConversion
144+
141145
return ctrl
142146
}
143147

0 commit comments

Comments
 (0)