@@ -40,11 +40,12 @@ import (
4040)
4141
4242var  (
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