Skip to content

Commit 472863e

Browse files
authored
Merge pull request #940 from k8s-infra-cherrypick-robot/cherry-pick-922-to-release-6.3
[release-6.3] add cmdline args to enable group snapshot webhooks
2 parents cef3f0f + 06f835b commit 472863e

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

deploy/kubernetes/webhook-example/webhook.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ spec:
2121
- name: snapshot-validation
2222
image: registry.k8s.io/sig-storage/snapshot-validation-webhook:v6.2.1 # change the image if you wish to use your own custom validation server image
2323
imagePullPolicy: IfNotPresent
24-
args: ['--tls-cert-file=/etc/snapshot-validation-webhook/certs/tls.crt', '--tls-private-key-file=/etc/snapshot-validation-webhook/certs/tls.key']
24+
args:
25+
- '--tls-cert-file=/etc/snapshot-validation-webhook/certs/tls.crt'
26+
- '--tls-private-key-file=/etc/snapshot-validation-webhook/certs/tls.key'
27+
# uncomment the following line to enable webhook for VolumeGroupSnapshot, VolumeGroupSnapshotContent and VolumeGroupSnapshotClass.
28+
# - '--enable-volume-group-snapshot-webhook'
2529
ports:
2630
- containerPort: 443 # change the port as needed
2731
volumeMounts:

pkg/validation-webhook/webhook.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ import (
4040
)
4141

4242
var (
43-
certFile string
44-
keyFile string
45-
kubeconfigFile string
46-
port int
47-
preventVolumeModeConversion bool
43+
certFile string
44+
keyFile string
45+
kubeconfigFile string
46+
port int
47+
preventVolumeModeConversion bool
48+
enableVolumeGroupSnapshotWebhook bool
4849
)
4950

5051
// CmdWebhook is used by Cobra.
@@ -71,6 +72,8 @@ func init() {
7172
CmdWebhook.Flags().StringVar(&kubeconfigFile, "kubeconfig", "", "kubeconfig file to use for volumesnapshotclasses")
7273
CmdWebhook.Flags().BoolVar(&preventVolumeModeConversion, "prevent-volume-mode-conversion",
7374
false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
75+
CmdWebhook.Flags().BoolVar(&enableVolumeGroupSnapshotWebhook, "enable-volume-group-snapshot-webhook",
76+
false, "Enables webhook for VolumeGroupSnapshot, VolumeGroupSnapshotContent and VolumeGroupSnapshotClass.")
7477
}
7578

7679
// admitv1beta1Func handles a v1beta1 admission
@@ -217,14 +220,18 @@ func startServer(
217220
snapshotWebhook := serveSnapshotWebhook{
218221
lister: vscLister,
219222
}
220-
groupSnapshotWebhook := serveGroupSnapshotWebhook{
221-
lister: vgscLister,
222-
}
223223

224224
fmt.Println("Starting webhook server")
225225
mux := http.NewServeMux()
226226
mux.Handle("/volumesnapshot", snapshotWebhook)
227-
mux.Handle("/volumegroupsnapshot", groupSnapshotWebhook)
227+
228+
if enableVolumeGroupSnapshotWebhook {
229+
groupSnapshotWebhook := serveGroupSnapshotWebhook{
230+
lister: vgscLister,
231+
}
232+
mux.Handle("/volumegroupsnapshot", groupSnapshotWebhook)
233+
}
234+
228235
mux.HandleFunc("/readyz", func(w http.ResponseWriter, req *http.Request) { w.Write([]byte("ok")) })
229236
srv := &http.Server{
230237
Handler: mux,
@@ -267,7 +274,10 @@ func main(cmd *cobra.Command, args []string) {
267274

268275
factory := informers.NewSharedInformerFactory(snapClient, 0)
269276
snapshotLister := factory.Snapshot().V1().VolumeSnapshotClasses().Lister()
270-
groupSnapshotLister := factory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses().Lister()
277+
var groupSnapshotLister groupsnapshotlisters.VolumeGroupSnapshotClassLister
278+
if enableVolumeGroupSnapshotWebhook {
279+
groupSnapshotLister = factory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses().Lister()
280+
}
271281

272282
// Start the informers
273283
factory.Start(ctx.Done())

0 commit comments

Comments
 (0)