Skip to content

Commit 403d436

Browse files
authored
Merge pull request #701 from RaunakShah/cp-svm-webhook
Backport: Add webhook to make SourceVolumeMode immutable
2 parents eee5b4b + faf07c4 commit 403d436

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/validation-webhook/snapshot.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,5 +377,12 @@ func checkSnapshotContentImmutableFieldsV1(snapcontent, oldSnapcontent *volumesn
377377
if !reflect.DeepEqual(source.SnapshotHandle, oldSource.SnapshotHandle) {
378378
return fmt.Errorf("Spec.Source.SnapshotHandle is immutable but was changed from %s to %s", strPtrDereference(oldSource.SnapshotHandle), strPtrDereference(source.SnapshotHandle))
379379
}
380+
381+
if preventVolumeModeConversion {
382+
if !reflect.DeepEqual(snapcontent.Spec.SourceVolumeMode, oldSnapcontent.Spec.SourceVolumeMode) {
383+
return fmt.Errorf("Spec.SourceVolumeMode is immutable but was changed from %v to %v", *oldSnapcontent.Spec.SourceVolumeMode, *snapcontent.Spec.SourceVolumeMode)
384+
}
385+
}
386+
380387
return nil
381388
}

pkg/validation-webhook/webhook.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ import (
3939
)
4040

4141
var (
42-
certFile string
43-
keyFile string
44-
kubeconfigFile string
45-
port int
42+
certFile string
43+
keyFile string
44+
kubeconfigFile string
45+
port int
46+
preventVolumeModeConversion bool
4647
)
4748

4849
// CmdWebhook is used by Cobra.
@@ -67,6 +68,8 @@ func init() {
6768
CmdWebhook.MarkFlagRequired("tls-private-key-file")
6869
// Add optional flag for kubeconfig
6970
CmdWebhook.Flags().StringVar(&kubeconfigFile, "kubeconfig", "", "kubeconfig file to use for volumesnapshotclasses")
71+
CmdWebhook.Flags().BoolVar(&preventVolumeModeConversion, "prevent-volume-mode-conversion",
72+
false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
7073
}
7174

7275
// admitv1beta1Func handles a v1beta1 admission

vendor/github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1/types.go

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

0 commit comments

Comments
 (0)